- removed the pure software render surface and deleted a few unused variables.

With all the 2D refactorings thhe softsurface won't work anymore.
This also revealed a bug with the fullscreen variable, a few places were still using the old one from the SDL backend.
This commit is contained in:
Christoph Oelckers 2020-01-01 12:36:48 +01:00
parent d09b83d4a5
commit 18099e9179
9 changed files with 19 additions and 361 deletions

View file

@ -699,7 +699,6 @@ set (PCH_SOURCES
build/src/pragmas.cpp build/src/pragmas.cpp
build/src/scriptfile.cpp build/src/scriptfile.cpp
build/src/sdlayer.cpp build/src/sdlayer.cpp
build/src/softsurface.cpp
build/src/tiles.cpp build/src/tiles.cpp
build/src/timer.cpp build/src/timer.cpp
build/src/voxmodel.cpp build/src/voxmodel.cpp

View file

@ -242,7 +242,6 @@ void scrUnInit(void)
void scrSetGameMode(int vidMode, int XRes, int YRes, int nBits) void scrSetGameMode(int vidMode, int XRes, int YRes, int nBits)
{ {
videoResetMode();
V_Init2(); V_Init2();
videoClearViewableArea(0); videoClearViewableArea(0);
scrNextPage(); scrNextPage();

View file

@ -18,7 +18,6 @@
extern char appactive; extern char appactive;
extern char modechange; extern char modechange;
extern char nogl;
extern int32_t swapcomplete; extern int32_t swapcomplete;
@ -29,7 +28,7 @@ extern int32_t newaspect_enable;
extern int32_t r_fpgrouscan; extern int32_t r_fpgrouscan;
extern int32_t setaspect_new_use_dimen; extern int32_t setaspect_new_use_dimen;
extern uint32_t r_screenxy; extern uint32_t r_screenxy;
extern int32_t xres, yres, bpp, fullscreen, bytesperline, refreshfreq; extern int32_t xres, yres, bpp, bytesperline, refreshfreq;
extern intptr_t frameplace; extern intptr_t frameplace;
extern char offscreenrendering; extern char offscreenrendering;
@ -38,7 +37,6 @@ void calc_ylookup(int32_t bpl, int32_t lastyidx);
int32_t videoCheckMode(int32_t *x, int32_t *y, int32_t c, int32_t fs, int32_t forced); int32_t videoCheckMode(int32_t *x, int32_t *y, int32_t c, int32_t fs, int32_t forced);
int32_t videoSetMode(int32_t x, int32_t y, int32_t c, int32_t fs); int32_t videoSetMode(int32_t x, int32_t y, int32_t c, int32_t fs);
void videoGetModes(void); void videoGetModes(void);
void videoResetMode(void);
void videoEndDrawing(void); void videoEndDrawing(void);
void videoShowFrame(int32_t); void videoShowFrame(int32_t);
int32_t videoUpdatePalette(int32_t start, int32_t num); int32_t videoUpdatePalette(int32_t start, int32_t num);

View file

@ -1,47 +0,0 @@
/*
* softsurface.h
* An 8-bit rendering surface that can quickly upscale and blit 8-bit paletted buffers to an external 32-bit screen buffer.
*
* Copyright © 2018, Alex Dawson. All rights reserved.
*/
#ifndef SOFTSURFACE_H_
#define SOFTSURFACE_H_
#include "compat.h"
// Initialize the softsurface with the Software renderer's buffer resolution.
// If the Software renderer's resolution and the actual resolution don't match,
// softsurface will still render at the full size of the screen.
// If a surface already exists, softsurface_destroy() will be automatically called before re-initializing.
// Returns whether or not the softsurface could be successfully initialized.
bool softsurface_initialize(vec2_t bufferResolution,
vec2_t destBufferResolution);
// Destroy an existing surface.
void softsurface_destroy();
// Sets the palette to contain the RGBA byte buffer pointed to by pPalette.
// destRedMask/destGreenMask/destBlueMask mask the bits that represent each colour component in the destination buffer's pixel format.
// If the surface is not initialized, the function returns immediately.
void softsurface_setPalette(void* pPalette,
uint32_t destRedMask,
uint32_t destGreenMask,
uint32_t destBlueMask);
// Returns a pointer to the start of the surface's 8-bit pixel buffer
// Returns NULL if the surface is not initialized.
uint8_t* softsurface_getBuffer();
// Returns the resolution of the surface's buffer
vec2_t softsurface_getBufferResolution();
// Returns the resolution of the destination buffer
vec2_t softsurface_getDestinationBufferResolution();
// Blit the surface's pixel buffer to the destination buffer using the palette set with softsurface_setPalette().
// If the surface is not initialized, the function returns immediately.
void softsurface_blitBuffer(uint32_t* destBuffer,
uint32_t destBpp);
#endif /* SOFTSURFACE_H_ */

View file

@ -20,7 +20,6 @@
#include "palette.h" #include "palette.h"
#include "pragmas.h" #include "pragmas.h"
#include "scriptfile.h" #include "scriptfile.h"
#include "softsurface.h"
#include "gamecvars.h" #include "gamecvars.h"
#include "c_console.h" #include "c_console.h"
#include "v_2ddrawer.h" #include "v_2ddrawer.h"
@ -9158,22 +9157,10 @@ static void videoAllocateBuffers(void)
ysavecnt = YSAVES; ysavecnt = YSAVES;
nodesperline = tabledivide32_noinline(YSAVES, ydim); nodesperline = tabledivide32_noinline(YSAVES, ydim);
#ifdef RENDERTYPESDL
if (videoGetRenderMode() == REND_CLASSIC) if (videoGetRenderMode() == REND_CLASSIC)
{
# ifdef USE_OPENGL
if (!nogl)
{ {
glsurface_initialize({ xdim, ydim }); glsurface_initialize({ xdim, ydim });
} }
else
# endif
{
softsurface_initialize({ xdim, ydim },
{ xres, yres });
}
}
#endif
} }
@ -9181,7 +9168,6 @@ static void videoAllocateBuffers(void)
// setgamemode // setgamemode
// //
// JBF: davidoption now functions as a windowed-mode flag (0 == windowed, 1 == fullscreen) // JBF: davidoption now functions as a windowed-mode flag (0 == windowed, 1 == fullscreen)
extern char videomodereset;
int32_t videoSetGameMode(char davidoption, int32_t daupscaledxdim, int32_t daupscaledydim, int32_t dabpp, int32_t daupscalefactor) int32_t videoSetGameMode(char davidoption, int32_t daupscaledxdim, int32_t daupscaledydim, int32_t dabpp, int32_t daupscalefactor)
{ {
int32_t j; int32_t j;
@ -9191,7 +9177,7 @@ int32_t videoSetGameMode(char davidoption, int32_t daupscaledxdim, int32_t daups
daupscaledxdim = max(320, daupscaledxdim); daupscaledxdim = max(320, daupscaledxdim);
daupscaledydim = max(200, daupscaledydim); daupscaledydim = max(200, daupscaledydim);
if (in3dmode() && videomodereset == 0 && if (in3dmode() &&
(xres == daupscaledxdim) && (yres == daupscaledydim) && (bpp == dabpp)) (xres == daupscaledxdim) && (yres == daupscaledydim) && (bpp == dabpp))
return 0; return 0;
@ -10440,33 +10426,8 @@ void videoSetCorrectedAspect()
const int32_t xd = setaspect_new_use_dimen ? xdimen : xdim; const int32_t xd = setaspect_new_use_dimen ? xdimen : xdim;
const int32_t yd = setaspect_new_use_dimen ? ydimen : ydim; const int32_t yd = setaspect_new_use_dimen ? ydimen : ydim;
if (fullscreen && !setaspect_new_use_dimen)
{
const int32_t screenw = r_screenxy/100;
const int32_t screenh = r_screenxy%100;
if (screenw==0 || screenh==0)
{
// Assume square pixel aspect.
x = xd; x = xd;
y = yd; y = yd;
}
else
{
int32_t pixratio;
x = screenw;
y = screenh;
pixratio = divscale16(xdim*screenh, ydim*screenw);
yx = divscale16(yx, pixratio);
}
}
else
{
x = xd;
y = yd;
}
vr = divscale16(x*3, y*4); vr = divscale16(x*3, y*4);

View file

@ -17,7 +17,6 @@
#include "osd.h" #include "osd.h"
#include "palette.h" #include "palette.h"
#include "baselayer.h" #include "baselayer.h"
#include "softsurface.h"
#include "m_argv.h" #include "m_argv.h"
#include "mmulti.h" #include "mmulti.h"
#include "scriptfile.h" #include "scriptfile.h"
@ -37,27 +36,9 @@
#include "imgui.h" #include "imgui.h"
#include "imgui_impl_sdl.h" #include "imgui_impl_sdl.h"
#include "imgui_impl_opengl3.h" #include "imgui_impl_opengl3.h"
#ifndef NETCODE_DISABLE
#include "enet.h"
#endif
#include "../../glbackend/glbackend.h"
#ifdef USE_OPENGL
# include "glsurface.h" # include "glsurface.h"
#endif
#if defined HAVE_GTK2
# include "gtkbits.h"
#endif
#if defined __APPLE__
# include "osxbits.h"
# include <mach/mach.h>
# include <mach/mach_time.h>
#endif
double g_beforeSwapTime; double g_beforeSwapTime;
GameInterface* gi; GameInterface* gi;
@ -92,22 +73,11 @@ void ImGui_Begin_Frame()
//ImGui::NewFrame(); //ImGui::NewFrame();
} }
int32_t xres=-1, yres=-1, bpp=0, fullscreen=0, bytesperline, refreshfreq=-1; int32_t xres=-1, yres=-1, bpp=0, bytesperline, refreshfreq=-1;
intptr_t frameplace=0; intptr_t frameplace=0;
int32_t lockcount=0; int32_t lockcount=0;
char modechange=1; char modechange=1;
char offscreenrendering=0; char offscreenrendering=0;
char videomodereset = 0;
static uint16_t sysgamma[3][256];
#ifdef USE_OPENGL
// OpenGL stuff
char nogl=0;
#endif
static int32_t vsync_renderlayer;
// Joystick dead and saturation zones
uint16_t joydead[9], joysatur[9];
#define MAX_ERRORTEXT 4096 #define MAX_ERRORTEXT 4096
@ -151,14 +121,6 @@ void I_FatalError(const char* error, ...)
} }
void videoResetMode(void)
{
videomodereset = 1;
}
// Calculate ylookup[] and call setvlinebpl() // Calculate ylookup[] and call setvlinebpl()
void calc_ylookup(int32_t bpl, int32_t lastyidx) void calc_ylookup(int32_t bpl, int32_t lastyidx)
{ {
@ -245,16 +207,7 @@ void videoBeginDrawing(void)
return; return;
} }
else else
#ifdef USE_OPENGL
if (!nogl)
{
frameplace = (intptr_t)glsurface_getBuffer(); frameplace = (intptr_t)glsurface_getBuffer();
}
else
#endif
{
frameplace = (intptr_t)softsurface_getBuffer();
}
if (modechange) if (modechange)
{ {
@ -301,14 +254,17 @@ auto vsnprintfptr = vsnprintf; // This is an inline in Visual Studio but we need
void debugprintf(const char* f, ...) void debugprintf(const char* f, ...)
{ {
va_list va; va_list va;
char buf[1024]; va_start(va, f);
#ifdef _WIN32
if (!IsDebuggerPresent()) return; if (!IsDebuggerPresent()) return;
va_start(va, f); char buf[1024];
Bvsnprintf(buf, 1024, f, va); vsnprintf(buf, 1024, f, va);
va_end(va); va_end(va);
OutputDebugStringA(buf); OutputDebugStringA(buf);
#else
vprintf(f, va);
#endif
} }

View file

@ -1,208 +0,0 @@
/*
* softsurface.cpp
* An 8-bit rendering surface that can quickly upscale and blit 8-bit paletted buffers to an external 32-bit buffer.
*
* Copyright © 2018, Alex Dawson. All rights reserved.
*/
#include "softsurface.h"
#include "pragmas.h"
#include "build.h"
static uint8_t* buffer;
static vec2_t bufferRes;
static vec2_t destBufferRes;
static uint32_t xScale16;
static uint32_t yScale16;
static uint32_t recXScale16;
static uint32_t pPal[256];
// lookup table to find the source position within a scanline
static uint16_t* scanPosLookupTable;
template <uint32_t multiple>
static uint32_t roundUp(uint32_t num)
{
return (num+multiple-1)/multiple * multiple;
}
static uint32_t countTrailingZeros(uint32_t u)
{
#if (defined __GNUC__ && __GNUC__>=3) || defined __clang__
return __builtin_ctz(u);
#elif defined _MSC_VER
DWORD result;
_BitScanForward(&result, u);
return result;
#else
uint32_t last = u;
for (; u != 0; last = u, u >>= 1);
return last;
#endif
}
bool softsurface_initialize(vec2_t bufferResolution,
vec2_t destBufferResolution)
{
if (buffer)
softsurface_destroy();
bufferRes = bufferResolution;
destBufferRes = destBufferResolution;
xScale16 = divscale16(destBufferRes.x, bufferRes.x);
yScale16 = divscale16(destBufferRes.y, bufferRes.y);
recXScale16 = divscale16(bufferRes.x, destBufferRes.x);
// allocate one continuous block of memory large enough to hold the buffer, the palette,
// and the scanPosLookupTable while maintaining alignment for each
uint32_t bufferSize = roundUp<16>(bufferRes.x * bufferRes.y);
buffer = (uint8_t*) Xaligned_alloc(16, bufferSize + sizeof(uint16_t)*destBufferRes.x);
scanPosLookupTable = (uint16_t*) (buffer + bufferSize);
// calculate the scanPosLookupTable for horizontal scaling
uint32_t incr = recXScale16;
for (int32_t i = 0; i < destBufferRes.x; ++i)
{
scanPosLookupTable[i] = incr >> 16;
incr += recXScale16;
}
return true;
}
void softsurface_destroy()
{
if (!buffer)
return;
ALIGNED_FREE_AND_NULL(buffer);
scanPosLookupTable = 0;
xScale16 = 0;
yScale16 = 0;
recXScale16 = 0;
bufferRes = {};
destBufferRes = {};
}
void softsurface_setPalette(void* pPalette,
uint32_t destRedMask,
uint32_t destGreenMask,
uint32_t destBlueMask)
{
if (!buffer)
return;
if (!pPalette)
return;
uint32_t destRedShift = countTrailingZeros(destRedMask);
uint32_t destRedLoss = 8 - countTrailingZeros((destRedMask>>destRedShift)+1);
uint32_t destGreenShift = countTrailingZeros(destGreenMask);
uint32_t destGreenLoss = 8 - countTrailingZeros((destGreenMask>>destGreenShift)+1);
uint32_t destBlueShift = countTrailingZeros(destBlueMask);
uint32_t destBlueLoss = 8 - countTrailingZeros((destBlueMask>>destBlueShift)+1);
uint8_t* pUI8Palette = (uint8_t*) pPalette;
for (int i = 0; i < 256; ++i)
{
pPal[i] = ((pUI8Palette[sizeof(uint32_t)*i] >> destRedLoss << destRedShift) & destRedMask) |
((pUI8Palette[sizeof(uint32_t)*i+1] >> destGreenLoss << destGreenShift) & destGreenMask) |
((pUI8Palette[sizeof(uint32_t)*i+2] >> destBlueLoss << destBlueShift) & destBlueMask);
}
}
uint8_t* softsurface_getBuffer()
{
return buffer;
}
vec2_t softsurface_getBufferResolution()
{
return bufferRes;
}
vec2_t softsurface_getDestinationBufferResolution()
{
return destBufferRes;
}
#define BLIT(x) pDst[x] = *((UINTTYPE*)(pPal+pSrc[pScanPos[x]]))
#define BLIT2(x) BLIT(x); BLIT(x+1)
#define BLIT4(x) BLIT2(x); BLIT2(x+2)
#define BLIT8(x) BLIT4(x); BLIT4(x+4)
#define BLIT16(x) BLIT8(x); BLIT8(x+8)
#define BLIT32(x) BLIT16(x); BLIT16(x+16)
#define BLIT64(x) BLIT32(x); BLIT32(x+32)
template <typename UINTTYPE>
void softsurface_blitBufferInternal(UINTTYPE* destBuffer)
{
const uint8_t* __restrict pSrc = buffer;
UINTTYPE* __restrict pDst = destBuffer;
const UINTTYPE* const pEnd = destBuffer+destBufferRes.x*mulscale16(yScale16, bufferRes.y);
uint32_t remainder = 0;
while (pDst < pEnd)
{
uint16_t* __restrict pScanPos = scanPosLookupTable;
UINTTYPE* const pScanEnd = pDst+destBufferRes.x;
while (pDst < pScanEnd-64)
{
BLIT64(0);
pDst += 64;
pScanPos += 64;
}
while (pDst < pScanEnd)
{
BLIT(0);
++pDst;
++pScanPos;
}
pSrc += bufferRes.x;
static const uint32_t MASK16 = (1<<16)-1;
uint32_t linesCopied = 1;
uint32_t linesToCopy = yScale16+remainder;
remainder = linesToCopy & MASK16;
linesToCopy = (linesToCopy >> 16)-1;
const UINTTYPE* const __restrict pScanLineSrc = pDst-destBufferRes.x;
while (linesToCopy)
{
uint32_t lines = min(linesCopied, linesToCopy);
memcpy(pDst, pScanLineSrc, sizeof(UINTTYPE)*lines*destBufferRes.x);
pDst += lines*destBufferRes.x;
linesToCopy -= lines;
}
}
}
void softsurface_blitBuffer(uint32_t* destBuffer,
uint32_t destBpp)
{
if (!buffer)
return;
if (!destBuffer)
return;
switch (destBpp)
{
case 15:
softsurface_blitBufferInternal<uint16_t>((uint16_t*) destBuffer);
break;
case 16:
softsurface_blitBufferInternal<uint16_t>((uint16_t*) destBuffer);
break;
case 24:
softsurface_blitBufferInternal<uint32_t>(destBuffer);
break;
case 32:
softsurface_blitBufferInternal<uint32_t>(destBuffer);
break;
default:
return;
}
}

View file

@ -147,7 +147,7 @@ int32_t handleevents(void)
if (setmodeneeded) if (setmodeneeded)
{ {
setmodeneeded = false; setmodeneeded = false;
screen->ToggleFullscreen(fullscreen); screen->ToggleFullscreen(vid_fullscreen);
V_OutputResized(screen->GetWidth(), screen->GetHeight()); V_OutputResized(screen->GetWidth(), screen->GetHeight());
} }

View file

@ -65,7 +65,7 @@ CCMD (menu_resolution_set_custom)
CCMD (menu_resolution_commit_changes) CCMD (menu_resolution_commit_changes)
{ {
int do_fullscreen = fullscreen; int do_fullscreen = vid_fullscreen;
if (argv.argc() > 1) if (argv.argc() > 1)
{ {
do_fullscreen = atoi(argv[1]); do_fullscreen = atoi(argv[1]);
@ -80,7 +80,7 @@ CCMD (menu_resolution_commit_changes)
} }
else else
{ {
fullscreen = true; vid_fullscreen = true;
vid_scalemode = 5; vid_scalemode = 5;
vid_scalefactor = 1.; vid_scalefactor = 1.;
vid_scale_customwidth = menu_resolution_custom_width; vid_scale_customwidth = menu_resolution_custom_width;