2019-07-08 16:00:47 +00:00
|
|
|
/*
|
|
|
|
vid_sdl.c
|
|
|
|
|
|
|
|
Video driver for Sam Lantinga's Simple DirectMedia Layer
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <SDL.h>
|
|
|
|
|
|
|
|
#include "QF/console.h"
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/qendian.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
#include "QF/vid.h"
|
|
|
|
|
|
|
|
#include "context_sdl.h"
|
|
|
|
#include "d_iface.h"
|
|
|
|
#include "vid_internal.h"
|
|
|
|
#include "vid_gl.h"
|
|
|
|
|
|
|
|
// Define GLAPIENTRY to a useful value
|
|
|
|
#ifndef GLAPIENTRY
|
|
|
|
# ifdef _WIN32
|
|
|
|
# include <windows.h>
|
|
|
|
# define GLAPIENTRY WINAPI
|
|
|
|
# undef LoadImage
|
|
|
|
# else
|
|
|
|
# ifdef APIENTRY
|
|
|
|
# define GLAPIENTRY APIENTRY
|
|
|
|
# else
|
|
|
|
# define GLAPIENTRY
|
|
|
|
# endif
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void (GLAPIENTRY *qfglFinish) (void);
|
|
|
|
static int use_gl_procaddress = 0;
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
static char *gl_driver;
|
|
|
|
static cvar_t gl_driver_cvar = {
|
|
|
|
.name = "gl_driver",
|
|
|
|
.description =
|
|
|
|
"The OpenGL library to use. (path optional)",
|
|
|
|
.default_value = GL_DRIVER,
|
|
|
|
.flags = CVAR_ROM,
|
|
|
|
.value = { .type = 0, .value = &gl_driver },
|
|
|
|
};
|
2019-07-08 16:00:47 +00:00
|
|
|
|
|
|
|
static void *
|
2023-06-13 09:06:11 +00:00
|
|
|
QFGL_ProcAddress (const char *name, bool crit)
|
2019-07-08 16:00:47 +00:00
|
|
|
{
|
|
|
|
void *glfunc = NULL;
|
|
|
|
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_vid, "DEBUG: Finding symbol %s ... ", name);
|
2019-07-08 16:00:47 +00:00
|
|
|
|
|
|
|
glfunc = SDL_GL_GetProcAddress (name);
|
|
|
|
if (glfunc) {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_vid, "found [%p]\n", glfunc);
|
2019-07-08 16:00:47 +00:00
|
|
|
return glfunc;
|
|
|
|
}
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_vid, "not found\n");
|
2019-07-08 16:00:47 +00:00
|
|
|
|
|
|
|
if (crit) {
|
|
|
|
if (strncmp ("fxMesa", name, 6) == 0) {
|
|
|
|
Sys_Printf ("This target requires a special version of Mesa with "
|
|
|
|
"support for Glide and SVGAlib.\n");
|
|
|
|
Sys_Printf ("If you are in X, try using a GLX or SGL target.\n");
|
|
|
|
}
|
|
|
|
Sys_Error ("Couldn't load critical OpenGL function %s, exiting...",
|
|
|
|
name);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sdlgl_set_vid_mode (gl_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
sdl_flags |= SDL_OPENGL;
|
|
|
|
|
|
|
|
// Setup GL Attributes
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
|
|
|
|
// SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE, 0); // Try for 0, 8
|
|
|
|
// SDL_GL_SetAttribute (SDL_GL_STEREO, 1); // Someday...
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
int k;
|
|
|
|
int color[5] = {32, 24, 16, 15, 0};
|
|
|
|
int rgba[5][4] = {
|
|
|
|
{8, 8, 8, 0},
|
|
|
|
{8, 8, 8, 8},
|
|
|
|
{5, 6, 5, 0},
|
|
|
|
{5, 5, 5, 0},
|
|
|
|
{5, 5, 5, 1},
|
|
|
|
};
|
|
|
|
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_RED_SIZE, rgba[i][0]);
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, rgba[i][1]);
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, rgba[i][2]);
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE, rgba[i][3]);
|
|
|
|
|
|
|
|
for (j = 0; j < 5; j++) {
|
|
|
|
for (k = 32; k >= 16; k -= 8) {
|
|
|
|
SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, k);
|
|
|
|
if ((sdl_screen = SDL_SetVideoMode (viddef.width, viddef.height,
|
|
|
|
color[j], sdl_flags)))
|
|
|
|
goto success;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Sys_Error ("Couldn't set video mode: %s", SDL_GetError ());
|
|
|
|
SDL_Quit ();
|
|
|
|
|
|
|
|
success:
|
|
|
|
viddef.numpages = 2;
|
|
|
|
|
|
|
|
ctx->init_gl ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sdlgl_end_rendering (void)
|
|
|
|
{
|
|
|
|
qfglFinish ();
|
|
|
|
SDL_GL_SwapBuffers ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sdl_load_gl (void)
|
|
|
|
{
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (SDL_GL_LoadLibrary (gl_driver) != 0)
|
|
|
|
Sys_Error ("Couldn't load OpenGL library %s!", gl_driver);
|
2019-07-08 16:00:47 +00:00
|
|
|
|
|
|
|
use_gl_procaddress = 1;
|
|
|
|
|
|
|
|
qfglFinish = QFGL_ProcAddress ("glFinish", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
gl_ctx_t *
|
|
|
|
SDL_GL_Context (void)
|
|
|
|
{
|
|
|
|
gl_ctx_t *ctx = calloc (1, sizeof (gl_ctx_t));
|
|
|
|
ctx->load_gl = sdl_load_gl;
|
|
|
|
ctx->create_context = sdlgl_set_vid_mode;
|
|
|
|
ctx->get_proc_address = QFGL_ProcAddress;
|
|
|
|
ctx->end_rendering = sdlgl_end_rendering;
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SDL_GL_Init_Cvars ()
|
|
|
|
{
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Cvar_Register (&gl_driver_cvar, 0, 0);
|
2019-07-08 16:00:47 +00:00
|
|
|
}
|