- moved video files to 'common'.
This commit is contained in:
parent
ddef3f7b98
commit
b1dd1eff50
4 changed files with 2 additions and 2 deletions
|
|
@ -1,314 +0,0 @@
|
|||
/*
|
||||
** The base framebuffer class
|
||||
**
|
||||
**---------------------------------------------------------------------------
|
||||
** Copyright 1999-2016 Randy Heit
|
||||
** Copyright 2005-2018 Christoph Oelckers
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions
|
||||
** are met:
|
||||
**
|
||||
** 1. Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**---------------------------------------------------------------------------
|
||||
**
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#include "v_video.h"
|
||||
|
||||
#include "c_dispatch.h"
|
||||
#include "hardware.h"
|
||||
#include "r_videoscale.h"
|
||||
#include "i_time.h"
|
||||
#include "v_font.h"
|
||||
#include "v_draw.h"
|
||||
#include "i_time.h"
|
||||
#include "v_2ddrawer.h"
|
||||
#include "vm.h"
|
||||
#include "i_interface.h"
|
||||
#include "flatvertices.h"
|
||||
#include "version.h"
|
||||
#include "hw_material.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
|
||||
CVAR(Bool, gl_scale_viewport, true, CVAR_ARCHIVE);
|
||||
|
||||
EXTERN_CVAR(Int, vid_maxfps)
|
||||
CVAR(Bool, cl_capfps, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
EXTERN_CVAR(Int, screenblocks)
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// DFrameBuffer Constructor
|
||||
//
|
||||
// A frame buffer canvas is the most common and represents the image that
|
||||
// gets drawn to the screen.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
DFrameBuffer::DFrameBuffer (int width, int height)
|
||||
{
|
||||
SetSize(width, height);
|
||||
}
|
||||
|
||||
DFrameBuffer::~DFrameBuffer()
|
||||
{
|
||||
}
|
||||
|
||||
void DFrameBuffer::SetSize(int width, int height)
|
||||
{
|
||||
Width = ViewportScaledWidth(width, height);
|
||||
Height = ViewportScaledHeight(width, height);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Palette stuff.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void DFrameBuffer::Update()
|
||||
{
|
||||
int initialWidth = GetClientWidth();
|
||||
int initialHeight = GetClientHeight();
|
||||
int clientWidth = ViewportScaledWidth(initialWidth, initialHeight);
|
||||
int clientHeight = ViewportScaledHeight(initialWidth, initialHeight);
|
||||
if (clientWidth < VID_MIN_WIDTH) clientWidth = VID_MIN_WIDTH;
|
||||
if (clientHeight < VID_MIN_HEIGHT) clientHeight = VID_MIN_HEIGHT;
|
||||
if (clientWidth > 0 && clientHeight > 0 && (GetWidth() != clientWidth || GetHeight() != clientHeight))
|
||||
{
|
||||
SetVirtualSize(clientWidth, clientHeight);
|
||||
V_OutputResized(clientWidth, clientHeight);
|
||||
mVertexData->OutputResized(clientWidth, clientHeight);
|
||||
}
|
||||
}
|
||||
|
||||
void DFrameBuffer::SetClearColor(int color)
|
||||
{
|
||||
PalEntry pe = GPalette.BaseColors[color];
|
||||
mSceneClearColor[0] = pe.r / 255.f;
|
||||
mSceneClearColor[1] = pe.g / 255.f;
|
||||
mSceneClearColor[2] = pe.b / 255.f;
|
||||
mSceneClearColor[3] = 1.f;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// DFrameBuffer :: SetVSync
|
||||
//
|
||||
// Turns vertical sync on and off, if supported.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void DFrameBuffer::SetVSync (bool vsync)
|
||||
{
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// DFrameBuffer :: WipeStartScreen
|
||||
//
|
||||
// Grabs a copy of the screen currently displayed to serve as the initial
|
||||
// frame of a screen wipe. Also determines which screenwipe will be
|
||||
// performed.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FTexture *DFrameBuffer::WipeStartScreen()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// DFrameBuffer :: WipeEndScreen
|
||||
//
|
||||
// Grabs a copy of the most-recently drawn, but not yet displayed, screen
|
||||
// to serve as the final frame of a screen wipe.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FTexture *DFrameBuffer::WipeEndScreen()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Calculates the viewport values needed for 2D and 3D operations
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void DFrameBuffer::SetViewportRects(IntRect *bounds)
|
||||
{
|
||||
if (bounds)
|
||||
{
|
||||
mSceneViewport = *bounds;
|
||||
mScreenViewport = *bounds;
|
||||
mOutputLetterbox = *bounds;
|
||||
return;
|
||||
}
|
||||
|
||||
// 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;
|
||||
scaleX = std::min(clientWidth / (float)screenWidth, clientHeight / ((float)screenHeight * ViewportPixelAspect()));
|
||||
scaleY = scaleX * ViewportPixelAspect();
|
||||
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
|
||||
if (sysCallbacks && sysCallbacks->GetSceneRect) mSceneViewport = sysCallbacks->GetSceneRect();
|
||||
else mSceneViewport = mScreenViewport;
|
||||
|
||||
// Scale viewports to fit letterbox
|
||||
bool notScaled = ((mScreenViewport.width == ViewportScaledWidth(mScreenViewport.width, mScreenViewport.height)) &&
|
||||
(mScreenViewport.width == ViewportScaledHeight(mScreenViewport.width, mScreenViewport.height)) &&
|
||||
(ViewportPixelAspect() == 1.0));
|
||||
if (gl_scale_viewport && !IsFullscreen() && notScaled)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// 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());
|
||||
}
|
||||
|
||||
void DFrameBuffer::ScaleCoordsFromWindow(int16_t &x, int16_t &y)
|
||||
{
|
||||
int letterboxX = mOutputLetterbox.left;
|
||||
int letterboxY = mOutputLetterbox.top;
|
||||
int letterboxWidth = mOutputLetterbox.width;
|
||||
int letterboxHeight = mOutputLetterbox.height;
|
||||
|
||||
x = int16_t((x - letterboxX) * Width / letterboxWidth);
|
||||
y = int16_t((y - letterboxY) * Height / letterboxHeight);
|
||||
}
|
||||
|
||||
void DFrameBuffer::FPSLimit()
|
||||
{
|
||||
using namespace std::chrono;
|
||||
using namespace std::this_thread;
|
||||
|
||||
if (vid_maxfps <= 0 || cl_capfps)
|
||||
return;
|
||||
|
||||
uint64_t targetWakeTime = fpsLimitTime + 1'000'000 / vid_maxfps;
|
||||
|
||||
while (true)
|
||||
{
|
||||
fpsLimitTime = duration_cast<microseconds>(steady_clock::now().time_since_epoch()).count();
|
||||
int64_t timeToWait = targetWakeTime - fpsLimitTime;
|
||||
|
||||
if (timeToWait > 1'000'000 || timeToWait <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (timeToWait <= 2'000)
|
||||
{
|
||||
// We are too close to the deadline. OS sleep is not precise enough to wake us before it elapses.
|
||||
// Yield execution and check time again.
|
||||
sleep_for(nanoseconds(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Sleep, but try to wake before deadline.
|
||||
sleep_for(microseconds(timeToWait - 2'000));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FMaterial* DFrameBuffer::CreateMaterial(FGameTexture* tex, int scaleflags)
|
||||
{
|
||||
return new FMaterial(tex, scaleflags);
|
||||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// ZScript wrappers for inlines
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
DEFINE_ACTION_FUNCTION(_Screen, GetWidth)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
ACTION_RETURN_INT(screen->GetWidth());
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(_Screen, GetHeight)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
ACTION_RETURN_INT(screen->GetHeight());
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(_Screen, PaletteColor)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
PARAM_INT(index);
|
||||
if (index < 0 || index > 255) index = 0;
|
||||
else index = GPalette.BaseColors[index];
|
||||
ACTION_RETURN_INT(index);
|
||||
}
|
||||
|
||||
|
|
@ -1,485 +0,0 @@
|
|||
/*
|
||||
** Video basics and init code.
|
||||
**
|
||||
**---------------------------------------------------------------------------
|
||||
** Copyright 1999-2016 Randy Heit
|
||||
** Copyright 2005-2016 Christoph Oelckers
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions
|
||||
** are met:
|
||||
**
|
||||
** 1. Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**---------------------------------------------------------------------------
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "i_system.h"
|
||||
#include "c_cvars.h"
|
||||
#include "x86.h"
|
||||
#include "i_video.h"
|
||||
|
||||
#include "c_console.h"
|
||||
|
||||
#include "m_argv.h"
|
||||
|
||||
#include "v_video.h"
|
||||
#include "v_text.h"
|
||||
#include "sc_man.h"
|
||||
|
||||
#include "filesystem.h"
|
||||
#include "c_dispatch.h"
|
||||
#include "cmdlib.h"
|
||||
#include "hardware.h"
|
||||
#include "m_png.h"
|
||||
#include "menu/menu.h"
|
||||
#include "vm.h"
|
||||
#include "r_videoscale.h"
|
||||
#include "i_time.h"
|
||||
#include "version.h"
|
||||
#include "texturemanager.h"
|
||||
#include "i_interface.h"
|
||||
#include "v_draw.h"
|
||||
#include "templates.h"
|
||||
|
||||
EXTERN_CVAR(Int, menu_resolution_custom_width)
|
||||
EXTERN_CVAR(Int, menu_resolution_custom_height)
|
||||
|
||||
CVAR(Int, win_x, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
CVAR(Int, win_y, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
CVAR(Int, win_w, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
CVAR(Int, win_h, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
CVAR(Bool, win_maximized, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
|
||||
|
||||
CUSTOM_CVAR(Int, vid_maxfps, 200, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
{
|
||||
if (self < GameTicRate && self != 0)
|
||||
{
|
||||
self = GameTicRate;
|
||||
}
|
||||
else if (vid_maxfps > 1000)
|
||||
{
|
||||
self = 1000;
|
||||
}
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Int, vid_preferbackend, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
|
||||
{
|
||||
// [SP] This may seem pointless - but I don't want to implement live switching just
|
||||
// yet - I'm pretty sure it's going to require a lot of reinits and destructions to
|
||||
// do it right without memory leaks
|
||||
|
||||
switch(self)
|
||||
{
|
||||
case 2:
|
||||
Printf("Selecting SoftPoly backend...\n");
|
||||
break;
|
||||
#ifdef HAVE_VULKAN
|
||||
case 1:
|
||||
Printf("Selecting Vulkan backend...\n");
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
Printf("Selecting OpenGL backend...\n");
|
||||
}
|
||||
|
||||
Printf("Changing the video backend requires a restart for " GAMENAME ".\n");
|
||||
}
|
||||
|
||||
CVAR(Int, vid_renderer, 1, 0) // for some stupid mods which threw caution out of the window...
|
||||
|
||||
CUSTOM_CVAR(Int, uiscale, 0, CVAR_ARCHIVE | CVAR_NOINITCALL)
|
||||
{
|
||||
if (self < 0)
|
||||
{
|
||||
self = 0;
|
||||
return;
|
||||
}
|
||||
if (sysCallbacks && sysCallbacks->OnScreenSizeChanged)
|
||||
sysCallbacks->OnScreenSizeChanged();
|
||||
setsizeneeded = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
EXTERN_CVAR(Bool, r_blendmethod)
|
||||
|
||||
int active_con_scale();
|
||||
|
||||
#define DBGBREAK assert(0)
|
||||
|
||||
class DDummyFrameBuffer : public DFrameBuffer
|
||||
{
|
||||
typedef DFrameBuffer Super;
|
||||
public:
|
||||
DDummyFrameBuffer (int width, int height)
|
||||
: DFrameBuffer (0, 0)
|
||||
{
|
||||
SetVirtualSize(width, height);
|
||||
}
|
||||
// These methods should never be called.
|
||||
void Update() override { DBGBREAK; }
|
||||
bool IsFullscreen() override { DBGBREAK; return 0; }
|
||||
int GetClientWidth() override { DBGBREAK; return 0; }
|
||||
int GetClientHeight() override { DBGBREAK; return 0; }
|
||||
void InitializeState() override {}
|
||||
|
||||
float Gamma;
|
||||
};
|
||||
|
||||
int DisplayWidth, DisplayHeight;
|
||||
|
||||
// [RH] The framebuffer is no longer a mere byte array.
|
||||
// There's also only one, not four.
|
||||
DFrameBuffer *screen;
|
||||
|
||||
CVAR (Int, vid_defwidth, 640, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
||||
CVAR (Int, vid_defheight, 480, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
||||
CVAR (Bool, ticker, false, 0)
|
||||
|
||||
CUSTOM_CVAR (Bool, vid_vsync, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
||||
{
|
||||
if (screen != NULL)
|
||||
{
|
||||
screen->SetVSync (*self);
|
||||
}
|
||||
}
|
||||
|
||||
// [RH] Set true when vid_setmode command has been executed
|
||||
bool setmodeneeded = false;
|
||||
bool setsizeneeded = false;
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// DCanvas Constructor
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
DCanvas::DCanvas (int _width, int _height, bool _bgra)
|
||||
{
|
||||
// Init member vars
|
||||
Width = _width;
|
||||
Height = _height;
|
||||
Bgra = _bgra;
|
||||
Resize(_width, _height);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// DCanvas Destructor
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
DCanvas::~DCanvas ()
|
||||
{
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void DCanvas::Resize(int width, int height, bool optimizepitch)
|
||||
{
|
||||
Width = width;
|
||||
Height = height;
|
||||
|
||||
// Making the pitch a power of 2 is very bad for performance
|
||||
// Try to maximize the number of cache lines that can be filled
|
||||
// for each column drawing operation by making the pitch slightly
|
||||
// longer than the width. The values used here are all based on
|
||||
// empirical evidence.
|
||||
|
||||
if (width <= 640 || !optimizepitch)
|
||||
{
|
||||
// For low resolutions, just keep the pitch the same as the width.
|
||||
// Some speedup can be seen using the technique below, but the speedup
|
||||
// is so marginal that I don't consider it worthwhile.
|
||||
Pitch = width;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we couldn't figure out the CPU's L1 cache line size, assume
|
||||
// it's 32 bytes wide.
|
||||
if (CPU.DataL1LineSize == 0)
|
||||
{
|
||||
CPU.DataL1LineSize = 32;
|
||||
}
|
||||
// The Athlon and P3 have very different caches, apparently.
|
||||
// I am going to generalize the Athlon's performance to all AMD
|
||||
// processors and the P3's to all non-AMD processors. I don't know
|
||||
// how smart that is, but I don't have a vast plethora of
|
||||
// processors to test with.
|
||||
if (CPU.bIsAMD)
|
||||
{
|
||||
Pitch = width + CPU.DataL1LineSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
Pitch = width + MAX(0, CPU.DataL1LineSize - 8);
|
||||
}
|
||||
}
|
||||
int bytes_per_pixel = Bgra ? 4 : 1;
|
||||
Pixels.Resize(Pitch * height * bytes_per_pixel);
|
||||
memset (Pixels.Data(), 0, Pixels.Size());
|
||||
}
|
||||
|
||||
|
||||
CCMD(clean)
|
||||
{
|
||||
Printf ("CleanXfac: %d\nCleanYfac: %d\n", CleanXfac, CleanYfac);
|
||||
}
|
||||
|
||||
|
||||
void V_UpdateModeSize (int width, int height)
|
||||
{
|
||||
// This calculates the menu scale.
|
||||
// The optimal scale will always be to fit a virtual 640 pixel wide display onto the screen.
|
||||
// Exceptions are made for a few ranges where the available virtual width is > 480.
|
||||
|
||||
// This reference size is being used so that on 800x450 (small 16:9) a scale of 2 gets used.
|
||||
|
||||
CleanXfac = std::max(std::min(screen->GetWidth() / 400, screen->GetHeight() / 240), 1);
|
||||
if (CleanXfac >= 4) CleanXfac--; // Otherwise we do not have enough space for the episode/skill menus in some languages.
|
||||
CleanYfac = CleanXfac;
|
||||
CleanWidth = screen->GetWidth() / CleanXfac;
|
||||
CleanHeight = screen->GetHeight() / CleanYfac;
|
||||
|
||||
int w = screen->GetWidth();
|
||||
int factor;
|
||||
if (w < 640) factor = 1;
|
||||
else if (w >= 1024 && w < 1280) factor = 2;
|
||||
else if (w >= 1600 && w < 1920) factor = 3;
|
||||
else factor = w / 640;
|
||||
|
||||
if (w < 1360) factor = 1;
|
||||
else if (w < 1920) factor = 2;
|
||||
else factor = int(factor * 0.7);
|
||||
|
||||
CleanYfac_1 = CleanXfac_1 = factor;// MAX(1, int(factor * 0.7));
|
||||
CleanWidth_1 = width / CleanXfac_1;
|
||||
CleanHeight_1 = height / CleanYfac_1;
|
||||
|
||||
DisplayWidth = width;
|
||||
DisplayHeight = height;
|
||||
}
|
||||
|
||||
void V_OutputResized (int width, int height)
|
||||
{
|
||||
V_UpdateModeSize(width, height);
|
||||
setsizeneeded = true;
|
||||
C_NewModeAdjust();
|
||||
if (sysCallbacks && sysCallbacks->OnScreenSizeChanged)
|
||||
sysCallbacks->OnScreenSizeChanged();
|
||||
}
|
||||
|
||||
bool IVideo::SetResolution ()
|
||||
{
|
||||
DFrameBuffer *buff = CreateFrameBuffer();
|
||||
|
||||
if (buff == NULL) // this cannot really happen
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
screen = buff;
|
||||
screen->InitializeState();
|
||||
|
||||
V_UpdateModeSize(screen->GetWidth(), screen->GetHeight());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// V_Init
|
||||
//
|
||||
|
||||
void V_InitScreenSize ()
|
||||
{
|
||||
const char *i;
|
||||
int width, height, bits;
|
||||
|
||||
width = height = bits = 0;
|
||||
|
||||
if ( (i = Args->CheckValue ("-width")) )
|
||||
width = atoi (i);
|
||||
|
||||
if ( (i = Args->CheckValue ("-height")) )
|
||||
height = atoi (i);
|
||||
|
||||
if (width == 0)
|
||||
{
|
||||
if (height == 0)
|
||||
{
|
||||
width = vid_defwidth;
|
||||
height = vid_defheight;
|
||||
}
|
||||
else
|
||||
{
|
||||
width = (height * 8) / 6;
|
||||
}
|
||||
}
|
||||
else if (height == 0)
|
||||
{
|
||||
height = (width * 6) / 8;
|
||||
}
|
||||
// Remember the passed arguments for the next time the game starts up windowed.
|
||||
vid_defwidth = width;
|
||||
vid_defheight = height;
|
||||
}
|
||||
|
||||
void V_InitScreen()
|
||||
{
|
||||
screen = new DDummyFrameBuffer (vid_defwidth, vid_defheight);
|
||||
}
|
||||
|
||||
void V_Init2()
|
||||
{
|
||||
float gamma = static_cast<DDummyFrameBuffer *>(screen)->Gamma;
|
||||
|
||||
{
|
||||
DFrameBuffer *s = screen;
|
||||
screen = NULL;
|
||||
delete s;
|
||||
}
|
||||
|
||||
UCVarValue val;
|
||||
|
||||
val.Bool = !!Args->CheckParm("-devparm");
|
||||
ticker.SetGenericRepDefault(val, CVAR_Bool);
|
||||
|
||||
|
||||
I_InitGraphics();
|
||||
|
||||
Video->SetResolution(); // this only fails via exceptions.
|
||||
Printf ("Resolution: %d x %d\n", SCREENWIDTH, SCREENHEIGHT);
|
||||
|
||||
// init these for the scaling menu
|
||||
menu_resolution_custom_width = SCREENWIDTH;
|
||||
menu_resolution_custom_height = SCREENHEIGHT;
|
||||
|
||||
screen->SetVSync(vid_vsync);
|
||||
FBaseCVar::ResetColors ();
|
||||
C_NewModeAdjust();
|
||||
setsizeneeded = true;
|
||||
}
|
||||
|
||||
CUSTOM_CVAR (Int, vid_aspect, 0, CVAR_GLOBALCONFIG|CVAR_ARCHIVE)
|
||||
{
|
||||
setsizeneeded = true;
|
||||
if (sysCallbacks && sysCallbacks->OnScreenSizeChanged)
|
||||
sysCallbacks->OnScreenSizeChanged();
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(_Screen, GetAspectRatio)
|
||||
{
|
||||
ACTION_RETURN_FLOAT(ActiveRatio(screen->GetWidth(), screen->GetHeight(), nullptr));
|
||||
}
|
||||
|
||||
CCMD(vid_setsize)
|
||||
{
|
||||
if (argv.argc() < 3)
|
||||
{
|
||||
Printf("Usage: vid_setsize width height\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
screen->SetWindowSize((int)strtol(argv[1], nullptr, 0), (int)strtol(argv[2], nullptr, 0));
|
||||
V_OutputResized(screen->GetClientWidth(), screen->GetClientHeight());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void IVideo::DumpAdapters ()
|
||||
{
|
||||
Printf("Multi-monitor support unavailable.\n");
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Bool, vid_fullscreen, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
|
||||
{
|
||||
setmodeneeded = true;
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Bool, vid_hdr, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
|
||||
{
|
||||
Printf("This won't take effect until " GAMENAME " is restarted.\n");
|
||||
}
|
||||
|
||||
CCMD(vid_listadapters)
|
||||
{
|
||||
if (Video != NULL)
|
||||
Video->DumpAdapters();
|
||||
}
|
||||
|
||||
bool vid_hdr_active = false;
|
||||
|
||||
DEFINE_GLOBAL(SmallFont)
|
||||
DEFINE_GLOBAL(SmallFont2)
|
||||
DEFINE_GLOBAL(BigFont)
|
||||
DEFINE_GLOBAL(ConFont)
|
||||
DEFINE_GLOBAL(NewConsoleFont)
|
||||
DEFINE_GLOBAL(NewSmallFont)
|
||||
DEFINE_GLOBAL(AlternativeSmallFont)
|
||||
DEFINE_GLOBAL(OriginalSmallFont)
|
||||
DEFINE_GLOBAL(OriginalBigFont)
|
||||
DEFINE_GLOBAL(IntermissionFont)
|
||||
DEFINE_GLOBAL(CleanXfac)
|
||||
DEFINE_GLOBAL(CleanYfac)
|
||||
DEFINE_GLOBAL(CleanWidth)
|
||||
DEFINE_GLOBAL(CleanHeight)
|
||||
DEFINE_GLOBAL(CleanXfac_1)
|
||||
DEFINE_GLOBAL(CleanYfac_1)
|
||||
DEFINE_GLOBAL(CleanWidth_1)
|
||||
DEFINE_GLOBAL(CleanHeight_1)
|
||||
|
||||
IHardwareTexture* CreateHardwareTexture()
|
||||
{
|
||||
return screen->CreateHardwareTexture();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// CVAR transsouls
|
||||
//
|
||||
// How translucent things drawn with STYLE_SoulTrans are. Normally, only
|
||||
// Lost Souls have this render style.
|
||||
// Values less than 0.25 will automatically be set to
|
||||
// 0.25 to ensure some degree of visibility. Likewise, values above 1.0 will
|
||||
// be set to 1.0, because anything higher doesn't make sense.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
CUSTOM_CVAR(Float, transsouls, 0.75f, CVAR_ARCHIVE)
|
||||
{
|
||||
if (self < 0.25f)
|
||||
{
|
||||
self = 0.25f;
|
||||
}
|
||||
else if (self > 1.f)
|
||||
{
|
||||
self = 1.f;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,300 +0,0 @@
|
|||
/*
|
||||
** v_video.h
|
||||
**
|
||||
**---------------------------------------------------------------------------
|
||||
** Copyright 1998-2008 Randy Heit
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions
|
||||
** are met:
|
||||
**
|
||||
** 1. Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**---------------------------------------------------------------------------
|
||||
**
|
||||
*/
|
||||
|
||||
#ifndef __V_VIDEO_H__
|
||||
#define __V_VIDEO_H__
|
||||
|
||||
#include <functional>
|
||||
#include "basics.h"
|
||||
#include "vectors.h"
|
||||
#include "m_png.h"
|
||||
#include "renderstyle.h"
|
||||
#include "c_cvars.h"
|
||||
#include "v_2ddrawer.h"
|
||||
#include "intrect.h"
|
||||
#include "hw_shadowmap.h"
|
||||
|
||||
|
||||
struct sector_t;
|
||||
struct FPortalSceneState;
|
||||
class FSkyVertexBuffer;
|
||||
class IIndexBuffer;
|
||||
class IVertexBuffer;
|
||||
class IDataBuffer;
|
||||
class FFlatVertexBuffer;
|
||||
class HWViewpointBuffer;
|
||||
class FLightBuffer;
|
||||
struct HWDrawInfo;
|
||||
class FMaterial;
|
||||
class FGameTexture;
|
||||
class FRenderState;
|
||||
|
||||
enum EHWCaps
|
||||
{
|
||||
// [BB] Added texture compression flags.
|
||||
RFL_TEXTURE_COMPRESSION = 1,
|
||||
RFL_TEXTURE_COMPRESSION_S3TC = 2,
|
||||
|
||||
RFL_SHADER_STORAGE_BUFFER = 4,
|
||||
RFL_BUFFER_STORAGE = 8,
|
||||
|
||||
RFL_NO_CLIP_PLANES = 32,
|
||||
|
||||
RFL_INVALIDATE_BUFFER = 64,
|
||||
RFL_DEBUG = 128,
|
||||
};
|
||||
|
||||
|
||||
extern int DisplayWidth, DisplayHeight;
|
||||
|
||||
void V_UpdateModeSize (int width, int height);
|
||||
void V_OutputResized (int width, int height);
|
||||
|
||||
EXTERN_CVAR(Bool, vid_fullscreen)
|
||||
EXTERN_CVAR(Int, win_x)
|
||||
EXTERN_CVAR(Int, win_y)
|
||||
EXTERN_CVAR(Int, win_w)
|
||||
EXTERN_CVAR(Int, win_h)
|
||||
EXTERN_CVAR(Bool, win_maximized)
|
||||
|
||||
struct FColormap;
|
||||
class FileWriter;
|
||||
enum FTextureFormat : uint32_t;
|
||||
class FModelRenderer;
|
||||
struct SamplerUniform;
|
||||
|
||||
//
|
||||
// VIDEO
|
||||
//
|
||||
//
|
||||
class DCanvas
|
||||
{
|
||||
public:
|
||||
DCanvas (int width, int height, bool bgra);
|
||||
~DCanvas ();
|
||||
void Resize(int width, int height, bool optimizepitch = true);
|
||||
|
||||
// Member variable access
|
||||
inline uint8_t *GetPixels () const { return Pixels.Data(); }
|
||||
inline int GetWidth () const { return Width; }
|
||||
inline int GetHeight () const { return Height; }
|
||||
inline int GetPitch () const { return Pitch; }
|
||||
inline bool IsBgra() const { return Bgra; }
|
||||
|
||||
protected:
|
||||
TArray<uint8_t> Pixels;
|
||||
int Width;
|
||||
int Height;
|
||||
int Pitch;
|
||||
bool Bgra;
|
||||
};
|
||||
|
||||
class IHardwareTexture;
|
||||
class FTexture;
|
||||
|
||||
|
||||
class DFrameBuffer
|
||||
{
|
||||
private:
|
||||
int Width = 0;
|
||||
int Height = 0;
|
||||
|
||||
public:
|
||||
// Hardware render state that needs to be exposed to the API independent part of the renderer. For ease of access this is stored in the base class.
|
||||
int hwcaps = 0; // Capability flags
|
||||
float glslversion = 0; // This is here so that the differences between old OpenGL and new OpenGL/Vulkan can be handled by platform independent code.
|
||||
int instack[2] = { 0,0 }; // this is globally maintained state for portal recursion avoidance.
|
||||
int stencilValue = 0; // Global stencil test value
|
||||
unsigned int uniformblockalignment = 256; // Hardware dependent uniform buffer alignment.
|
||||
unsigned int maxuniformblock = 65536;
|
||||
const char *vendorstring; // We have to account for some issues with particular vendors.
|
||||
FSkyVertexBuffer *mSkyData = nullptr; // the sky vertex buffer
|
||||
FFlatVertexBuffer *mVertexData = nullptr; // Global vertex data
|
||||
HWViewpointBuffer *mViewpoints = nullptr; // Viewpoint render data.
|
||||
FLightBuffer *mLights = nullptr; // Dynamic lights
|
||||
IShadowMap mShadowMap;
|
||||
|
||||
IntRect mScreenViewport;
|
||||
IntRect mSceneViewport;
|
||||
IntRect mOutputLetterbox;
|
||||
float mSceneClearColor[4];
|
||||
|
||||
public:
|
||||
DFrameBuffer (int width=1, int height=1);
|
||||
virtual ~DFrameBuffer();
|
||||
virtual void InitializeState() = 0; // For stuff that needs 'screen' set.
|
||||
virtual bool IsVulkan() { return false; }
|
||||
virtual bool IsPoly() { return false; }
|
||||
void SetAABBTree(hwrenderer::LevelAABBTree * tree)
|
||||
{
|
||||
mShadowMap.SetAABBTree(tree);
|
||||
}
|
||||
|
||||
virtual DCanvas* GetCanvas() { return nullptr; }
|
||||
|
||||
void SetSize(int width, int height);
|
||||
void SetVirtualSize(int width, int height)
|
||||
{
|
||||
Width = width;
|
||||
Height = height;
|
||||
}
|
||||
inline int GetWidth() const { return Width; }
|
||||
inline int GetHeight() const { return Height; }
|
||||
|
||||
FVector2 SceneScale() const
|
||||
{
|
||||
return { mSceneViewport.width / (float)mScreenViewport.width, mSceneViewport.height / (float)mScreenViewport.height };
|
||||
}
|
||||
|
||||
FVector2 SceneOffset() const
|
||||
{
|
||||
return { mSceneViewport.left / (float)mScreenViewport.width, mSceneViewport.top / (float)mScreenViewport.height };
|
||||
}
|
||||
|
||||
// Make the surface visible.
|
||||
virtual void Update ();
|
||||
|
||||
// Stores the palette with flash blended in into 256 dwords
|
||||
// Mark the palette as changed. It will be updated on the next Update().
|
||||
virtual void UpdatePalette() {}
|
||||
|
||||
// Returns true if running fullscreen.
|
||||
virtual bool IsFullscreen () = 0;
|
||||
virtual void ToggleFullscreen(bool yes) {}
|
||||
|
||||
// Changes the vsync setting, if supported by the device.
|
||||
virtual void SetVSync (bool vsync);
|
||||
|
||||
// Delete any resources that need to be deleted after restarting with a different IWAD
|
||||
virtual void SetTextureFilterMode() {}
|
||||
virtual IHardwareTexture *CreateHardwareTexture() { return nullptr; }
|
||||
virtual void PrecacheMaterial(FMaterial *mat, int translation) {}
|
||||
virtual FModelRenderer *CreateModelRenderer(int mli) { return nullptr; }
|
||||
virtual FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags);
|
||||
virtual void TextureFilterChanged() {}
|
||||
virtual void BeginFrame() {}
|
||||
virtual void SetWindowSize(int w, int h) {}
|
||||
virtual void StartPrecaching() {}
|
||||
virtual FRenderState* RenderState() { return nullptr; }
|
||||
|
||||
virtual int GetClientWidth() = 0;
|
||||
virtual int GetClientHeight() = 0;
|
||||
virtual void BlurScene(float amount) {}
|
||||
|
||||
// Interface to hardware rendering resources
|
||||
virtual IVertexBuffer *CreateVertexBuffer() { return nullptr; }
|
||||
virtual IIndexBuffer *CreateIndexBuffer() { return nullptr; }
|
||||
virtual IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo, bool needsresize) { return nullptr; }
|
||||
bool BuffersArePersistent() { return !!(hwcaps & RFL_BUFFER_STORAGE); }
|
||||
|
||||
// This is overridable in case Vulkan does it differently.
|
||||
virtual bool RenderTextureIsFlipped() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Report a game restart
|
||||
void SetClearColor(int color);
|
||||
virtual int Backend() { return 0; }
|
||||
virtual const char* DeviceName() const { return "Unknown"; }
|
||||
virtual void AmbientOccludeScene(float m5) {}
|
||||
virtual void FirstEye() {}
|
||||
virtual void NextEye(int eyecount) {}
|
||||
virtual void SetSceneRenderTarget(bool useSSAO) {}
|
||||
virtual void UpdateShadowMap() {}
|
||||
virtual void WaitForCommands(bool finish) {}
|
||||
virtual void SetSaveBuffers(bool yes) {}
|
||||
virtual void ImageTransitionScene(bool unknown) {}
|
||||
virtual void CopyScreenToBuffer(int width, int height, uint8_t* buffer) { memset(buffer, 0, width* height); }
|
||||
virtual bool FlipSavePic() const { return false; }
|
||||
virtual void RenderTextureView(FCanvasTexture* tex, std::function<void(IntRect&)> renderFunc) {}
|
||||
virtual void SetActiveRenderTarget() {}
|
||||
|
||||
// Screen wiping
|
||||
virtual FTexture *WipeStartScreen();
|
||||
virtual FTexture *WipeEndScreen();
|
||||
|
||||
virtual void PostProcessScene(bool swscene, int fixedcm, const std::function<void()> &afterBloomDrawEndScene2D) { if (afterBloomDrawEndScene2D) afterBloomDrawEndScene2D(); }
|
||||
|
||||
void ScaleCoordsFromWindow(int16_t &x, int16_t &y);
|
||||
|
||||
virtual void Draw2D() {}
|
||||
|
||||
virtual void SetViewportRects(IntRect *bounds);
|
||||
int ScreenToWindowX(int x);
|
||||
int ScreenToWindowY(int y);
|
||||
|
||||
void FPSLimit();
|
||||
|
||||
// Retrieves a buffer containing image data for a screenshot.
|
||||
// Hint: Pitch can be negative for upside-down images, in which case buffer
|
||||
// points to the last row in the buffer, which will be the first row output.
|
||||
virtual TArray<uint8_t> GetScreenshotBuffer(int &pitch, ESSType &color_type, float &gamma) { return TArray<uint8_t>(); }
|
||||
|
||||
static float GetZNear() { return 5.f; }
|
||||
static float GetZFar() { return 65536.f; }
|
||||
|
||||
// The original size of the framebuffer as selected in the video menu.
|
||||
uint64_t FrameTime = 0;
|
||||
|
||||
private:
|
||||
uint64_t fpsLimitTime = 0;
|
||||
|
||||
bool isIn2D = false;
|
||||
};
|
||||
|
||||
|
||||
// This is the screen updated by I_FinishUpdate.
|
||||
extern DFrameBuffer *screen;
|
||||
|
||||
#define SCREENWIDTH (screen->GetWidth ())
|
||||
#define SCREENHEIGHT (screen->GetHeight ())
|
||||
#define SCREENPITCH (screen->GetPitch ())
|
||||
|
||||
EXTERN_CVAR (Float, vid_gamma)
|
||||
|
||||
|
||||
// Allocates buffer screens, call before R_Init.
|
||||
void V_InitScreenSize();
|
||||
void V_InitScreen();
|
||||
|
||||
// Initializes graphics mode for the first time.
|
||||
void V_Init2 ();
|
||||
|
||||
void V_Shutdown ();
|
||||
|
||||
inline bool IsRatioWidescreen(int ratio) { return (ratio & 3) != 0; }
|
||||
extern bool setsizeneeded, setmodeneeded;
|
||||
|
||||
|
||||
#endif // __V_VIDEO_H__
|
||||
Loading…
Add table
Add a link
Reference in a new issue