2011-12-25 04:53:52 +00:00
|
|
|
/*
|
|
|
|
vid_common_glsl.c
|
|
|
|
|
|
|
|
Common OpenGLSL video driver functions
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
Copyright (C) 2011 Bill Currie <bill@taniwha.org>
|
|
|
|
|
|
|
|
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
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2011-12-25 04:53:52 +00:00
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_MATH_H
|
|
|
|
# include <math.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "QF/cvar.h"
|
2011-12-26 08:17:29 +00:00
|
|
|
#include "QF/dstring.h"
|
2011-12-25 04:53:52 +00:00
|
|
|
#include "QF/qargs.h"
|
|
|
|
#include "QF/quakefs.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
#include "QF/va.h"
|
|
|
|
#include "QF/vid.h"
|
2011-12-26 07:08:55 +00:00
|
|
|
#include "QF/GLSL/defines.h"
|
|
|
|
#include "QF/GLSL/funcs.h"
|
|
|
|
#include "QF/GLSL/qf_vid.h"
|
2012-01-02 02:19:23 +00:00
|
|
|
#include "QF/GLSL/qf_textures.h"
|
2011-12-25 04:53:52 +00:00
|
|
|
|
|
|
|
#include "compat.h"
|
|
|
|
#include "d_iface.h"
|
2012-02-15 00:50:40 +00:00
|
|
|
#include "r_internal.h"
|
2011-12-25 04:53:52 +00:00
|
|
|
|
2013-05-12 04:51:02 +00:00
|
|
|
static const char quakeforge_effect[] =
|
2020-06-21 14:15:17 +00:00
|
|
|
#include "libs/video/renderer/glsl/quakeforge.slc"
|
2013-05-12 04:51:02 +00:00
|
|
|
;
|
|
|
|
|
2012-02-18 13:28:42 +00:00
|
|
|
int glsl_palette;
|
|
|
|
int glsl_colormap;
|
2011-12-25 04:53:52 +00:00
|
|
|
|
|
|
|
static void
|
2012-02-17 09:57:13 +00:00
|
|
|
GLSL_Common_Init_Cvars (void)
|
2011-12-25 04:53:52 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-04-12 04:57:05 +00:00
|
|
|
void
|
2021-07-10 15:09:41 +00:00
|
|
|
GLSL_SetPalette (void *data, const byte *palette)
|
2011-12-25 04:53:52 +00:00
|
|
|
{
|
2012-04-12 04:57:05 +00:00
|
|
|
const byte *col, *ip;
|
|
|
|
byte *pal, *op;
|
|
|
|
unsigned r, g, b, v;
|
2011-12-25 04:53:52 +00:00
|
|
|
unsigned short i;
|
2012-04-12 04:57:05 +00:00
|
|
|
unsigned *table;
|
2011-12-25 04:53:52 +00:00
|
|
|
|
|
|
|
// 8 8 8 encoding
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_vid, "Converting 8to24\n");
|
2011-12-25 04:53:52 +00:00
|
|
|
|
|
|
|
table = d_8to24table;
|
|
|
|
for (i = 0; i < 255; i++) { // used to be i<256, see d_8to24table below
|
2012-04-12 04:57:05 +00:00
|
|
|
r = palette[i * 3 + 0];
|
|
|
|
g = palette[i * 3 + 1];
|
|
|
|
b = palette[i * 3 + 2];
|
2011-12-25 04:53:52 +00:00
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
v = (255 << 0) + (r << 24) + (g << 16) + (b << 8);
|
|
|
|
#else
|
|
|
|
v = (255 << 24) + (r << 0) + (g << 8) + (b << 16);
|
|
|
|
#endif
|
|
|
|
*table++ = v;
|
|
|
|
}
|
|
|
|
d_8to24table[255] = 0; // 255 is transparent
|
|
|
|
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_vid, "Converting palette/colormap to RGBA textures\n");
|
2012-01-14 12:42:42 +00:00
|
|
|
pal = malloc (256 * VID_GRADES * 4);
|
2012-02-26 05:00:15 +00:00
|
|
|
for (i = 0, col = vr_data.vid->colormap8, op = pal; i < 256 * VID_GRADES;
|
|
|
|
i++) {
|
2012-01-14 12:42:42 +00:00
|
|
|
ip = palette + *col++ * 3;
|
|
|
|
*op++ = *ip++;
|
|
|
|
*op++ = *ip++;
|
|
|
|
*op++ = *ip++;
|
|
|
|
*op++ = 255; // alpha = 1
|
|
|
|
}
|
|
|
|
for (i = 0; i < VID_GRADES; i++)
|
|
|
|
pal[i * 256 * 4 + 255 + 3] = 0;
|
|
|
|
|
|
|
|
if (!glsl_colormap) {
|
|
|
|
GLuint tex;
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglGenTextures (1, &tex);
|
2012-01-14 12:42:42 +00:00
|
|
|
glsl_colormap = tex;
|
|
|
|
}
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglBindTexture (GL_TEXTURE_2D, glsl_colormap);
|
|
|
|
qfeglTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 256, VID_GRADES, 0,
|
2012-01-14 12:42:42 +00:00
|
|
|
GL_RGBA, GL_UNSIGNED_BYTE, pal);
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
2012-01-14 12:42:42 +00:00
|
|
|
|
2012-01-14 13:20:23 +00:00
|
|
|
for (i = 0, ip = palette, op = pal; i < 255; i++) {
|
2011-12-26 01:41:16 +00:00
|
|
|
*op++ = *ip++;
|
|
|
|
*op++ = *ip++;
|
2011-12-25 04:53:52 +00:00
|
|
|
*op++ = *ip++;
|
|
|
|
*op++ = 255; // alpha = 1
|
|
|
|
}
|
2012-01-14 13:20:23 +00:00
|
|
|
QuatZero (op);
|
2011-12-25 04:53:52 +00:00
|
|
|
|
|
|
|
if (!glsl_palette) {
|
|
|
|
GLuint tex;
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglGenTextures (1, &tex);
|
2011-12-25 04:53:52 +00:00
|
|
|
glsl_palette = tex;
|
|
|
|
}
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglBindTexture (GL_TEXTURE_2D, glsl_palette);
|
|
|
|
qfeglTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 256, 1, 0,
|
2011-12-25 04:53:52 +00:00
|
|
|
GL_RGBA, GL_UNSIGNED_BYTE, pal);
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
qfeglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
2011-12-25 04:53:52 +00:00
|
|
|
free (pal);
|
|
|
|
}
|
|
|
|
|
2023-03-05 07:56:09 +00:00
|
|
|
void
|
|
|
|
GLSL_Shutdown_Common (void)
|
|
|
|
{
|
|
|
|
GLSL_ShaderShutdown ();
|
|
|
|
}
|
|
|
|
|
2011-12-25 04:53:52 +00:00
|
|
|
void
|
2012-02-22 07:48:57 +00:00
|
|
|
GLSL_Init_Common (void)
|
2011-12-25 04:53:52 +00:00
|
|
|
{
|
2012-02-22 07:48:57 +00:00
|
|
|
EGLF_FindFunctions ();
|
2011-12-25 04:53:52 +00:00
|
|
|
|
2012-02-17 09:57:13 +00:00
|
|
|
GLSL_Common_Init_Cvars ();
|
2011-12-25 04:53:52 +00:00
|
|
|
|
2012-02-17 09:57:13 +00:00
|
|
|
GLSL_TextureInit ();
|
2012-01-06 07:24:13 +00:00
|
|
|
|
[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 (developer & SYS_glsl) {
|
2012-04-29 12:15:27 +00:00
|
|
|
GLint max;
|
|
|
|
|
|
|
|
qfeglGetIntegerv (GL_MAX_VERTEX_UNIFORM_VECTORS, &max);
|
|
|
|
Sys_Printf ("max vertex uniform vectors: %d\n", max);
|
|
|
|
qfeglGetIntegerv (GL_MAX_FRAGMENT_UNIFORM_VECTORS, &max);
|
|
|
|
Sys_Printf ("max fragment uniforms: %d\n", max);
|
|
|
|
qfeglGetIntegerv (GL_MAX_TEXTURE_IMAGE_UNITS, &max);
|
|
|
|
Sys_Printf ("max texture image units: %d\n", max);
|
|
|
|
qfeglGetIntegerv (GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &max);
|
|
|
|
Sys_Printf ("max vertex texture image units: %d\n", max);
|
|
|
|
qfeglGetIntegerv (GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &max);
|
|
|
|
Sys_Printf ("max combined texture image units: %d\n", max);
|
|
|
|
qfeglGetIntegerv (GL_MAX_CUBE_MAP_TEXTURE_SIZE, &max);
|
|
|
|
Sys_Printf ("max cube map texture size: %d\n", max);
|
|
|
|
qfeglGetIntegerv (GL_MAX_RENDERBUFFER_SIZE, &max);
|
|
|
|
Sys_Printf ("max renderbuffer size: %d\n", max);
|
|
|
|
qfeglGetIntegerv (GL_MAX_VARYING_VECTORS, &max);
|
|
|
|
Sys_Printf ("max varying vectors: %d\n", max);
|
|
|
|
qfeglGetIntegerv (GL_MAX_VERTEX_ATTRIBS, &max);
|
|
|
|
Sys_Printf ("max vertex attribs: %d\n", max);
|
|
|
|
}
|
|
|
|
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglClearColor (0, 0, 0, 0);
|
2011-12-25 04:53:52 +00:00
|
|
|
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglPixelStorei (GL_UNPACK_ALIGNMENT, 1);
|
2012-01-08 17:18:39 +00:00
|
|
|
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglEnable (GL_TEXTURE_2D);
|
|
|
|
qfeglFrontFace (GL_CW);
|
|
|
|
qfeglCullFace (GL_BACK);
|
2011-12-25 04:53:52 +00:00
|
|
|
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglEnable (GL_BLEND);
|
|
|
|
qfeglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2013-05-12 04:51:02 +00:00
|
|
|
|
|
|
|
GLSL_RegisterEffect ("QuakeForge", quakeforge_effect);
|
2011-12-25 04:53:52 +00:00
|
|
|
}
|
|
|
|
|
2011-12-26 08:17:29 +00:00
|
|
|
int
|
2013-02-26 12:52:35 +00:00
|
|
|
GLSL_CompileShader (const char *name, const shader_t *shader, int type)
|
2011-12-26 08:17:29 +00:00
|
|
|
{
|
2013-02-26 12:52:35 +00:00
|
|
|
int sid;
|
2011-12-26 08:17:29 +00:00
|
|
|
int compiled;
|
|
|
|
|
2013-02-26 12:52:35 +00:00
|
|
|
sid = qfeglCreateShader (type);
|
|
|
|
qfeglShaderSource (sid, shader->num_strings, shader->strings, 0);
|
|
|
|
qfeglCompileShader (sid);
|
|
|
|
qfeglGetShaderiv (sid, GL_COMPILE_STATUS, &compiled);
|
[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 (!compiled || (developer & SYS_glsl)) {
|
2011-12-26 08:17:29 +00:00
|
|
|
dstring_t *log = dstring_new ();
|
|
|
|
int size;
|
2013-02-26 12:52:35 +00:00
|
|
|
qfeglGetShaderiv (sid, GL_INFO_LOG_LENGTH, &size);
|
2011-12-26 08:17:29 +00:00
|
|
|
log->size = size + 1; // for terminating null
|
|
|
|
dstring_adjust (log);
|
2013-02-26 12:52:35 +00:00
|
|
|
qfeglGetShaderInfoLog (sid, log->size, 0, log->str);
|
2011-12-28 03:40:28 +00:00
|
|
|
if (!compiled)
|
2013-02-26 12:52:35 +00:00
|
|
|
qfeglDeleteShader (sid);
|
2011-12-28 03:40:28 +00:00
|
|
|
Sys_Printf ("Shader (%s) compile log:\n----8<----\n%s----8<----\n",
|
2011-12-26 08:17:29 +00:00
|
|
|
name, log->str);
|
|
|
|
dstring_delete (log);
|
2011-12-28 03:40:28 +00:00
|
|
|
if (!compiled)
|
|
|
|
return 0;
|
2011-12-26 08:17:29 +00:00
|
|
|
}
|
2013-02-26 12:52:35 +00:00
|
|
|
return sid;
|
|
|
|
}
|
|
|
|
|
2011-12-28 03:40:28 +00:00
|
|
|
static const char *
|
|
|
|
type_name (GLenum type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case GL_FLOAT_VEC2:
|
|
|
|
return "vec2";
|
|
|
|
case GL_FLOAT_VEC3:
|
|
|
|
return "vec3";
|
|
|
|
case GL_FLOAT_VEC4:
|
|
|
|
return "vec4";
|
|
|
|
case GL_INT_VEC2:
|
|
|
|
return "ivec2";
|
|
|
|
case GL_INT_VEC3:
|
|
|
|
return "ivec3";
|
|
|
|
case GL_INT_VEC4:
|
|
|
|
return "ivec4";
|
|
|
|
case GL_BOOL:
|
|
|
|
return "bool";
|
|
|
|
case GL_BOOL_VEC2:
|
|
|
|
return "bvec2";
|
|
|
|
case GL_BOOL_VEC3:
|
|
|
|
return "bvec3";
|
|
|
|
case GL_BOOL_VEC4:
|
|
|
|
return "bvec4";
|
|
|
|
case GL_FLOAT_MAT2:
|
|
|
|
return "mat2";
|
|
|
|
case GL_FLOAT_MAT3:
|
|
|
|
return "mat3";
|
|
|
|
case GL_FLOAT_MAT4:
|
|
|
|
return "mat4";
|
|
|
|
case GL_SAMPLER_2D:
|
|
|
|
return "sampler_2d";
|
|
|
|
case GL_SAMPLER_CUBE:
|
|
|
|
return "sampler_cube";
|
|
|
|
case GL_BYTE:
|
|
|
|
return "byte";
|
|
|
|
case GL_UNSIGNED_BYTE:
|
|
|
|
return "unsigned byte";
|
|
|
|
case GL_SHORT:
|
|
|
|
return "short";
|
|
|
|
case GL_UNSIGNED_SHORT:
|
|
|
|
return "unsigned short";
|
|
|
|
case GL_INT:
|
|
|
|
return "int";
|
|
|
|
case GL_UNSIGNED_INT:
|
|
|
|
return "unsigned int";
|
|
|
|
case GL_FLOAT:
|
|
|
|
return "float";
|
|
|
|
case GL_FIXED:
|
|
|
|
return "fixed";
|
|
|
|
}
|
2021-01-31 07:01:20 +00:00
|
|
|
return va (0, "%x", type);
|
2011-12-28 03:40:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dump_program (const char *name, int program)
|
|
|
|
{
|
|
|
|
GLint ind = 0;
|
|
|
|
GLint count = 0;
|
|
|
|
GLint size;
|
|
|
|
dstring_t *pname;
|
|
|
|
GLint psize = 0;
|
|
|
|
GLenum ptype = 0;
|
|
|
|
|
|
|
|
pname = dstring_new ();
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglGetProgramiv (program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &size);
|
2011-12-28 03:40:28 +00:00
|
|
|
pname->size = size;
|
|
|
|
dstring_adjust (pname);
|
|
|
|
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglGetProgramiv(program, GL_ACTIVE_UNIFORMS, &count);
|
2012-01-02 01:22:03 +00:00
|
|
|
Sys_Printf("Program %s (%d) has %i uniforms\n", name, program, count);
|
2011-12-28 03:40:28 +00:00
|
|
|
for (ind = 0; ind < count; ind++) {
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglGetActiveUniform(program, ind, pname->size, 0, &psize, &ptype,
|
2011-12-28 03:40:28 +00:00
|
|
|
pname->str);
|
|
|
|
Sys_Printf ("Uniform %i name \"%s\" size %i type %s\n", (int)ind,
|
|
|
|
pname->str, (int)psize, type_name (ptype));
|
|
|
|
}
|
|
|
|
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglGetProgramiv (program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &size);
|
2011-12-28 03:40:28 +00:00
|
|
|
pname->size = size;
|
|
|
|
dstring_adjust (pname);
|
|
|
|
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &count);
|
2012-01-02 01:22:03 +00:00
|
|
|
Sys_Printf("Program %s (%d) has %i attributes\n", name, program, count);
|
2011-12-28 03:40:28 +00:00
|
|
|
for (ind = 0; ind < count; ind++) {
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglGetActiveAttrib(program, ind, pname->size, 0, &psize, &ptype,
|
2011-12-28 03:40:28 +00:00
|
|
|
pname->str);
|
|
|
|
Sys_Printf ("Attribute %i name \"%s\" size %i type %s\n", (int)ind,
|
|
|
|
pname->str, (int)psize, type_name (ptype));
|
|
|
|
}
|
2012-01-29 13:32:35 +00:00
|
|
|
dstring_delete (pname);
|
2011-12-28 03:40:28 +00:00
|
|
|
}
|
|
|
|
|
2011-12-26 08:17:29 +00:00
|
|
|
int
|
2012-02-17 09:57:13 +00:00
|
|
|
GLSL_LinkProgram (const char *name, int vert, int frag)
|
2011-12-26 08:17:29 +00:00
|
|
|
{
|
|
|
|
int program;
|
|
|
|
int linked;
|
|
|
|
|
2012-02-22 07:48:57 +00:00
|
|
|
program = qfeglCreateProgram ();
|
|
|
|
qfeglAttachShader (program, vert);
|
|
|
|
qfeglAttachShader (program, frag);
|
|
|
|
qfeglLinkProgram (program);
|
2011-12-26 08:17:29 +00:00
|
|
|
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglGetProgramiv (program, GL_LINK_STATUS, &linked);
|
[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 (!linked || (developer & SYS_glsl)) {
|
2011-12-26 08:17:29 +00:00
|
|
|
dstring_t *log = dstring_new ();
|
|
|
|
int size;
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglGetProgramiv (program, GL_INFO_LOG_LENGTH, &size);
|
2011-12-26 08:17:29 +00:00
|
|
|
log->size = size + 1; // for terminating null
|
|
|
|
dstring_adjust (log);
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglGetProgramInfoLog (program, log->size, 0, log->str);
|
2011-12-28 03:40:28 +00:00
|
|
|
if (!linked)
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglDeleteProgram (program);
|
2011-12-28 03:40:28 +00:00
|
|
|
Sys_Printf ("Program (%s) link log:\n----8<----\n%s----8<----\n",
|
2011-12-26 08:17:29 +00:00
|
|
|
name, log->str);
|
|
|
|
dstring_delete (log);
|
2011-12-28 03:40:28 +00:00
|
|
|
if (!linked)
|
|
|
|
return 0;
|
2011-12-26 08:17:29 +00:00
|
|
|
}
|
[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 (developer & SYS_glsl)
|
2011-12-28 03:40:28 +00:00
|
|
|
dump_program (name, program);
|
2011-12-26 08:17:29 +00:00
|
|
|
return program;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-02-17 09:57:13 +00:00
|
|
|
GLSL_ResolveShaderParam (int program, shaderparam_t *param)
|
2011-12-26 08:17:29 +00:00
|
|
|
{
|
|
|
|
if (param->uniform) {
|
2012-02-22 07:48:57 +00:00
|
|
|
param->location = qfeglGetUniformLocation (program, param->name);
|
2011-12-26 08:17:29 +00:00
|
|
|
} else {
|
2012-02-22 07:48:57 +00:00
|
|
|
param->location = qfeglGetAttribLocation (program, param->name);
|
2011-12-26 08:17:29 +00:00
|
|
|
}
|
|
|
|
if (param->location < 0) {
|
|
|
|
Sys_Printf ("could not resolve %s %s\n",
|
|
|
|
param->uniform ? "uniform" : "attribute", param->name);
|
2011-12-28 03:57:14 +00:00
|
|
|
} else {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_glsl, "Resolved %s %s @ %d\n",
|
2011-12-28 03:57:14 +00:00
|
|
|
param->uniform ? "uniform" : "attribute",
|
|
|
|
param->name, param->location);
|
2011-12-26 08:17:29 +00:00
|
|
|
}
|
|
|
|
return param->location;
|
|
|
|
}
|
2011-12-28 05:27:59 +00:00
|
|
|
|
|
|
|
void
|
2012-02-17 09:57:13 +00:00
|
|
|
GLSL_DumpAttribArrays (void)
|
2011-12-28 05:27:59 +00:00
|
|
|
{
|
|
|
|
GLint max = 0;
|
|
|
|
GLint ind;
|
|
|
|
GLint enabled;
|
|
|
|
GLint size = -1;
|
|
|
|
GLint stride = -1;
|
|
|
|
GLint type = -1;
|
|
|
|
GLint norm = -1;
|
|
|
|
GLint binding = -1;
|
2011-12-28 11:41:26 +00:00
|
|
|
GLint current[4] = {-1, -1, -1, -1};
|
2011-12-28 05:27:59 +00:00
|
|
|
void *pointer = 0;
|
|
|
|
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglGetIntegerv (GL_MAX_VERTEX_ATTRIBS, &max);
|
2011-12-28 05:27:59 +00:00
|
|
|
|
|
|
|
for (ind = 0; ind < max; ind++) {
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglGetVertexAttribiv (ind, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &enabled);
|
2011-12-28 05:27:59 +00:00
|
|
|
Sys_Printf ("attrib %d: %sabled\n", ind, enabled ? "en" : "dis");
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglGetVertexAttribiv (ind, GL_VERTEX_ATTRIB_ARRAY_SIZE, &size);
|
|
|
|
qfeglGetVertexAttribiv (ind, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &stride);
|
|
|
|
qfeglGetVertexAttribiv (ind, GL_VERTEX_ATTRIB_ARRAY_TYPE, &type);
|
|
|
|
qfeglGetVertexAttribiv (ind, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &norm);
|
|
|
|
qfeglGetVertexAttribiv (ind, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING,
|
2011-12-28 05:27:59 +00:00
|
|
|
&binding);
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglGetVertexAttribiv (ind, GL_CURRENT_VERTEX_ATTRIB, current);
|
|
|
|
qfeglGetVertexAttribPointerv (ind, GL_VERTEX_ATTRIB_ARRAY_POINTER,
|
2011-12-28 05:27:59 +00:00
|
|
|
&pointer);
|
2011-12-28 11:41:26 +00:00
|
|
|
Sys_Printf (" %d %d '%s' %d %d (%d %d %d %d) %p\n", size, stride,
|
|
|
|
type_name (type), norm, binding, QuatExpand (current),
|
|
|
|
pointer);
|
2011-12-28 05:27:59 +00:00
|
|
|
}
|
|
|
|
}
|