Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
bradharding committed Dec 1, 2023
1 parent 21bc0bf commit 546f154
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 46 deletions.
37 changes: 18 additions & 19 deletions src/i_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,6 @@ int windowheight;
int windowx;
int windowy;

uint32_t rmask;
uint32_t gmask;
uint32_t bmask;
uint32_t amask;
uint32_t pixelformat;
int bpp = 0;

uint32_t maprmask;
uint32_t mapgmask;
uint32_t mapbmask;
uint32_t mapamask;
uint32_t mappixelformat;
int mapbpp = 0;

static int displaywidth;
static int displayheight;
static int displaycenterx;
Expand Down Expand Up @@ -976,6 +962,13 @@ static void GetDisplays(void)
bool I_CreateExternalAutomap(void)
{
const char *displayname;
uint32_t rmask;
uint32_t gmask;
uint32_t bmask;
uint32_t amask;
uint32_t pixelformat;
int bpp = 0;


mapscreen = *screens;
mapblitfunc = &nullfunc;
Expand Down Expand Up @@ -1020,13 +1013,13 @@ bool I_CreateExternalAutomap(void)
if (!(mapsurface = SDL_CreateRGBSurface(0, MAPWIDTH, MAPHEIGHT, 8, 0, 0, 0, 0)))
I_SDLError("SDL_CreateRGBSurface", -1);

if ((mappixelformat = SDL_GetWindowPixelFormat(mapwindow)) == SDL_PIXELFORMAT_UNKNOWN)
if ((pixelformat = SDL_GetWindowPixelFormat(mapwindow)) == SDL_PIXELFORMAT_UNKNOWN)
I_SDLError("SDL_GetWindowPixelFormat", -1);

if (!SDL_PixelFormatEnumToMasks(mappixelformat, &mapbpp, &maprmask, &mapgmask, &mapbmask, &mapamask))
if (!SDL_PixelFormatEnumToMasks(pixelformat, &bpp, &rmask, &gmask, &bmask, &amask))
I_SDLError("SDL_PixelFormatEnumToMasks", -1);

if (!(mapbuffer = SDL_CreateRGBSurface(0, MAPWIDTH, MAPHEIGHT, mapbpp, maprmask, mapgmask, mapbmask, mapamask)))
if (!(mapbuffer = SDL_CreateRGBSurface(0, MAPWIDTH, MAPHEIGHT, bpp, rmask, gmask, bmask, amask)))
I_SDLError("SDL_CreateRGBSurface", -1);

mappitch = mapbuffer->pitch;
Expand All @@ -1037,15 +1030,15 @@ bool I_CreateExternalAutomap(void)
if (nearestlinear)
SDL_SetHintWithPriority(SDL_HINT_RENDER_SCALE_QUALITY, vid_scalefilter_nearest, SDL_HINT_OVERRIDE);

if (!(maptexture = SDL_CreateTexture(maprenderer, mappixelformat, SDL_TEXTUREACCESS_STREAMING,
if (!(maptexture = SDL_CreateTexture(maprenderer, pixelformat, SDL_TEXTUREACCESS_STREAMING,
MAPWIDTH, MAPHEIGHT)))
I_SDLError("SDL_CreateTexture", -2);

if (nearestlinear)
{
SDL_SetHintWithPriority(SDL_HINT_RENDER_SCALE_QUALITY, vid_scalefilter_linear, SDL_HINT_OVERRIDE);

if (!(maptexture_upscaled = SDL_CreateTexture(maprenderer, mappixelformat,
if (!(maptexture_upscaled = SDL_CreateTexture(maprenderer, pixelformat,
SDL_TEXTUREACCESS_TARGET, upscaledwidth * MAPWIDTH, upscaledheight * MAPHEIGHT)))
I_SDLError("SDL_CreateTexture", -2);

Expand Down Expand Up @@ -1240,6 +1233,12 @@ static void SetVideoMode(const bool createwindow, const bool output)
SDL_RendererInfo rendererinfo;
const char *displayname = SDL_GetDisplayName((displayindex = vid_display - 1));
bool instead = false;
uint32_t rmask;
uint32_t gmask;
uint32_t bmask;
uint32_t amask;
uint32_t pixelformat;
int bpp = 0;

if (displayindex >= numdisplays)
{
Expand Down
14 changes: 0 additions & 14 deletions src/i_video.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,6 @@ extern int windowwidth;
extern int windowborderwidth;
extern int windowborderheight;

extern uint32_t rmask;
extern uint32_t gmask;
extern uint32_t bmask;
extern uint32_t amask;
extern uint32_t pixelformat;
extern int bpp;

extern uint32_t maprmask;
extern uint32_t mapgmask;
extern uint32_t mapbmask;
extern uint32_t mapamask;
extern uint32_t mappixelformat;
extern int mapbpp;

extern bool usinggamecontroller;
extern bool usingmouse;
extern bool windowfocused;
Expand Down
29 changes: 16 additions & 13 deletions src/v_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -1756,23 +1756,26 @@ char lbmpath1[MAX_PATH];
static char lbmname2[MAX_PATH];
char lbmpath2[MAX_PATH];

static bool V_SavePNG(SDL_Window *sdlwindow, SDL_Renderer *sdlrenderer, int sdlpixelformat,
int sdlbpp, int sdlrmask, int sdlgmask, int sdlbmask, int sdlamask, const char *path)
static bool V_SavePNG(SDL_Window *sdlwindow, SDL_Renderer *sdlrenderer, const char *path)
{
bool result = false;
int width = 0;
int height = 0;
SDL_Surface *screenshot;
bool result = false;
int width = 0;
int height = 0;

SDL_GetWindowSize(sdlwindow, &width, &height);

if (width && height && (screenshot = SDL_CreateRGBSurface(0, (vid_widescreen ? width : height * 4 / 3),
height, sdlbpp, sdlrmask, sdlgmask, sdlbmask, sdlamask)))
if (width > 0 && height > 0)
{
if (!SDL_RenderReadPixels(sdlrenderer, NULL, sdlpixelformat, screenshot->pixels, screenshot->pitch))
result = !IMG_SavePNG(screenshot, path);
SDL_Surface *screenshot = SDL_CreateRGBSurface(0, (vid_widescreen ? width : height * 4 / 3),
height, 32, 0, 0, 0, 0);

if (screenshot)
{
if (!SDL_RenderReadPixels(sdlrenderer, NULL, 0, screenshot->pixels, screenshot->pitch))
result = !IMG_SavePNG(screenshot, path);

SDL_FreeSurface(screenshot);
SDL_FreeSurface(screenshot);
}
}

return result;
Expand Down Expand Up @@ -1851,7 +1854,7 @@ bool V_ScreenShot(void)
M_snprintf(lbmpath1, sizeof(lbmpath1), "%s%s", screenshotfolder, lbmname1);
} while (M_FileExists(lbmpath1));

result = V_SavePNG(window, renderer, pixelformat, bpp, rmask, gmask, bmask, amask, lbmpath1);
result = V_SavePNG(window, renderer, lbmpath1);

if (result && mapwindow && gamestate == GS_LEVEL)
{
Expand All @@ -1873,7 +1876,7 @@ bool V_ScreenShot(void)
M_snprintf(lbmpath2, sizeof(lbmpath2), "%s%s", screenshotfolder, lbmname2);
} while (M_FileExists(lbmpath2));

V_SavePNG(mapwindow, maprenderer, mappixelformat, mapbpp, maprmask, mapgmask, mapbmask, mapamask, lbmpath2);
V_SavePNG(mapwindow, maprenderer, lbmpath2);
}

free(temp1);
Expand Down

0 comments on commit 546f154

Please sign in to comment.