1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
|
/*
Copyright (C) 2002-2003 A Nourai
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.
*/
// vid_common_gl.c -- Common code for vid_wgl.c and vid_glx.c
#include <SDL.h>
#include "quakedef.h"
#include "gl_model.h"
#include "gl_local.h"
const char *gl_vendor;
const char *gl_renderer;
const char *gl_version;
const char *gl_extensions;
int anisotropy_ext = 0;
qbool gl_mtexable = false;
int gl_textureunits = 1;
lpMTexFUNC qglMultiTexCoord2f = NULL;
lpSelTexFUNC qglActiveTexture = NULL;
qbool gl_combine = false;
qbool gl_add_ext = false;
float vid_gamma = 1.0;
byte vid_gamma_table[256];
unsigned short d_8to16table[256];
unsigned d_8to24table[256];
unsigned d_8to24table2[256];
byte color_white[4] = {255, 255, 255, 255};
byte color_black[4] = {0, 0, 0, 255};
void OnChange_gl_ext_texture_compression(cvar_t *, char *, qbool *);
cvar_t gl_strings = {"gl_strings", "", CVAR_ROM | CVAR_SILENT};
cvar_t gl_ext_texture_compression = {"gl_ext_texture_compression", "0", CVAR_SILENT, OnChange_gl_ext_texture_compression};
cvar_t gl_maxtmu2 = {"gl_maxtmu2", "0", CVAR_LATCH};
// GL_ARB_texture_non_power_of_two
qbool gl_support_arb_texture_non_power_of_two = false;
cvar_t gl_ext_arb_texture_non_power_of_two = {"gl_ext_arb_texture_non_power_of_two", "1", CVAR_LATCH};
/************************************* EXTENSIONS *************************************/
qbool CheckExtension (const char *extension) {
const char *start;
char *where, *terminator;
if (!gl_extensions && !(gl_extensions = (const char*) glGetString (GL_EXTENSIONS)))
return false;
if (!extension || *extension == 0 || strchr (extension, ' '))
return false;
for (start = gl_extensions; (where = strstr(start, extension)); start = terminator) {
terminator = where + strlen (extension);
if ((where == start || *(where - 1) == ' ') && (*terminator == 0 || *terminator == ' '))
return true;
}
return false;
}
void CheckMultiTextureExtensions (void) {
if (!COM_CheckParm("-nomtex") && CheckExtension("GL_ARB_multitexture")) {
if (strstr(gl_renderer, "Savage"))
return;
qglMultiTexCoord2f = SDL_GL_GetProcAddress("glMultiTexCoord2fARB");
qglActiveTexture = SDL_GL_GetProcAddress("glActiveTextureARB");
if (!qglMultiTexCoord2f || !qglActiveTexture)
return;
Com_Printf_State(PRINT_OK, "Multitexture extensions found\n");
gl_mtexable = true;
}
glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, (GLint *)&gl_textureunits);
gl_textureunits = min(gl_textureunits, 4);
if (COM_CheckParm("-maxtmu2") /*|| !strcmp(gl_vendor, "ATI Technologies Inc.")*/ || gl_maxtmu2.value)
gl_textureunits = min(gl_textureunits, 2);
if (gl_textureunits < 2)
gl_mtexable = false;
if (!gl_mtexable)
gl_textureunits = 1;
else
Com_Printf_State(PRINT_OK, "Enabled %i texture units on hardware\n", gl_textureunits);
}
void GL_CheckExtensions (void) {
CheckMultiTextureExtensions ();
gl_combine = CheckExtension("GL_ARB_texture_env_combine");
gl_add_ext = CheckExtension("GL_ARB_texture_env_add");
if (CheckExtension("GL_EXT_texture_filter_anisotropic")) {
int gl_anisotropy_factor_max;
anisotropy_ext = 1;
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_anisotropy_factor_max);
Com_Printf_State(PRINT_OK, "Anisotropic Filtering Extension Found (%d max)\n",gl_anisotropy_factor_max);
}
if (CheckExtension("GL_ARB_texture_compression")) {
Com_Printf_State(PRINT_OK, "Texture compression extensions found\n");
Cvar_SetCurrentGroup(CVAR_GROUP_TEXTURES);
Cvar_Register (&gl_ext_texture_compression);
Cvar_ResetCurrentGroup();
}
// GL_ARB_texture_non_power_of_two
// NOTE: we always register cvar even if ext is not supported.
// cvar added just to be able force OFF an extension.
Cvar_SetCurrentGroup(CVAR_GROUP_TEXTURES);
Cvar_Register (&gl_ext_arb_texture_non_power_of_two);
Cvar_ResetCurrentGroup();
gl_support_arb_texture_non_power_of_two =
gl_ext_arb_texture_non_power_of_two.integer && CheckExtension("GL_ARB_texture_non_power_of_two");
Com_Printf_State(PRINT_OK, "GL_ARB_texture_non_power_of_two extension %s\n",
gl_support_arb_texture_non_power_of_two ? "found" : "not found");
}
void OnChange_gl_ext_texture_compression(cvar_t *var, char *string, qbool *cancel) {
float newval = Q_atof(string);
gl_alpha_format = newval ? GL_COMPRESSED_RGBA_ARB : GL_RGBA;
gl_solid_format = newval ? GL_COMPRESSED_RGB_ARB : GL_RGB;
}
/************************************** GL INIT **************************************/
void GL_Init (void) {
gl_vendor = (const char*) glGetString (GL_VENDOR);
gl_renderer = (const char*) glGetString (GL_RENDERER);
gl_version = (const char*) glGetString (GL_VERSION);
gl_extensions = (const char*) glGetString (GL_EXTENSIONS);
#if !defined( _WIN32 ) && !defined( __linux__ ) /* we print this in different place on WIN and Linux */
/* FIXME/TODO: FreeBSD too? */
Com_Printf_State(PRINT_INFO, "GL_VENDOR: %s\n", gl_vendor);
Com_Printf_State(PRINT_INFO, "GL_RENDERER: %s\n", gl_renderer);
Com_Printf_State(PRINT_INFO, "GL_VERSION: %s\n", gl_version);
#endif
if (COM_CheckParm("-gl_ext"))
Com_Printf_State(PRINT_INFO, "GL_EXTENSIONS: %s\n", gl_extensions);
Cvar_Register (&gl_strings);
Cvar_ForceSet (&gl_strings, va("GL_VENDOR: %s\nGL_RENDERER: %s\n"
"GL_VERSION: %s\nGL_EXTENSIONS: %s", gl_vendor, gl_renderer, gl_version, gl_extensions));
Cvar_Register (&gl_maxtmu2);
#ifndef __APPLE__
glClearColor (1,0,0,0);
#else
glClearColor (0.2,0.2,0.2,1.0);
#endif
glCullFace(GL_FRONT);
glEnable(GL_TEXTURE_2D);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.666);
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
glShadeModel (GL_FLAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
GL_CheckExtensions();
}
/************************************* VID GAMMA *************************************/
void Check_Gamma (unsigned char *pal) {
float inf;
unsigned char palette[768];
int i;
// we do not need this after host initialized
if (!host_initialized)
{
float old = v_gamma.value;
if ((i = COM_CheckParm("-gamma")) != 0 && i + 1 < COM_Argc())
vid_gamma = bound (0.3, Q_atof(COM_Argv(i + 1)), 1);
else
vid_gamma = 1;
Cvar_SetDefault (&v_gamma, vid_gamma);
// Cvar_SetDefault set not only default value, but also reset to default, fix that
Cvar_SetValue(&v_gamma, old ? old : vid_gamma);
}
if (vid_gamma != 1){
for (i = 0; i < 256; i++){
inf = 255 * pow((i + 0.5) / 255.5, vid_gamma) + 0.5;
if (inf > 255)
inf = 255;
vid_gamma_table[i] = inf;
}
} else {
for (i = 0; i < 256; i++)
vid_gamma_table[i] = i;
}
for (i = 0; i < 768; i++)
palette[i] = vid_gamma_table[pal[i]];
memcpy (pal, palette, sizeof(palette));
}
/************************************* HW GAMMA *************************************/
void VID_SetPalette (unsigned char *palette) {
int i;
byte *pal;
unsigned r,g,b, v, *table;
// 8 8 8 encoding
// Macintosh has different byte order
pal = palette;
table = d_8to24table;
for (i = 0; i < 256; i++) {
r = pal[0];
g = pal[1];
b = pal[2];
pal += 3;
v = LittleLong ((255 << 24) + (r << 0) + (g << 8) + (b << 16));
*table++ = v;
}
d_8to24table[255] = 0; // 255 is transparent
// Tonik: create a brighter palette for bmodel textures
pal = palette;
table = d_8to24table2;
for (i = 0; i < 256; i++) {
r = pal[0] * (2.0 / 1.5); if (r > 255) r = 255;
g = pal[1] * (2.0 / 1.5); if (g > 255) g = 255;
b = pal[2] * (2.0 / 1.5); if (b > 255) b = 255;
pal += 3;
*table++ = LittleLong ((255 << 24) + (r << 0) + (g << 8) + (b << 16));
}
d_8to24table2[255] = 0; // 255 is transparent
}
|