mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2025-02-21 19:31:13 +00:00
Überarbeite das Render-Backend
This commit is contained in:
parent
f408d056db
commit
829f986109
4 changed files with 111 additions and 180 deletions
3
TODO
3
TODO
|
@ -6,7 +6,8 @@ Allgemein:
|
||||||
- Den Fenstertitel auf "Yamagi Quake II" ändern, ebenso alle Ausgaben
|
- Den Fenstertitel auf "Yamagi Quake II" ändern, ebenso alle Ausgaben
|
||||||
von "Quake 2" und "Quake II" ändern.
|
von "Quake 2" und "Quake II" ändern.
|
||||||
- Die Makefile sollte komplett neu geschrieben werden.
|
- Die Makefile sollte komplett neu geschrieben werden.
|
||||||
- Wieso durchläuft der Client seine Shutdown-Rotine doppelt?
|
- Wieso durchläuft der Client seine Shutdown-Rotine doppelt? Bekommen
|
||||||
|
wir es evtl hin, das sie auch rekursiv nicht mehr aufgerufen wird?
|
||||||
- Noch mal uncrustify über client/, common/, unix/ und sdl/
|
- Noch mal uncrustify über client/, common/, unix/ und sdl/
|
||||||
|
|
||||||
Unix / SDL:
|
Unix / SDL:
|
||||||
|
|
|
@ -1063,7 +1063,7 @@ int R_Init( void *hinstance, void *hWnd )
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize OS-specific parts of OpenGL
|
// initialize OS-specific parts of OpenGL
|
||||||
if ( !GLimp_Init( hinstance, hWnd ) )
|
if ( !GLimp_Init() )
|
||||||
{
|
{
|
||||||
QGL_Shutdown();
|
QGL_Shutdown();
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1312,8 +1312,6 @@ void R_BeginFrame( float camera_separation )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GLimp_BeginFrame( camera_separation );
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** go into 2D mode
|
** go into 2D mode
|
||||||
*/
|
*/
|
||||||
|
@ -1544,7 +1542,7 @@ refexport_t GetRefAPI (refimport_t rimp )
|
||||||
re.BeginFrame = R_BeginFrame;
|
re.BeginFrame = R_BeginFrame;
|
||||||
re.EndFrame = GLimp_EndFrame;
|
re.EndFrame = GLimp_EndFrame;
|
||||||
|
|
||||||
re.AppActivate = GLimp_AppActivate;
|
re.AppActivate = NULL;
|
||||||
|
|
||||||
Swap_Init ();
|
Swap_Init ();
|
||||||
|
|
||||||
|
|
|
@ -434,7 +434,7 @@ IMPLEMENTATION SPECIFIC FUNCTIONS
|
||||||
|
|
||||||
void GLimp_BeginFrame( float camera_separation );
|
void GLimp_BeginFrame( float camera_separation );
|
||||||
void GLimp_EndFrame( void );
|
void GLimp_EndFrame( void );
|
||||||
int GLimp_Init( void *hinstance, void *hWnd );
|
int GLimp_Init( void );
|
||||||
void GLimp_Shutdown( void );
|
void GLimp_Shutdown( void );
|
||||||
int GLimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen );
|
int GLimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen );
|
||||||
void GLimp_AppActivate( qboolean active );
|
void GLimp_AppActivate( qboolean active );
|
||||||
|
|
|
@ -1,114 +1,76 @@
|
||||||
/*
|
|
||||||
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:
|
|
||||||
|
|
||||||
Free Software Foundation, Inc.
|
|
||||||
59 Temple Place - Suite 330
|
|
||||||
Boston, MA 02111-1307, USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
#include <SDL.h>
|
||||||
#include "SDL.h"
|
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
|
|
||||||
#include "../refresh/header/local.h"
|
#include "../refresh/header/local.h"
|
||||||
#include "../unix/header/glwindow.h"
|
#include "../unix/header/glwindow.h"
|
||||||
|
|
||||||
#include "../client/input/header/keyboard.h"
|
/* The window icon */
|
||||||
#include "../unix/header/unix.h"
|
#include "icon/q2icon.xbm"
|
||||||
|
|
||||||
/*****************************************************************************/
|
SDL_Surface *surface;
|
||||||
|
glwstate_t glw_state;
|
||||||
|
static cvar_t *use_stencil;
|
||||||
|
qboolean have_stencil = false;
|
||||||
|
|
||||||
static qboolean X11_active = false;
|
/*
|
||||||
|
* Initialzes the SDL OpenGL context
|
||||||
qboolean have_stencil = false;
|
*/
|
||||||
|
int GLimp_Init(void)
|
||||||
SDL_Surface *surface;
|
|
||||||
|
|
||||||
int config_notify=0;
|
|
||||||
int config_notify_width;
|
|
||||||
int config_notify_height;
|
|
||||||
|
|
||||||
glwstate_t glw_state;
|
|
||||||
static cvar_t *use_stencil;
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/* MOUSE */
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
int SWimp_Init( void *hInstance, void *wndProc )
|
|
||||||
{
|
{
|
||||||
if (SDL_WasInit(SDL_INIT_AUDIO|SDL_INIT_CDROM|SDL_INIT_VIDEO) == 0) {
|
if (!SDL_WasInit(SDL_INIT_VIDEO))
|
||||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
{
|
||||||
Sys_Error("SDL Init failed: %s\n", SDL_GetError());
|
char driverName[ 64 ];
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else if (SDL_WasInit(SDL_INIT_VIDEO) == 0) {
|
|
||||||
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
|
|
||||||
Sys_Error("SDL Init failed: %s\n", SDL_GetError());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
if (SDL_Init(SDL_INIT_VIDEO) == -1)
|
||||||
}
|
{
|
||||||
|
ri.Con_Printf( PRINT_ALL, "\nSDL_Init( SDL_INIT_VIDEO ) FAILED (%s)\n", SDL_GetError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
SDL_VideoDriverName( driverName, sizeof( driverName ) - 1 );
|
||||||
|
ri.Con_Printf( PRINT_ALL, "\nSDL using driver \"%s\"\n", driverName );
|
||||||
|
}
|
||||||
|
|
||||||
void *GLimp_GetProcAddress(const char *func)
|
return true;
|
||||||
{
|
|
||||||
return SDL_GL_GetProcAddress(func);
|
|
||||||
}
|
|
||||||
|
|
||||||
int GLimp_Init( void *hInstance, void *wndProc )
|
|
||||||
{
|
|
||||||
return SWimp_Init(hInstance, wndProc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SetSDLIcon()
|
static void SetSDLIcon()
|
||||||
{
|
{
|
||||||
#include "icon/q2icon.xbm"
|
|
||||||
SDL_Surface *icon;
|
SDL_Surface *icon;
|
||||||
SDL_Color color;
|
SDL_Color color;
|
||||||
Uint8 *ptr;
|
Uint8 *ptr;
|
||||||
int i, mask;
|
int i;
|
||||||
|
int mask;
|
||||||
|
|
||||||
icon = SDL_CreateRGBSurface(SDL_SWSURFACE, q2icon_width, q2icon_height, 8, 0, 0, 0, 0);
|
icon = SDL_CreateRGBSurface(SDL_SWSURFACE, q2icon_width, q2icon_height, 8, 0, 0, 0, 0);
|
||||||
|
|
||||||
if (icon == NULL)
|
if (icon == NULL)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SDL_SetColorKey(icon, SDL_SRCCOLORKEY, 0);
|
SDL_SetColorKey(icon, SDL_SRCCOLORKEY, 0);
|
||||||
|
|
||||||
color.r = 255;
|
color.r = 255;
|
||||||
color.g = 255;
|
color.g = 255;
|
||||||
color.b = 255;
|
color.b = 255;
|
||||||
|
|
||||||
SDL_SetColors(icon, &color, 0, 1);
|
SDL_SetColors(icon, &color, 0, 1);
|
||||||
|
|
||||||
color.r = 0;
|
color.r = 0;
|
||||||
color.g = 16;
|
color.g = 16;
|
||||||
color.b = 0;
|
color.b = 0;
|
||||||
|
|
||||||
SDL_SetColors(icon, &color, 1, 1);
|
SDL_SetColors(icon, &color, 1, 1);
|
||||||
|
|
||||||
ptr = (Uint8 *)icon->pixels;
|
ptr = (Uint8 *)icon->pixels;
|
||||||
for (i = 0; i < sizeof(q2icon_bits); i++) {
|
|
||||||
|
for (i = 0; i < sizeof(q2icon_bits); i++)
|
||||||
|
{
|
||||||
for (mask = 1; mask != 0x100; mask <<= 1) {
|
for (mask = 1; mask != 0x100; mask <<= 1) {
|
||||||
*ptr = (q2icon_bits[i] & mask) ? 1 : 0;
|
*ptr = (q2icon_bits[i] & mask) ? 1 : 0;
|
||||||
ptr++;
|
ptr++;
|
||||||
|
@ -122,90 +84,102 @@ static void SetSDLIcon()
|
||||||
void
|
void
|
||||||
UpdateHardwareGamma(void)
|
UpdateHardwareGamma(void)
|
||||||
{
|
{
|
||||||
float g = (1.3 - vid_gamma->value + 1);
|
float gamma;
|
||||||
g = (g > 1 ? g : 1);
|
|
||||||
|
gamma = (1.3 - vid_gamma->value + 1);
|
||||||
|
|
||||||
|
if (gamma < 1)
|
||||||
|
{
|
||||||
|
gamma = 1;
|
||||||
|
}
|
||||||
|
|
||||||
SDL_SetGamma(g, g, g);
|
SDL_SetGamma(gamma, gamma, gamma );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
SetSDLGamma(void)
|
|
||||||
{
|
|
||||||
gl_state.hwgamma = true;
|
|
||||||
vid_gamma->modified = true;
|
|
||||||
ri.Con_Printf(PRINT_ALL, "Using hardware gamma\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static qboolean GLimp_InitGraphics( qboolean fullscreen )
|
static qboolean GLimp_InitGraphics( qboolean fullscreen )
|
||||||
{
|
{
|
||||||
int flags;
|
int flags;
|
||||||
|
int stencil_bits;
|
||||||
|
|
||||||
if (surface && (surface->w == vid.width) && (surface->h == vid.height)) {
|
if (surface && (surface->w == vid.width) && (surface->h == vid.height))
|
||||||
|
{
|
||||||
|
/* Are we running fullscreen? */
|
||||||
int isfullscreen = (surface->flags & SDL_FULLSCREEN) ? 1 : 0;
|
int isfullscreen = (surface->flags & SDL_FULLSCREEN) ? 1 : 0;
|
||||||
if (fullscreen != isfullscreen)
|
|
||||||
SDL_WM_ToggleFullScreen(surface);
|
|
||||||
|
|
||||||
|
/* We should, but we don't */
|
||||||
|
if (fullscreen != isfullscreen)
|
||||||
|
{
|
||||||
|
SDL_WM_ToggleFullScreen(surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Do we now? */
|
||||||
isfullscreen = (surface->flags & SDL_FULLSCREEN) ? 1 : 0;
|
isfullscreen = (surface->flags & SDL_FULLSCREEN) ? 1 : 0;
|
||||||
|
|
||||||
if (fullscreen == isfullscreen)
|
if (fullscreen == isfullscreen)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
srandom(getpid());
|
/* Is the surface used? */
|
||||||
|
|
||||||
if (surface)
|
if (surface)
|
||||||
|
{
|
||||||
SDL_FreeSurface(surface);
|
SDL_FreeSurface(surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create the window */
|
||||||
ri.Vid_NewWindow (vid.width, vid.height);
|
ri.Vid_NewWindow (vid.width, vid.height);
|
||||||
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
|
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
|
||||||
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
|
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
|
||||||
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
|
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
|
||||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
|
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
||||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
|
||||||
|
|
||||||
if (use_stencil)
|
/* Initiate the flags */
|
||||||
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1);
|
|
||||||
|
|
||||||
flags = SDL_OPENGL;
|
flags = SDL_OPENGL;
|
||||||
|
|
||||||
if (fullscreen)
|
if (fullscreen)
|
||||||
|
{
|
||||||
flags |= SDL_FULLSCREEN;
|
flags |= SDL_FULLSCREEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set the icon */
|
||||||
SetSDLIcon();
|
SetSDLIcon();
|
||||||
|
|
||||||
if ((surface = SDL_SetVideoMode(vid.width, vid.height, 0, flags)) == NULL) {
|
if ((surface = SDL_SetVideoMode(vid.width, vid.height, 0, flags)) == NULL)
|
||||||
|
{
|
||||||
Sys_Error("(SDLGL) SDL SetVideoMode failed: %s\n", SDL_GetError());
|
Sys_Error("(SDLGL) SDL SetVideoMode failed: %s\n", SDL_GetError());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (use_stencil) {
|
/* Initialize the stencil buffer */
|
||||||
int stencil_bits;
|
if (!SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &stencil_bits))
|
||||||
|
{
|
||||||
have_stencil = false;
|
ri.Con_Printf(PRINT_ALL, "I: got %d bits of stencil\n", stencil_bits);
|
||||||
|
|
||||||
if (!SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &stencil_bits)) {
|
if (stencil_bits >= 1)
|
||||||
ri.Con_Printf(PRINT_ALL, "I: got %d bits of stencil\n",
|
{
|
||||||
stencil_bits);
|
have_stencil = true;
|
||||||
if (stencil_bits >= 1) {
|
}
|
||||||
have_stencil = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_WM_SetCaption("Quake II", "Quake II");
|
/* Initialize hardware gamma */
|
||||||
|
gl_state.hwgamma = true;
|
||||||
|
vid_gamma->modified = true;
|
||||||
|
ri.Con_Printf(PRINT_ALL, "Using hardware gamma\n");
|
||||||
|
ri.Con_Printf(PRINT_ALL, "If this doesn't work your X11 driver is broken!\n");
|
||||||
|
|
||||||
|
/* Window title */
|
||||||
|
SDL_WM_SetCaption("Yamagi Quake II", "Yamagi Quake II");
|
||||||
|
|
||||||
|
/* No cursor */
|
||||||
SDL_ShowCursor(0);
|
SDL_ShowCursor(0);
|
||||||
|
|
||||||
X11_active = true;
|
|
||||||
SetSDLGamma();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLimp_BeginFrame( float camera_seperation )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void GLimp_EndFrame (void)
|
void GLimp_EndFrame (void)
|
||||||
{
|
{
|
||||||
SDL_GL_SwapBuffers();
|
SDL_GL_SwapBuffers();
|
||||||
|
@ -216,8 +190,8 @@ int GLimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen )
|
||||||
{
|
{
|
||||||
ri.Con_Printf (PRINT_ALL, "setting mode %d:", mode );
|
ri.Con_Printf (PRINT_ALL, "setting mode %d:", mode );
|
||||||
|
|
||||||
// mode -1 is not in the vid mode table - so we keep the values in pwidth
|
/* mode -1 is not in the vid mode table - so we keep the values in pwidth
|
||||||
// and pheight and don't even try to look up the mode info
|
and pheight and don't even try to look up the mode info */
|
||||||
if ( mode != -1 && !ri.Vid_GetModeInfo( pwidth, pheight, mode ) )
|
if ( mode != -1 && !ri.Vid_GetModeInfo( pwidth, pheight, mode ) )
|
||||||
{
|
{
|
||||||
ri.Con_Printf( PRINT_ALL, " invalid mode\n" );
|
ri.Con_Printf( PRINT_ALL, " invalid mode\n" );
|
||||||
|
@ -226,74 +200,32 @@ int GLimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen )
|
||||||
|
|
||||||
ri.Con_Printf( PRINT_ALL, " %d %d\n", *pwidth, *pheight);
|
ri.Con_Printf( PRINT_ALL, " %d %d\n", *pwidth, *pheight);
|
||||||
|
|
||||||
if ( !GLimp_InitGraphics( fullscreen ) ) {
|
if ( !GLimp_InitGraphics( fullscreen ) )
|
||||||
|
{
|
||||||
return rserr_invalid_mode;
|
return rserr_invalid_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rserr_ok;
|
return rserr_ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GLimp_Shutdown( void )
|
void GLimp_Shutdown( void )
|
||||||
{
|
{
|
||||||
if (surface)
|
if (surface)
|
||||||
|
{
|
||||||
SDL_FreeSurface(surface);
|
SDL_FreeSurface(surface);
|
||||||
|
}
|
||||||
|
|
||||||
surface = NULL;
|
surface = NULL;
|
||||||
|
|
||||||
if (SDL_WasInit(SDL_INIT_EVERYTHING) == SDL_INIT_VIDEO)
|
if (SDL_WasInit(SDL_INIT_EVERYTHING) == SDL_INIT_VIDEO)
|
||||||
|
{
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||||
|
}
|
||||||
|
|
||||||
gl_state.hwgamma = false;
|
gl_state.hwgamma = false;
|
||||||
X11_active = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GLimp_AppActivate( qboolean active )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
//===============================================================================
|
|
||||||
|
|
||||||
/*
|
|
||||||
================
|
|
||||||
Sys_MakeCodeWriteable
|
|
||||||
================
|
|
||||||
*/
|
|
||||||
void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
|
|
||||||
{
|
|
||||||
|
|
||||||
int r;
|
|
||||||
unsigned long addr;
|
|
||||||
int psize = getpagesize();
|
|
||||||
|
|
||||||
addr = (startaddr & ~(psize-1)) - psize;
|
|
||||||
|
|
||||||
r = mprotect((char*)addr, length + startaddr - addr + psize, 7);
|
|
||||||
|
|
||||||
if (r < 0)
|
|
||||||
Sys_Error("Protection change failed\n");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/* KEYBOARD */
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
void Fake_glColorTableEXT( GLenum target, GLenum internalformat,
|
|
||||||
GLsizei width, GLenum format, GLenum type,
|
|
||||||
const GLvoid *table )
|
|
||||||
{
|
|
||||||
byte temptable[256][4];
|
|
||||||
byte *intbl;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (intbl = (byte *)table, i = 0; i < 256; i++) {
|
|
||||||
temptable[i][2] = *intbl++;
|
|
||||||
temptable[i][1] = *intbl++;
|
|
||||||
temptable[i][0] = *intbl++;
|
|
||||||
temptable[i][3] = 255;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue