2012-10-07 07:09:29 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2012-12-07 21:04:49 +00:00
|
|
|
|
|
|
|
#include "SDL.h"
|
2012-10-07 07:09:29 +00:00
|
|
|
|
|
|
|
#include "cdaudio.h"
|
|
|
|
#include "cmd.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "console.h"
|
|
|
|
#include "cvar.h"
|
|
|
|
#include "d_iface.h"
|
|
|
|
#include "d_local.h"
|
|
|
|
#include "draw.h"
|
|
|
|
#include "input.h"
|
|
|
|
#include "keys.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "quakedef.h"
|
|
|
|
#include "screen.h"
|
2012-12-07 21:04:49 +00:00
|
|
|
#include "sdl_common.h"
|
2012-10-07 07:09:29 +00:00
|
|
|
#include "sound.h"
|
|
|
|
#include "sys.h"
|
|
|
|
#include "vid.h"
|
|
|
|
#include "view.h"
|
|
|
|
#include "wad.h"
|
2012-12-07 21:04:49 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2012-10-07 07:09:29 +00:00
|
|
|
#include "winquake.h"
|
2012-12-07 21:04:49 +00:00
|
|
|
#endif
|
2012-10-07 07:09:29 +00:00
|
|
|
|
|
|
|
#ifdef NQ_HACK
|
|
|
|
#include "host.h"
|
|
|
|
#endif
|
|
|
|
#ifdef QW_HACK
|
|
|
|
#include "client.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// FIXME: evil hack to get full DirectSound support with SDL
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
HWND mainwindow;
|
2012-12-07 21:04:49 +00:00
|
|
|
qboolean DDActive = false;
|
2012-10-07 07:09:29 +00:00
|
|
|
#endif
|
|
|
|
|
2012-12-07 21:04:49 +00:00
|
|
|
static SDL_Renderer *renderer = NULL;
|
|
|
|
static SDL_Texture *texture = NULL;
|
2012-12-09 02:43:43 +00:00
|
|
|
static SDL_PixelFormat *sdl_format = NULL;
|
2012-12-09 02:44:36 +00:00
|
|
|
static SDL_PixelFormat *sdl_desktop_format = NULL;
|
2012-10-07 07:09:29 +00:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stuff adapted from vid_win.c below... refactor so SDL works for other
|
|
|
|
* platforms...
|
|
|
|
*/
|
|
|
|
|
|
|
|
static byte *vid_surfcache;
|
|
|
|
static int vid_surfcachesize;
|
|
|
|
static int VID_highhunkmark;
|
|
|
|
static qboolean hide_window;
|
|
|
|
//static int window_x, window_y;
|
|
|
|
static int window_width, window_height;
|
|
|
|
|
|
|
|
unsigned short d_8to16table[256];
|
|
|
|
unsigned d_8to24table[256];
|
|
|
|
viddef_t vid; /* global video state */
|
|
|
|
|
2012-12-07 21:04:49 +00:00
|
|
|
#ifdef _WIN32
|
2012-10-07 07:09:29 +00:00
|
|
|
static HICON hIcon;
|
2012-12-07 21:04:49 +00:00
|
|
|
RECT window_rect;
|
|
|
|
#endif
|
|
|
|
|
2012-10-07 07:09:29 +00:00
|
|
|
int window_center_x, window_center_y;
|
|
|
|
static int window_x, window_y;
|
|
|
|
|
|
|
|
/* Placeholders */
|
|
|
|
void VID_ForceLockState(int lk) { }
|
|
|
|
int VID_ForceUnlockedAndReturnState(void) { return 0; }
|
2012-12-09 02:45:12 +00:00
|
|
|
void VID_Shutdown(void)
|
|
|
|
{
|
|
|
|
if (renderer)
|
|
|
|
SDL_DestroyRenderer(renderer);
|
|
|
|
if (sdl_window)
|
|
|
|
SDL_DestroyWindow(sdl_window);
|
|
|
|
if (sdl_format)
|
|
|
|
SDL_FreeFormat(sdl_format);
|
|
|
|
if (sdl_desktop_format)
|
|
|
|
SDL_FreeFormat(sdl_desktop_format);
|
|
|
|
}
|
2012-12-07 21:04:49 +00:00
|
|
|
|
|
|
|
static qboolean palette_changed;
|
|
|
|
|
|
|
|
void
|
2013-03-28 05:08:42 +00:00
|
|
|
VID_ShiftPalette(const byte *palette)
|
2012-12-07 21:04:49 +00:00
|
|
|
{
|
|
|
|
VID_SetPalette(palette);
|
|
|
|
}
|
|
|
|
|
2012-10-07 07:09:29 +00:00
|
|
|
void VID_SetDefaultMode(void) { }
|
|
|
|
static qboolean VID_SetWindowedMode(int modenum) { return true; }
|
|
|
|
static qboolean VID_FullScreenMode(int modenum) { return true; }
|
|
|
|
|
|
|
|
static cvar_t vid_mode = {
|
|
|
|
.name = "vid_mode",
|
|
|
|
.string = stringify(VID_MODE_WINDOWED),
|
|
|
|
.archive = false
|
|
|
|
};
|
|
|
|
static cvar_t _vid_default_mode = {
|
|
|
|
.name = "_vid_default_mode",
|
|
|
|
.string = stringify(VID_MODE_WINDOWED),
|
|
|
|
.archive = true
|
|
|
|
};
|
|
|
|
static cvar_t _vid_default_mode_win = {
|
|
|
|
.name = "_vid_default_mode_win",
|
|
|
|
.string = stringify(VID_MODE_FULLSCREEN_DEFAULT),
|
|
|
|
.archive = true
|
|
|
|
};
|
|
|
|
static cvar_t vid_fullscreen_mode = {
|
|
|
|
.name = "vid_fullscreen_mode",
|
|
|
|
.string = stringify(VID_MODE_FULLSCREEN_DEFAULT),
|
|
|
|
.archive = true
|
|
|
|
};
|
|
|
|
static cvar_t vid_windowed_mode = {
|
|
|
|
.name = "vid_windowed_mode",
|
|
|
|
.string = stringify(VID_MODE_WINDOWED),
|
|
|
|
.archive = true
|
|
|
|
};
|
|
|
|
|
|
|
|
static cvar_t vid_wait = { "vid_wait", "0" };
|
|
|
|
static cvar_t vid_nopageflip = { "vid_nopageflip", "0", true };
|
|
|
|
static cvar_t _vid_wait_override = { "_vid_wait_override", "0", true };
|
|
|
|
static cvar_t block_switch = { "block_switch", "0", true };
|
|
|
|
static cvar_t vid_window_x = { "vid_window_x", "0", true };
|
|
|
|
static cvar_t vid_window_y = { "vid_window_y", "0", true };
|
|
|
|
|
|
|
|
static int windowed_default;
|
|
|
|
static int vid_default = VID_MODE_WINDOWED;
|
2013-03-28 05:08:42 +00:00
|
|
|
int vid_modenum = VID_MODE_NONE;
|
2012-10-07 07:09:29 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2012-12-09 02:43:43 +00:00
|
|
|
typeof(SDL_PIXELFORMAT_UNKNOWN) format;
|
2013-03-28 05:08:42 +00:00
|
|
|
} qvidformat_t;
|
2012-10-07 07:09:29 +00:00
|
|
|
|
|
|
|
static qboolean Minimized;
|
|
|
|
static qboolean force_mode_set;
|
|
|
|
|
|
|
|
qboolean
|
|
|
|
window_visible(void)
|
|
|
|
{
|
|
|
|
return !Minimized;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
VID_InitModeList(void)
|
|
|
|
{
|
2012-12-07 21:04:49 +00:00
|
|
|
int i, err;
|
|
|
|
int displays, sdlmodes;
|
2013-04-01 03:13:49 +00:00
|
|
|
SDL_DisplayMode sdlmode;
|
|
|
|
qvidmode_t *mode;
|
|
|
|
qvidformat_t *format;
|
2013-03-27 06:57:07 +00:00
|
|
|
|
2012-12-07 21:04:49 +00:00
|
|
|
displays = SDL_GetNumVideoDisplays();
|
|
|
|
if (displays < 1)
|
|
|
|
Sys_Error("%s: no displays found (%s)", __func__, SDL_GetError());
|
|
|
|
|
|
|
|
/* FIXME - allow use of more than one display */
|
2012-12-08 02:11:43 +00:00
|
|
|
sdlmodes = SDL_GetNumDisplayModes(0);
|
|
|
|
if (sdlmodes < 0)
|
|
|
|
Con_SafePrintf("%s: error enumerating SDL display modes (%s)\n",
|
|
|
|
__func__, SDL_GetError());
|
2012-10-07 07:09:29 +00:00
|
|
|
|
2012-10-19 23:30:19 +00:00
|
|
|
/*
|
2012-12-07 21:04:49 +00:00
|
|
|
* Check availability of fullscreen modes
|
2012-12-08 02:11:43 +00:00
|
|
|
* (default to display 0 for now)
|
2012-10-19 23:30:19 +00:00
|
|
|
*/
|
2013-04-01 03:13:49 +00:00
|
|
|
mode = &modelist[1];
|
|
|
|
nummodes = 1;
|
2012-12-07 21:04:49 +00:00
|
|
|
for (i = 0; i < sdlmodes && nummodes < MAX_MODE_LIST; i++) {
|
2013-04-01 03:13:49 +00:00
|
|
|
err = SDL_GetDisplayMode(0, i, &sdlmode);
|
2012-12-07 21:04:49 +00:00
|
|
|
if (err)
|
|
|
|
Sys_Error("%s: couldn't get mode %d info (%s)",
|
|
|
|
__func__, i, SDL_GetError());
|
|
|
|
|
|
|
|
printf("%s: checking mode %i: %dx%d, %s\n", __func__,
|
2013-04-01 03:13:49 +00:00
|
|
|
i, sdlmode.w, sdlmode.h, SDL_GetPixelFormatName(sdlmode.format));
|
2012-10-19 23:30:19 +00:00
|
|
|
|
2013-04-01 03:13:49 +00:00
|
|
|
if (sdlmode.h > MAXHEIGHT)
|
2012-12-08 02:12:37 +00:00
|
|
|
continue;
|
2012-12-09 02:43:43 +00:00
|
|
|
|
2013-04-01 03:13:49 +00:00
|
|
|
if (SDL_PIXELTYPE(sdlmode.format) == SDL_PIXELTYPE_PACKED32)
|
2012-12-09 02:43:43 +00:00
|
|
|
modelist[nummodes].bpp = 32;
|
2013-04-01 03:13:49 +00:00
|
|
|
else if (SDL_PIXELTYPE(sdlmode.format) == SDL_PIXELTYPE_PACKED16)
|
2012-12-09 02:43:43 +00:00
|
|
|
modelist[nummodes].bpp = 16;
|
|
|
|
else
|
2012-10-20 06:35:11 +00:00
|
|
|
continue;
|
2012-12-07 21:04:49 +00:00
|
|
|
|
2013-04-01 03:13:49 +00:00
|
|
|
mode->modenum = nummodes;
|
|
|
|
mode->width = sdlmode.w;
|
|
|
|
mode->height = sdlmode.h;
|
|
|
|
mode->refresh = sdlmode.refresh_rate;
|
|
|
|
format = (qvidformat_t *)mode->driverdata;
|
|
|
|
format->format = sdlmode.format;
|
2012-10-07 07:09:29 +00:00
|
|
|
nummodes++;
|
2013-04-01 03:13:49 +00:00
|
|
|
mode++;
|
2012-10-07 07:09:29 +00:00
|
|
|
}
|
2013-03-27 06:57:07 +00:00
|
|
|
|
2013-04-01 03:13:49 +00:00
|
|
|
VID_SortModeList(modelist, nummodes);
|
2013-03-27 06:57:07 +00:00
|
|
|
}
|
|
|
|
|
2012-10-07 07:09:29 +00:00
|
|
|
/*
|
|
|
|
================
|
|
|
|
ClearAllStates
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ClearAllStates(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// send an up event for each key, to make sure the server clears them all
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
Key_Event(i, false);
|
|
|
|
|
|
|
|
Key_ClearStates();
|
|
|
|
//IN_ClearStates();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
VID_CheckAdequateMem
|
|
|
|
====================
|
|
|
|
*/
|
2013-03-28 05:08:42 +00:00
|
|
|
qboolean
|
2012-10-07 07:09:29 +00:00
|
|
|
VID_CheckAdequateMem(int width, int height)
|
|
|
|
{
|
|
|
|
int tbuffersize;
|
|
|
|
|
|
|
|
tbuffersize = width * height * sizeof(*d_pzbuffer);
|
|
|
|
tbuffersize += D_SurfaceCacheForRes(width, height);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* see if there's enough memory, allowing for the normal mode 0x13 pixel,
|
|
|
|
* z, and surface buffers
|
|
|
|
*/
|
|
|
|
if ((host_parms.memsize - tbuffersize + SURFCACHE_SIZE_AT_320X200 +
|
|
|
|
0x10000 * 3) < minimum_memory)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
VID_AllocBuffers
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
static qboolean
|
|
|
|
VID_AllocBuffers(int width, int height)
|
|
|
|
{
|
|
|
|
int tsize, tbuffersize;
|
|
|
|
|
|
|
|
tsize = D_SurfaceCacheForRes(width, height);
|
|
|
|
tbuffersize = width * height * sizeof(*d_pzbuffer);
|
|
|
|
tbuffersize += tsize;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* see if there's enough memory, allowing for the normal mode 0x13 pixel,
|
|
|
|
* z, and surface buffers
|
|
|
|
*/
|
|
|
|
if ((host_parms.memsize - tbuffersize + SURFCACHE_SIZE_AT_320X200 +
|
|
|
|
0x10000 * 3) < minimum_memory) {
|
|
|
|
Con_SafePrintf("Not enough memory for video mode\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
vid_surfcachesize = tsize;
|
|
|
|
|
|
|
|
if (d_pzbuffer) {
|
|
|
|
D_FlushCaches();
|
|
|
|
Hunk_FreeToHighMark(VID_highhunkmark);
|
|
|
|
d_pzbuffer = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
VID_highhunkmark = Hunk_HighMark();
|
|
|
|
d_pzbuffer = Hunk_HighAllocName(tbuffersize, "video");
|
|
|
|
vid_surfcache = (byte *)d_pzbuffer + width * height * sizeof(*d_pzbuffer);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
qboolean
|
|
|
|
VID_IsFullScreen()
|
|
|
|
{
|
2013-04-01 03:13:49 +00:00
|
|
|
return !!vid_modenum;
|
2012-10-07 07:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
VID_UpdateWindowStatus
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
VID_UpdateWindowStatus(void)
|
|
|
|
{
|
2012-12-07 21:04:49 +00:00
|
|
|
#ifdef _WIN32
|
2012-10-07 07:09:29 +00:00
|
|
|
window_rect.left = window_x;
|
|
|
|
window_rect.top = window_y;
|
|
|
|
window_rect.right = window_x + window_width;
|
|
|
|
window_rect.bottom = window_y + window_height;
|
|
|
|
window_center_x = (window_rect.left + window_rect.right) / 2;
|
|
|
|
window_center_y = (window_rect.top + window_rect.bottom) / 2;
|
|
|
|
|
|
|
|
IN_UpdateClipCursor();
|
2012-12-07 21:04:49 +00:00
|
|
|
#endif
|
2012-10-07 07:09:29 +00:00
|
|
|
}
|
|
|
|
|
2013-03-28 05:08:42 +00:00
|
|
|
qboolean
|
|
|
|
VID_SetMode(const qvidmode_t *mode, const byte *palette)
|
2012-10-07 07:09:29 +00:00
|
|
|
{
|
2012-10-20 06:25:51 +00:00
|
|
|
Uint32 flags;
|
2012-12-09 06:54:12 +00:00
|
|
|
qboolean mouse_grab;
|
2013-04-01 03:13:49 +00:00
|
|
|
const qvidformat_t *format;
|
2012-12-09 06:54:12 +00:00
|
|
|
|
|
|
|
/* FIXME - hack to reset mouse grabs */
|
|
|
|
mouse_grab = _windowed_mouse.value;
|
|
|
|
if (mouse_grab) {
|
|
|
|
_windowed_mouse.value = 0;
|
|
|
|
_windowed_mouse.callback(&_windowed_mouse);
|
|
|
|
}
|
2012-10-07 07:09:29 +00:00
|
|
|
|
2012-12-07 21:04:49 +00:00
|
|
|
flags = SDL_WINDOW_SHOWN;
|
2013-04-01 03:13:49 +00:00
|
|
|
if (mode - modelist != 0)
|
2012-12-07 21:04:49 +00:00
|
|
|
flags |= SDL_WINDOW_FULLSCREEN;
|
|
|
|
|
|
|
|
if (renderer)
|
|
|
|
SDL_DestroyRenderer(renderer);
|
|
|
|
if (sdl_window)
|
|
|
|
SDL_DestroyWindow(sdl_window);
|
2012-12-09 02:43:43 +00:00
|
|
|
if (sdl_format)
|
|
|
|
SDL_FreeFormat(sdl_format);
|
|
|
|
|
2013-04-01 03:13:49 +00:00
|
|
|
format = (const qvidformat_t *)mode->driverdata;
|
|
|
|
sdl_format = SDL_AllocFormat(format->format);
|
2012-12-07 21:04:49 +00:00
|
|
|
|
|
|
|
sdl_window = SDL_CreateWindow("TyrQuake",
|
|
|
|
SDL_WINDOWPOS_UNDEFINED,
|
|
|
|
SDL_WINDOWPOS_UNDEFINED,
|
2013-04-01 03:13:49 +00:00
|
|
|
mode->width, mode->height, flags);
|
2012-12-07 21:04:49 +00:00
|
|
|
if (!sdl_window)
|
|
|
|
Sys_Error("%s: Unable to create window: %s", __func__, SDL_GetError());
|
|
|
|
|
|
|
|
renderer = SDL_CreateRenderer(sdl_window, -1, SDL_RENDERER_ACCELERATED);
|
|
|
|
if (!renderer)
|
|
|
|
Sys_Error("%s: Unable to create renderer: %s", __func__, SDL_GetError());
|
|
|
|
|
|
|
|
texture = SDL_CreateTexture(renderer,
|
2013-04-01 03:13:49 +00:00
|
|
|
format->format,
|
2012-12-07 21:04:49 +00:00
|
|
|
SDL_TEXTUREACCESS_STREAMING,
|
2013-04-01 03:13:49 +00:00
|
|
|
mode->width, mode->height);
|
2012-12-07 21:04:49 +00:00
|
|
|
if (!texture)
|
|
|
|
Sys_Error("%s: Unable to create texture: %s", __func__, SDL_GetError());
|
2012-10-07 07:09:29 +00:00
|
|
|
|
|
|
|
//VID_InitGamma(palette);
|
|
|
|
VID_SetPalette(palette);
|
|
|
|
|
|
|
|
vid.numpages = 1;
|
2013-04-01 03:13:49 +00:00
|
|
|
vid.width = vid.conwidth = mode->width;
|
|
|
|
vid.height = vid.conheight = mode->height;
|
2012-10-07 07:09:29 +00:00
|
|
|
vid.maxwarpwidth = WARP_WIDTH;
|
|
|
|
vid.maxwarpheight = WARP_HEIGHT;
|
|
|
|
vid.aspect = ((float)vid.height / (float)vid.width) * (320.0 / 240.0);
|
|
|
|
|
|
|
|
vid.colormap = host_colormap;
|
|
|
|
vid.fullbright = 256 - LittleLong(*((int *)vid.colormap + 2048));
|
|
|
|
|
|
|
|
VID_AllocBuffers(vid.width, vid.height);
|
2012-12-07 21:04:49 +00:00
|
|
|
|
|
|
|
// In-memory buffer which we upload via SDL texture
|
|
|
|
vid.buffer = vid.conbuffer = vid.direct = Hunk_HighAllocName(vid.width * vid.height, "vidbuf");
|
|
|
|
vid.rowbytes = vid.conrowbytes = vid.width;
|
|
|
|
|
2012-10-07 07:09:29 +00:00
|
|
|
D_InitCaches(vid_surfcache, vid_surfcachesize);
|
|
|
|
|
|
|
|
window_width = vid.width;
|
|
|
|
window_height = vid.height;
|
|
|
|
VID_UpdateWindowStatus();
|
|
|
|
|
2013-03-28 05:08:42 +00:00
|
|
|
vid_modenum = mode - modelist;
|
|
|
|
Cvar_SetValue("vid_mode", vid_modenum);
|
2012-10-07 07:09:29 +00:00
|
|
|
|
|
|
|
vid.recalc_refdef = 1;
|
|
|
|
|
2012-12-07 21:04:49 +00:00
|
|
|
#ifdef _WIN32
|
2012-10-20 05:55:42 +00:00
|
|
|
mainwindow=GetActiveWindow();
|
|
|
|
SendMessage(mainwindow, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)hIcon);
|
|
|
|
SendMessage(mainwindow, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)hIcon);
|
2012-12-07 21:04:49 +00:00
|
|
|
#endif
|
2012-10-20 05:55:42 +00:00
|
|
|
|
2012-12-09 06:54:12 +00:00
|
|
|
/* FIXME - hack to reset mouse grabs */
|
|
|
|
if (mouse_grab) {
|
|
|
|
_windowed_mouse.value = 1;
|
|
|
|
_windowed_mouse.callback(&_windowed_mouse);
|
|
|
|
}
|
|
|
|
|
2013-04-01 03:13:49 +00:00
|
|
|
Cvar_SetValue("vid_fullscreen", mode - modelist != 0);
|
|
|
|
Cvar_SetValue("vid_width", mode->width);
|
|
|
|
Cvar_SetValue("vid_height", mode->height);
|
|
|
|
Cvar_SetValue("vid_bpp", mode->bpp);
|
|
|
|
Cvar_SetValue("vid_refreshrate", mode->refresh);
|
|
|
|
|
2012-10-07 07:09:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
// The original defaults
|
|
|
|
#define BASEWIDTH 320
|
|
|
|
#define BASEHEIGHT 200
|
|
|
|
|
|
|
|
byte *VGA_pagebase;
|
|
|
|
int VGA_width, VGA_height, VGA_rowbytes, VGA_bufferrowbytes = 0;
|
|
|
|
|
|
|
|
void
|
2013-03-28 05:08:42 +00:00
|
|
|
VID_SetPalette(const byte *palette)
|
2012-10-07 07:09:29 +00:00
|
|
|
{
|
2012-12-07 21:04:49 +00:00
|
|
|
unsigned i, r, g, b;
|
2012-12-09 02:43:43 +00:00
|
|
|
|
|
|
|
switch (SDL_PIXELTYPE(sdl_format->format)) {
|
|
|
|
case SDL_PIXELTYPE_PACKED32:
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
r = palette[0];
|
|
|
|
g = palette[1];
|
|
|
|
b = palette[2];
|
|
|
|
palette += 3;
|
|
|
|
d_8to24table[i] = SDL_MapRGB(sdl_format, r, g, b);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_PIXELTYPE_PACKED16:
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
r = palette[0];
|
|
|
|
g = palette[1];
|
|
|
|
b = palette[2];
|
|
|
|
palette += 3;
|
|
|
|
d_8to16table[i] = SDL_MapRGB(sdl_format, r, g, b);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Sys_Error("%s: unsupported pixel format (%s)", __func__,
|
|
|
|
SDL_GetPixelFormatName(sdl_format->format));
|
2012-10-07 07:09:29 +00:00
|
|
|
}
|
2012-12-07 21:04:49 +00:00
|
|
|
|
|
|
|
palette_changed = true;
|
2012-10-07 07:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_screen_buffer(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-03-28 05:08:42 +00:00
|
|
|
VID_Init(const byte *palette)
|
2012-10-07 07:09:29 +00:00
|
|
|
{
|
2012-12-09 02:44:36 +00:00
|
|
|
int err;
|
|
|
|
SDL_DisplayMode desktop_mode;
|
2013-04-01 03:13:49 +00:00
|
|
|
qvidmode_t *mode;
|
|
|
|
qvidformat_t *format;
|
|
|
|
const qvidmode_t *setmode;
|
2012-12-09 02:44:36 +00:00
|
|
|
|
2013-03-27 06:52:59 +00:00
|
|
|
Cvar_RegisterVariable(&vid_mode);
|
|
|
|
Cvar_RegisterVariable(&vid_wait);
|
|
|
|
Cvar_RegisterVariable(&vid_nopageflip);
|
|
|
|
Cvar_RegisterVariable(&_vid_wait_override);
|
|
|
|
Cvar_RegisterVariable(&_vid_default_mode);
|
|
|
|
Cvar_RegisterVariable(&_vid_default_mode_win);
|
|
|
|
Cvar_RegisterVariable(&vid_fullscreen_mode);
|
|
|
|
Cvar_RegisterVariable(&vid_windowed_mode);
|
|
|
|
Cvar_RegisterVariable(&block_switch);
|
|
|
|
Cvar_RegisterVariable(&vid_window_x);
|
|
|
|
Cvar_RegisterVariable(&vid_window_y);
|
|
|
|
|
2013-04-01 03:13:49 +00:00
|
|
|
VID_InitModeCvars();
|
|
|
|
|
2013-03-27 06:52:59 +00:00
|
|
|
Cmd_AddCommand("vid_describemodes", VID_DescribeModes_f);
|
|
|
|
|
2012-12-07 21:04:49 +00:00
|
|
|
/*
|
|
|
|
* Init SDL and the video subsystem
|
|
|
|
*/
|
|
|
|
Q_SDL_InitOnce();
|
2012-12-11 05:54:26 +00:00
|
|
|
err = SDL_InitSubSystem(SDL_INIT_VIDEO);
|
|
|
|
if (err < 0)
|
2012-10-07 07:09:29 +00:00
|
|
|
Sys_Error("VID: Couldn't load SDL: %s", SDL_GetError());
|
|
|
|
|
2012-12-09 02:44:36 +00:00
|
|
|
err = SDL_GetDesktopDisplayMode(0, &desktop_mode);
|
|
|
|
if (err)
|
|
|
|
Sys_Error("%s: Unable to query desktop display mode (%s)",
|
|
|
|
__func__, SDL_GetError());
|
|
|
|
sdl_desktop_format = SDL_AllocFormat(desktop_mode.format);
|
|
|
|
if (!sdl_desktop_format)
|
|
|
|
Sys_Error("%s: Unable to allocate desktop pixel format (%s)",
|
|
|
|
__func__, SDL_GetError());
|
|
|
|
|
2013-04-01 03:13:49 +00:00
|
|
|
/* Init default windowed mode */
|
|
|
|
mode = modelist;
|
|
|
|
mode->modenum = 0;
|
|
|
|
mode->bpp = sdl_desktop_format->BitsPerPixel;
|
|
|
|
format = (qvidformat_t *)mode->driverdata;
|
|
|
|
format->format = sdl_desktop_format->format;
|
|
|
|
mode->refresh = desktop_mode.refresh_rate;
|
|
|
|
mode->width = 640;
|
|
|
|
mode->height = 480;
|
|
|
|
nummodes = 1;
|
|
|
|
|
|
|
|
/* TODO: read config files first to avoid multiple mode sets */
|
2012-10-07 07:09:29 +00:00
|
|
|
VID_InitModeList();
|
2013-04-01 03:13:49 +00:00
|
|
|
setmode = VID_GetCmdlineMode();
|
|
|
|
if (!setmode)
|
|
|
|
setmode = &modelist[0];
|
2012-10-07 07:09:29 +00:00
|
|
|
|
2013-04-01 03:13:49 +00:00
|
|
|
VID_SetMode(setmode, palette);
|
2012-10-07 07:09:29 +00:00
|
|
|
|
2012-12-07 21:04:49 +00:00
|
|
|
#ifdef _WIN32
|
2012-10-07 07:09:29 +00:00
|
|
|
mainwindow=GetActiveWindow();
|
|
|
|
SendMessage(mainwindow, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)hIcon);
|
|
|
|
SendMessage(mainwindow, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)hIcon);
|
2012-12-07 21:04:49 +00:00
|
|
|
#endif
|
2012-10-07 07:09:29 +00:00
|
|
|
|
|
|
|
vid_menudrawfn = VID_MenuDraw;
|
|
|
|
vid_menukeyfn = VID_MenuKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VID_Update(vrect_t *rects)
|
|
|
|
{
|
2012-12-07 21:04:49 +00:00
|
|
|
SDL_Rect subrect;
|
|
|
|
int i;
|
2012-10-07 07:09:29 +00:00
|
|
|
vrect_t *rect;
|
2012-12-07 21:04:49 +00:00
|
|
|
vrect_t fullrect;
|
|
|
|
byte *src;
|
2012-12-09 02:43:43 +00:00
|
|
|
void *dst;
|
|
|
|
Uint32 *dst32;
|
|
|
|
Uint16 *dst16;
|
2012-12-07 21:04:49 +00:00
|
|
|
int pitch;
|
|
|
|
int height;
|
|
|
|
int err;
|
2013-03-28 05:08:42 +00:00
|
|
|
const qvidmode_t *mode;
|
2012-10-07 07:09:29 +00:00
|
|
|
|
2012-10-29 10:42:19 +00:00
|
|
|
/*
|
|
|
|
* Check for vid_mode changes
|
|
|
|
*/
|
2012-12-07 21:04:49 +00:00
|
|
|
if ((int)vid_mode.value != vid_modenum) {
|
2013-03-28 05:08:42 +00:00
|
|
|
mode = &modelist[(int)vid_mode.value];
|
|
|
|
VID_SetMode(mode, host_basepal);
|
2012-12-07 21:04:49 +00:00
|
|
|
/* FIXME - not the right place! redraw the scene to buffer first */
|
|
|
|
return;
|
|
|
|
}
|
2012-10-29 10:42:19 +00:00
|
|
|
|
2012-12-07 21:04:49 +00:00
|
|
|
/*
|
|
|
|
* If the palette changed, refresh the whole screen
|
|
|
|
*/
|
|
|
|
if (palette_changed) {
|
|
|
|
palette_changed = false;
|
|
|
|
fullrect.x = 0;
|
|
|
|
fullrect.y = 0;
|
|
|
|
fullrect.width = vid.width;
|
|
|
|
fullrect.height = vid.height;
|
|
|
|
fullrect.pnext = NULL;
|
|
|
|
rects = &fullrect;
|
|
|
|
}
|
2012-10-07 07:09:29 +00:00
|
|
|
|
|
|
|
for (rect = rects; rect; rect = rect->pnext) {
|
2012-12-07 21:04:49 +00:00
|
|
|
subrect.x = rect->x;
|
|
|
|
subrect.y = rect->y;
|
|
|
|
subrect.w = rect->width;
|
|
|
|
subrect.h = rect->height;
|
|
|
|
|
|
|
|
err = SDL_LockTexture(texture, &subrect, (void **)&dst, &pitch);
|
|
|
|
if (err)
|
|
|
|
Sys_Error("%s: unable to lock texture (%s)",
|
|
|
|
__func__, SDL_GetError());
|
|
|
|
src = vid.buffer + rect->y * vid.width + rect->x;
|
|
|
|
height = subrect.h;
|
2012-12-09 02:43:43 +00:00
|
|
|
switch (SDL_PIXELTYPE(sdl_format->format)) {
|
|
|
|
case SDL_PIXELTYPE_PACKED32:
|
|
|
|
dst32 = dst;
|
|
|
|
while (height--) {
|
|
|
|
for (i = 0; i < rect->width; i++)
|
|
|
|
dst32[i] = d_8to24table[src[i]];
|
|
|
|
dst32 += pitch / sizeof(*dst32);
|
|
|
|
src += vid.width;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_PIXELTYPE_PACKED16:
|
|
|
|
dst16 = dst;
|
|
|
|
while (height--) {
|
|
|
|
for (i = 0; i < rect->width; i++)
|
|
|
|
dst16[i] = d_8to16table[src[i]];
|
|
|
|
dst16 += pitch / sizeof(*dst16);
|
|
|
|
src += vid.width;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Sys_Error("%s: unsupported pixel format (%s)", __func__,
|
|
|
|
SDL_GetPixelFormatName(sdl_format->format));
|
2012-12-07 21:04:49 +00:00
|
|
|
}
|
|
|
|
SDL_UnlockTexture(texture);
|
2012-10-07 07:09:29 +00:00
|
|
|
}
|
2012-12-07 21:04:49 +00:00
|
|
|
err = SDL_RenderCopy(renderer, texture, NULL, NULL);
|
|
|
|
if (err)
|
|
|
|
Sys_Error("%s: unable to render texture (%s)", __func__, SDL_GetError());
|
|
|
|
SDL_RenderPresent(renderer);
|
2012-10-07 07:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-22 05:44:59 +00:00
|
|
|
D_BeginDirectRect(int x, int y, const byte *pbitmap, int width, int height)
|
2012-10-07 07:09:29 +00:00
|
|
|
{
|
2012-12-07 21:04:49 +00:00
|
|
|
int err, i;
|
2012-12-22 05:44:59 +00:00
|
|
|
const byte *src;
|
2012-12-07 21:04:49 +00:00
|
|
|
unsigned *dst;
|
|
|
|
int pitch;
|
|
|
|
SDL_Rect subrect;
|
2012-10-07 07:09:29 +00:00
|
|
|
|
2012-12-07 21:04:49 +00:00
|
|
|
if (!texture || !renderer)
|
2012-10-07 07:09:29 +00:00
|
|
|
return;
|
2012-12-07 21:04:49 +00:00
|
|
|
|
|
|
|
subrect.x = (x < 0) ? vid.width + x - 1 : x;
|
|
|
|
subrect.y = y;
|
|
|
|
subrect.w = width;
|
|
|
|
subrect.h = height;
|
|
|
|
|
|
|
|
err = SDL_LockTexture(texture, &subrect, (void **)&dst, &pitch);
|
|
|
|
if (err)
|
|
|
|
Sys_Error("%s: unable to lock texture (%s)", __func__, SDL_GetError());
|
|
|
|
src = pbitmap;
|
2012-10-07 07:09:29 +00:00
|
|
|
while (height--) {
|
2012-12-07 21:04:49 +00:00
|
|
|
for (i = 0; i < width; i++)
|
|
|
|
dst[i] = d_8to24table[src[i]];
|
|
|
|
dst += pitch / sizeof(*dst);
|
|
|
|
src += width;
|
2012-10-07 07:09:29 +00:00
|
|
|
}
|
2012-12-07 21:04:49 +00:00
|
|
|
SDL_UnlockTexture(texture);
|
|
|
|
|
|
|
|
err = SDL_RenderCopy(renderer, texture, NULL, NULL);
|
|
|
|
if (err)
|
|
|
|
Sys_Error("%s: unable to render texture (%s)", __func__, SDL_GetError());
|
|
|
|
SDL_RenderPresent(renderer);
|
2012-10-07 07:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
D_EndDirectRect(int x, int y, int width, int height)
|
|
|
|
{
|
2012-12-07 21:04:49 +00:00
|
|
|
int err, i;
|
|
|
|
byte *src;
|
|
|
|
unsigned *dst;
|
|
|
|
int pitch;
|
|
|
|
SDL_Rect subrect;
|
|
|
|
|
|
|
|
if (!texture || !renderer)
|
2012-10-07 07:09:29 +00:00
|
|
|
return;
|
2012-12-07 21:04:49 +00:00
|
|
|
|
|
|
|
subrect.x = (x < 0) ? vid.width + x - 1 : x;
|
|
|
|
subrect.y = y;
|
|
|
|
subrect.w = width;
|
|
|
|
subrect.h = height;
|
|
|
|
|
|
|
|
err = SDL_LockTexture(texture, &subrect, (void **)&dst, &pitch);
|
|
|
|
if (err)
|
|
|
|
Sys_Error("%s: unable to lock texture (%s)", __func__, SDL_GetError());
|
|
|
|
src = vid.buffer + y * vid.width + subrect.x;
|
|
|
|
while (height--) {
|
|
|
|
for (i = 0; i < width; i++)
|
|
|
|
dst[i] = d_8to24table[src[i]];
|
|
|
|
dst += pitch / sizeof(*dst);
|
|
|
|
src += vid.width;
|
|
|
|
}
|
|
|
|
SDL_UnlockTexture(texture);
|
|
|
|
|
|
|
|
err = SDL_RenderCopy(renderer, texture, NULL, NULL);
|
|
|
|
if (err)
|
|
|
|
Sys_Error("%s: unable to render texture (%s)", __func__, SDL_GetError());
|
|
|
|
SDL_RenderPresent(renderer);
|
2012-10-07 07:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VID_LockBuffer(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VID_UnlockBuffer(void)
|
|
|
|
{
|
|
|
|
}
|
2012-12-07 21:04:49 +00:00
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
void
|
|
|
|
Sys_SendKeyEvents(void)
|
|
|
|
{
|
2012-12-16 10:28:55 +00:00
|
|
|
IN_ProcessEvents();
|
2012-12-07 21:04:49 +00:00
|
|
|
}
|
|
|
|
#endif
|