2000-10-26 06:08:09 +00:00
|
|
|
/*
|
|
|
|
vid_common_gl.c
|
|
|
|
|
|
|
|
Common OpenGL video driver functions
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
|
|
|
|
|
|
|
|
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
|
2000-11-16 22:37:59 +00:00
|
|
|
|
|
|
|
$Id$
|
2000-10-26 06:08:09 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2000-11-16 22:37:59 +00:00
|
|
|
# include "config.h"
|
2000-11-16 15:07:48 +00:00
|
|
|
#endif
|
2000-12-30 18:26:29 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
2000-11-22 13:05:27 +00:00
|
|
|
|
2000-12-08 07:46:40 +00:00
|
|
|
#ifdef _WIN32
|
2000-12-10 10:54:04 +00:00
|
|
|
// must be BEFORE include gl/gl.h
|
2000-12-08 07:46:40 +00:00
|
|
|
# include "winquake.h"
|
|
|
|
#endif
|
2000-10-26 06:08:09 +00:00
|
|
|
|
2000-12-10 10:54:04 +00:00
|
|
|
#include <GL/gl.h>
|
|
|
|
|
2000-10-26 06:08:09 +00:00
|
|
|
#include "console.h"
|
2000-10-26 16:29:45 +00:00
|
|
|
#include "glquake.h"
|
|
|
|
#include "input.h"
|
2000-10-26 06:08:09 +00:00
|
|
|
#include "qargs.h"
|
2000-11-29 04:59:18 +00:00
|
|
|
#include "qfgl_ext.h"
|
2000-10-26 16:29:45 +00:00
|
|
|
#include "quakefs.h"
|
|
|
|
#include "sbar.h"
|
2000-10-26 06:08:09 +00:00
|
|
|
|
|
|
|
#define WARP_WIDTH 320
|
|
|
|
#define WARP_HEIGHT 200
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
//unsigned short d_8to16table[256];
|
|
|
|
unsigned int d_8to24table[256];
|
|
|
|
unsigned char d_15to8table[65536];
|
2000-10-26 06:08:09 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
cvar_t *vid_mode;
|
2000-10-26 06:08:09 +00:00
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
int texture_extension_number = 1;
|
|
|
|
float gldepthmin, gldepthmax;
|
2000-10-26 06:08:09 +00:00
|
|
|
|
|
|
|
const char *gl_vendor;
|
|
|
|
const char *gl_renderer;
|
|
|
|
const char *gl_version;
|
|
|
|
const char *gl_extensions;
|
|
|
|
|
|
|
|
// ARB Multitexture
|
2001-01-06 07:29:17 +00:00
|
|
|
qboolean gl_mtex_capable = false;
|
|
|
|
GLenum gl_mtex_enum = GL_TEXTURE0_ARB;
|
2000-10-26 06:08:09 +00:00
|
|
|
|
2001-01-06 07:29:17 +00:00
|
|
|
QF_glColorTableEXT qglColorTableEXT = NULL;
|
|
|
|
qboolean is8bit = false;
|
|
|
|
cvar_t *vid_use8bit;
|
2000-10-26 06:08:09 +00:00
|
|
|
|
2001-01-27 11:01:51 +00:00
|
|
|
extern int gl_filter_min, gl_filter_max;
|
|
|
|
|
2000-10-26 06:08:09 +00:00
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
CheckMultiTextureExtensions
|
|
|
|
|
2001-01-06 07:29:17 +00:00
|
|
|
Check for ARB multitexture support
|
2000-10-26 06:08:09 +00:00
|
|
|
*/
|
|
|
|
void
|
2000-10-27 10:17:38 +00:00
|
|
|
CheckMultiTextureExtensions (void)
|
2000-10-26 06:08:09 +00:00
|
|
|
{
|
2000-11-29 04:59:18 +00:00
|
|
|
Con_Printf ("Checking for multitexture: ");
|
2000-10-26 06:08:09 +00:00
|
|
|
if (COM_CheckParm ("-nomtex")) {
|
2001-01-06 07:29:17 +00:00
|
|
|
Con_Printf ("disabled.\n");
|
2000-10-26 06:08:09 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-12-08 06:10:50 +00:00
|
|
|
|
2000-11-29 04:59:18 +00:00
|
|
|
if (QFGL_ExtensionPresent ("GL_ARB_multitexture")) {
|
2001-01-06 07:29:17 +00:00
|
|
|
|
|
|
|
int max_texture_units = 0;
|
|
|
|
|
|
|
|
glGetIntegerv (GL_MAX_TEXTURE_UNITS_ARB, &max_texture_units);
|
|
|
|
if (max_texture_units >= 2) {
|
|
|
|
Con_Printf ("enabled, %d TMUs.\n", max_texture_units);
|
|
|
|
qglMultiTexCoord2f = QFGL_ExtensionAddress ("glMultiTexCoord2fARB");
|
|
|
|
qglActiveTexture = QFGL_ExtensionAddress ("glActiveTextureARB");
|
|
|
|
gl_mtex_enum = GL_TEXTURE0_ARB;
|
|
|
|
gl_mtex_capable = true;
|
|
|
|
} else {
|
|
|
|
Con_Printf ("disabled, not enough TMUs.\n");
|
|
|
|
}
|
2000-10-26 06:08:09 +00:00
|
|
|
} else {
|
2001-01-06 07:29:17 +00:00
|
|
|
Con_Printf ("not found.\n");
|
2000-10-26 06:08:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-16 13:05:57 +00:00
|
|
|
// LordHavoc: finds closest color match
|
|
|
|
byte
|
|
|
|
LHFindColor(unsigned char *palette, int first, int last, int r, int g, int b)
|
|
|
|
{
|
2001-03-16 13:48:24 +00:00
|
|
|
int i, bestdistance, bestcolor, distance, color[3];
|
2001-03-16 13:05:57 +00:00
|
|
|
bestdistance = 1000000000;
|
|
|
|
bestcolor = first;
|
|
|
|
color[0] = r;
|
|
|
|
color[1] = g;
|
|
|
|
color[2] = b;
|
|
|
|
palette += first * 3;
|
|
|
|
for (i = first;i < last;i++)
|
|
|
|
{
|
|
|
|
// LordHavoc: distance in color cube from desired color
|
|
|
|
distance = VectorDistance_fast(palette, color);
|
2001-03-16 13:48:24 +00:00
|
|
|
if (distance < bestdistance)
|
2001-03-16 13:05:57 +00:00
|
|
|
{
|
|
|
|
bestdistance = distance;
|
|
|
|
bestcolor = i;
|
|
|
|
}
|
|
|
|
palette += 3;
|
|
|
|
}
|
|
|
|
return bestcolor;
|
|
|
|
}
|
|
|
|
|
2000-10-26 06:08:09 +00:00
|
|
|
void
|
|
|
|
VID_SetPalette (unsigned char *palette)
|
|
|
|
{
|
2001-03-16 13:05:57 +00:00
|
|
|
byte *pal, *out;
|
2000-10-26 06:08:09 +00:00
|
|
|
unsigned short i;
|
2000-12-08 06:51:37 +00:00
|
|
|
QFile *f;
|
|
|
|
char s[255];
|
2000-10-26 06:08:09 +00:00
|
|
|
static qboolean palflag = false;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
// Con_Printf("Converting 8to24\n");
|
2000-10-26 06:08:09 +00:00
|
|
|
|
2001-03-16 13:05:57 +00:00
|
|
|
// LordHavoc: cleaned up stupid endian-specific table building,
|
|
|
|
// now builds directly as bytes
|
2000-10-26 06:08:09 +00:00
|
|
|
pal = palette;
|
2001-03-16 13:48:24 +00:00
|
|
|
out = (byte *)&d_8to24table;
|
2001-03-16 13:05:57 +00:00
|
|
|
for (i = 0; i < 255; i++) {
|
|
|
|
*out++ = *pal++;
|
|
|
|
*out++ = *pal++;
|
|
|
|
*out++ = *pal++;
|
|
|
|
*out++ = 255;
|
2000-10-26 06:08:09 +00:00
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
d_8to24table[255] = 0; // 255 is transparent
|
2000-10-26 06:08:09 +00:00
|
|
|
|
|
|
|
if (palflag)
|
|
|
|
return;
|
|
|
|
palflag = true;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
COM_FOpenFile ("glquake/15to8.pal", &f);
|
2000-10-26 06:08:09 +00:00
|
|
|
if (f) {
|
2001-03-16 13:05:57 +00:00
|
|
|
Qread (f, d_15to8table, 32768);
|
2000-12-08 06:51:37 +00:00
|
|
|
Qclose (f);
|
2000-10-26 06:08:09 +00:00
|
|
|
} else {
|
2001-03-16 13:05:57 +00:00
|
|
|
// LordHavoc: cleaned this up
|
|
|
|
Con_Printf("Building 15bit to 8bit color conversion table\n");
|
|
|
|
for (i = 0; i < 32768; i++) {
|
|
|
|
int r, g, b;
|
|
|
|
// split out to 8bit components
|
|
|
|
r = ((i & 0x001F) >> 0) << 3;
|
|
|
|
g = ((i & 0x03E0) >> 5) << 3;
|
|
|
|
b = ((i & 0x7C00) >> 10) << 3;
|
|
|
|
d_15to8table[i] = LHFindColor(palette, 0, 256, r, g, b);
|
2000-10-26 06:08:09 +00:00
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
snprintf (s, sizeof (s), "%s/glquake/15to8.pal", com_gamedir);
|
2000-10-26 06:08:09 +00:00
|
|
|
COM_CreatePath (s);
|
2000-12-08 06:51:37 +00:00
|
|
|
if ((f = Qopen (s, "wb")) != NULL) {
|
2001-03-16 13:05:57 +00:00
|
|
|
Qwrite (f, d_15to8table, 32768);
|
2000-12-08 06:51:37 +00:00
|
|
|
Qclose (f);
|
2000-10-26 06:08:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
GL_Init_Common
|
2000-10-26 06:08:09 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
GL_Init_Common (void)
|
|
|
|
{
|
|
|
|
gl_vendor = glGetString (GL_VENDOR);
|
|
|
|
Con_Printf ("GL_VENDOR: %s\n", gl_vendor);
|
|
|
|
gl_renderer = glGetString (GL_RENDERER);
|
|
|
|
Con_Printf ("GL_RENDERER: %s\n", gl_renderer);
|
|
|
|
|
|
|
|
gl_version = glGetString (GL_VERSION);
|
|
|
|
Con_Printf ("GL_VERSION: %s\n", gl_version);
|
|
|
|
gl_extensions = glGetString (GL_EXTENSIONS);
|
|
|
|
Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions);
|
|
|
|
|
2000-11-29 04:59:18 +00:00
|
|
|
glClearColor (0, 0, 0, 0);
|
|
|
|
glCullFace (GL_FRONT);
|
|
|
|
glEnable (GL_TEXTURE_2D);
|
2000-10-26 06:08:09 +00:00
|
|
|
|
2000-11-29 04:59:18 +00:00
|
|
|
glEnable (GL_ALPHA_TEST);
|
|
|
|
glAlphaFunc (GL_GREATER, 0.666);
|
2000-10-26 06:08:09 +00:00
|
|
|
|
|
|
|
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
|
|
|
|
|
|
|
|
glShadeModel (GL_FLAT);
|
|
|
|
|
2001-01-27 11:01:51 +00:00
|
|
|
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_min);
|
|
|
|
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
|
2000-11-29 04:59:18 +00:00
|
|
|
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
|
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
2000-10-26 06:08:09 +00:00
|
|
|
|
2000-11-29 04:59:18 +00:00
|
|
|
glEnable (GL_BLEND);
|
2000-10-26 06:08:09 +00:00
|
|
|
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
2000-11-29 04:59:18 +00:00
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
2000-10-26 06:08:09 +00:00
|
|
|
|
|
|
|
CheckMultiTextureExtensions ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
GL_BeginRendering
|
2000-10-26 06:08:09 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
GL_BeginRendering (int *x, int *y, int *width, int *height)
|
|
|
|
{
|
|
|
|
*x = *y = 0;
|
|
|
|
*width = scr_width;
|
|
|
|
*height = scr_height;
|
|
|
|
}
|
|
|
|
|
2000-11-29 04:59:18 +00:00
|
|
|
qboolean
|
|
|
|
VID_Is8bit (void)
|
2000-10-26 06:08:09 +00:00
|
|
|
{
|
|
|
|
return is8bit;
|
|
|
|
}
|
|
|
|
|
2000-11-29 04:59:18 +00:00
|
|
|
|
|
|
|
#ifdef GL_SHARED_TEXTURE_PALETTE_EXT
|
2000-11-16 22:37:59 +00:00
|
|
|
void
|
2000-11-29 04:59:18 +00:00
|
|
|
Tdfx_Init8bitPalette (void)
|
2000-10-26 06:08:09 +00:00
|
|
|
{
|
2000-11-16 22:37:59 +00:00
|
|
|
// Check for 8bit Extensions and initialize them.
|
2000-12-08 06:51:37 +00:00
|
|
|
int i;
|
2000-10-26 06:08:09 +00:00
|
|
|
|
2000-11-16 23:23:53 +00:00
|
|
|
if (is8bit) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-11-29 04:59:18 +00:00
|
|
|
if (QFGL_ExtensionPresent ("3DFX_set_global_palette")) {
|
2000-10-26 06:08:09 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
char *oldpal;
|
|
|
|
GLubyte table[256][4];
|
2000-11-29 04:59:18 +00:00
|
|
|
QF_gl3DfxSetPaletteEXT qgl3DfxSetPaletteEXT = NULL;
|
2000-10-26 06:08:09 +00:00
|
|
|
|
2000-12-08 07:46:40 +00:00
|
|
|
if (!(qgl3DfxSetPaletteEXT = QFGL_ExtensionAddress ("gl3DfxSetPaletteEXT"))) {
|
2000-11-16 23:23:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-11-16 22:37:59 +00:00
|
|
|
|
2000-11-16 23:23:53 +00:00
|
|
|
Con_Printf ("3DFX_set_global_palette.\n");
|
2000-10-26 06:08:09 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
oldpal = (char *) d_8to24table; // d_8to24table3dfx;
|
2000-11-16 22:37:59 +00:00
|
|
|
for (i = 0; i < 256; i++) {
|
2000-10-26 06:08:09 +00:00
|
|
|
table[i][2] = *oldpal++;
|
|
|
|
table[i][1] = *oldpal++;
|
|
|
|
table[i][0] = *oldpal++;
|
|
|
|
table[i][3] = 255;
|
|
|
|
oldpal++;
|
|
|
|
}
|
2000-11-21 09:10:35 +00:00
|
|
|
glEnable (GL_SHARED_TEXTURE_PALETTE_EXT);
|
2000-11-16 23:23:53 +00:00
|
|
|
qgl3DfxSetPaletteEXT ((GLuint *) table);
|
2000-10-26 06:08:09 +00:00
|
|
|
is8bit = true;
|
2000-11-16 22:37:59 +00:00
|
|
|
}
|
2000-10-26 06:08:09 +00:00
|
|
|
}
|
|
|
|
|
2000-12-22 09:22:54 +00:00
|
|
|
/*
|
|
|
|
* The GL_EXT_shared_texture_palette seems like an idea which is
|
|
|
|
* /almost/ a good idea, but seems to be severely broken with many
|
|
|
|
* drivers, as such it is disabled.
|
|
|
|
*
|
|
|
|
* It should be noted, that a palette object extension as suggested by
|
|
|
|
* the GL_EXT_shared_texture_palette spec might be a very good idea in
|
|
|
|
* general.
|
|
|
|
*/
|
2000-10-26 06:08:09 +00:00
|
|
|
void
|
2000-11-16 22:37:59 +00:00
|
|
|
Shared_Init8bitPalette (void)
|
2000-10-26 06:08:09 +00:00
|
|
|
{
|
2001-01-06 07:29:17 +00:00
|
|
|
int i;
|
|
|
|
GLubyte thePalette[256 * 3];
|
|
|
|
GLubyte *oldPalette, *newPalette;
|
2000-10-26 06:08:09 +00:00
|
|
|
|
2000-11-16 23:23:53 +00:00
|
|
|
if (is8bit) {
|
2000-10-26 06:08:09 +00:00
|
|
|
return;
|
2000-11-16 22:37:59 +00:00
|
|
|
}
|
2000-10-26 06:08:09 +00:00
|
|
|
|
2000-11-29 04:59:18 +00:00
|
|
|
if (QFGL_ExtensionPresent ("GL_EXT_shared_texture_palette")) {
|
|
|
|
if (!(qglColorTableEXT = QFGL_ExtensionAddress ("glColorTableEXT"))) {
|
2000-11-16 22:37:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-10-26 06:08:09 +00:00
|
|
|
|
2000-11-16 23:23:53 +00:00
|
|
|
Con_Printf ("GL_EXT_shared_texture_palette\n");
|
|
|
|
|
2001-01-06 07:29:17 +00:00
|
|
|
glEnable (GL_SHARED_TEXTURE_PALETTE_EXT);
|
2000-12-08 06:51:37 +00:00
|
|
|
oldPalette = (GLubyte *) d_8to24table; // d_8to24table3dfx;
|
2001-01-06 07:29:17 +00:00
|
|
|
newPalette = thePalette;
|
2000-11-21 09:10:35 +00:00
|
|
|
for (i = 0; i < 256; i++) {
|
2001-01-06 07:29:17 +00:00
|
|
|
*newPalette++ = *oldPalette++;
|
|
|
|
*newPalette++ = *oldPalette++;
|
|
|
|
*newPalette++ = *oldPalette++;
|
|
|
|
oldPalette++;
|
2000-11-16 23:23:53 +00:00
|
|
|
}
|
2000-12-28 06:45:19 +00:00
|
|
|
qglColorTableEXT (GL_SHARED_TEXTURE_PALETTE_EXT, GL_RGB, 256, GL_RGB,
|
2001-01-06 07:29:17 +00:00
|
|
|
GL_UNSIGNED_BYTE, (GLvoid *) thePalette);
|
2000-11-16 23:23:53 +00:00
|
|
|
is8bit = true;
|
|
|
|
}
|
2000-10-26 06:08:09 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
2000-11-14 21:45:34 +00:00
|
|
|
VID_Init8bitPalette (void)
|
2000-10-26 06:08:09 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
vid_use8bit =
|
2000-12-22 09:22:54 +00:00
|
|
|
Cvar_Get ("vid_use8bit", "0", CVAR_ROM, "Use 8-bit shared palettes.");
|
2000-11-23 07:21:46 +00:00
|
|
|
|
2000-11-29 04:59:18 +00:00
|
|
|
Con_Printf ("Checking for 8-bit extension: ");
|
2000-11-17 07:12:28 +00:00
|
|
|
if (vid_use8bit->int_val) {
|
2000-11-29 04:59:18 +00:00
|
|
|
#ifdef GL_SHARED_TEXTURE_PALETTE_EXT
|
|
|
|
Tdfx_Init8bitPalette ();
|
2001-01-06 07:29:17 +00:00
|
|
|
Shared_Init8bitPalette ();
|
2000-10-26 06:08:09 +00:00
|
|
|
#endif
|
2000-11-16 23:23:53 +00:00
|
|
|
if (!is8bit) {
|
2001-01-06 07:29:17 +00:00
|
|
|
Con_Printf ("not found.\n");
|
2000-11-16 23:23:53 +00:00
|
|
|
}
|
2000-11-23 07:21:46 +00:00
|
|
|
} else {
|
|
|
|
Con_Printf ("disabled.\n");
|
2000-10-26 06:08:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-11-16 22:37:59 +00:00
|
|
|
VID_LockBuffer (void)
|
2000-10-26 06:08:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-11-16 22:37:59 +00:00
|
|
|
VID_UnlockBuffer (void)
|
2000-10-26 06:08:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-12-08 07:46:40 +00:00
|
|
|
D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
|
2000-10-26 06:08:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
D_EndDirectRect (int x, int y, int width, int height)
|
|
|
|
{
|
|
|
|
}
|