mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2025-02-15 08:31:03 +00:00
Comments & formatting
This commit is contained in:
parent
0234ffe6ff
commit
376a437df8
6 changed files with 86 additions and 58 deletions
|
@ -1,5 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
# cgc from https://developer.nvidia.com/cg-toolkit
|
||||
|
||||
rm -f r_alias_vertexshader.h
|
||||
rm -f r_alias_vertexshader.vp
|
||||
|
||||
|
|
|
@ -347,7 +347,7 @@ void GL_MakeAliasModelDisplayLists (qmodel_t *m, aliashdr_t *hdr)
|
|||
for (i=0 ; i<paliashdr->numposes ; i++)
|
||||
for (j=0 ; j<numorder ; j++)
|
||||
*verts++ = poseverts[i][vertexorder[j]];
|
||||
|
||||
|
||||
// ericw
|
||||
GL_MakeAliasModelDisplayLists_VBO ();
|
||||
}
|
||||
|
@ -359,6 +359,9 @@ unsigned int r_meshvertexbuffer = 0;
|
|||
================
|
||||
GL_MakeAliasModelDisplayLists_VBO
|
||||
|
||||
Saves data needed to build the VBO for this model on the hunk. Afterwards this
|
||||
is copied to Mod_Extradata.
|
||||
|
||||
Original code by MH from RMQEngine
|
||||
================
|
||||
*/
|
||||
|
@ -372,14 +375,14 @@ void GL_MakeAliasModelDisplayLists_VBO (void)
|
|||
|
||||
if (!GLAlias_SupportsShaders())
|
||||
return;
|
||||
|
||||
|
||||
// first, copy the verts onto the hunk
|
||||
verts = (trivertx_t *) Hunk_Alloc (paliashdr->numposes * paliashdr->numverts * sizeof(trivertx_t));
|
||||
paliashdr->vertexes = (byte *)verts - (byte *)paliashdr;
|
||||
for (i=0 ; i<paliashdr->numposes ; i++)
|
||||
for (j=0 ; j<paliashdr->numverts ; j++)
|
||||
verts[i*paliashdr->numverts + j] = poseverts[i][j];
|
||||
|
||||
|
||||
// there can never be more than this number of verts and we just put them all on the hunk
|
||||
maxverts_vbo = pheader->numtris * 3;
|
||||
desc = (aliasmesh_t *) Hunk_Alloc (sizeof (aliasmesh_t) * maxverts_vbo);
|
||||
|
@ -445,6 +448,9 @@ GLuint r_meshindexesvbo = 0;
|
|||
================
|
||||
GLMesh_LoadVertexBuffers
|
||||
|
||||
Loop over all precached alias models, and upload them into one big VBO plus
|
||||
an GL_ELEMENT_ARRAY_BUFFER for the vertex indices.
|
||||
|
||||
Original code by MH from RMQEngine
|
||||
================
|
||||
*/
|
||||
|
@ -454,10 +460,10 @@ void GLMesh_LoadVertexBuffers (void)
|
|||
qmodel_t *m;
|
||||
int totalindexes = 0;
|
||||
int totalvbosize = 0;
|
||||
|
||||
|
||||
if (!GLAlias_SupportsShaders())
|
||||
return;
|
||||
|
||||
|
||||
// pass 1 - count the sizes we need
|
||||
for (j = 1; j < MAX_MODELS; j++)
|
||||
{
|
||||
|
@ -503,7 +509,7 @@ void GLMesh_LoadVertexBuffers (void)
|
|||
aliasmesh_t *desc;
|
||||
meshst_t *st;
|
||||
float hscale, vscale;
|
||||
|
||||
|
||||
if (!(m = cl.model_precache[j])) break;
|
||||
if (m->type != mod_alias) continue;
|
||||
|
||||
|
@ -529,7 +535,7 @@ void GLMesh_LoadVertexBuffers (void)
|
|||
for (v = 0; v < hdr->numverts_vbo; v++)
|
||||
{
|
||||
trivertx_t trivert = tv[desc[v].vertindex];
|
||||
|
||||
|
||||
xyz[v].xyz[0] = trivert.v[0];
|
||||
xyz[v].xyz[1] = trivert.v[1];
|
||||
xyz[v].xyz[2] = trivert.v[2];
|
||||
|
|
|
@ -325,29 +325,35 @@ void D_FlushCaches (void)
|
|||
static GLuint gl_arb_programs[16];
|
||||
static int gl_num_arb_programs = 0;
|
||||
|
||||
// from RMQEngine
|
||||
/*
|
||||
====================
|
||||
GL_CreateProgram
|
||||
|
||||
Compiles an ARB vertex program. from RMQEngine
|
||||
====================
|
||||
*/
|
||||
GLuint GL_CreateProgram (const GLchar *source)
|
||||
{
|
||||
GLuint progid;
|
||||
GLint errPos;
|
||||
const GLubyte *errString;
|
||||
GLenum errGLErr;
|
||||
|
||||
|
||||
GL_GenProgramsARBFunc (1, &progid);
|
||||
GL_BindProgramARBFunc (GL_VERTEX_PROGRAM_ARB, progid);
|
||||
|
||||
|
||||
errGLErr = glGetError ();
|
||||
GL_ProgramStringARBFunc (GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen (source), source);
|
||||
errGLErr = glGetError ();
|
||||
|
||||
|
||||
// Find the error position
|
||||
glGetIntegerv (GL_PROGRAM_ERROR_POSITION_ARB, &errPos);
|
||||
errString = glGetString (GL_PROGRAM_ERROR_STRING_ARB);
|
||||
|
||||
if (errGLErr != GL_NO_ERROR) Con_Printf ("Generic OpenGL Error\n");
|
||||
if (errPos != -1) Con_Printf ("Program error at position: %d\n", errPos);
|
||||
if (errString && errString[0]) Con_Printf ("Program error: %s\n", errString);
|
||||
|
||||
|
||||
if (errGLErr != GL_NO_ERROR) Con_Warning ("GL_CreateProgram: Generic OpenGL Error\n");
|
||||
if (errPos != -1) Con_Warning ("GL_CreateProgram: Program error at position: %d\n", errPos);
|
||||
if (errString && errString[0]) Con_Warning ("GL_CreateProgram: Program error: %s\n", errString);
|
||||
|
||||
if ((errPos != -1) || (errString && errString[0]) || (errGLErr != GL_NO_ERROR))
|
||||
{
|
||||
Con_Printf ("Program:\n%s\n", source);
|
||||
|
@ -362,12 +368,19 @@ GLuint GL_CreateProgram (const GLchar *source)
|
|||
|
||||
gl_arb_programs[gl_num_arb_programs] = progid;
|
||||
gl_num_arb_programs++;
|
||||
|
||||
|
||||
GL_BindProgramARBFunc (GL_VERTEX_PROGRAM_ARB, 0);
|
||||
return progid;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
====================
|
||||
R_DeleteShaders
|
||||
|
||||
Deletes any ARB programs that have been created.
|
||||
====================
|
||||
*/
|
||||
void R_DeleteShaders (void)
|
||||
{
|
||||
GL_DeleteProgramsARBFunc (sizeof(gl_arb_programs)/sizeof(GLuint), gl_arb_programs);
|
||||
|
|
|
@ -1018,7 +1018,7 @@ static void GL_CheckExtensions (void)
|
|||
{
|
||||
Con_Warning ("texture_non_power_of_two not supported\n");
|
||||
}
|
||||
|
||||
|
||||
// GL_ARB_vertex_program
|
||||
//
|
||||
if (COM_CheckParm("-novertexprogram"))
|
||||
|
@ -1026,7 +1026,7 @@ static void GL_CheckExtensions (void)
|
|||
else
|
||||
{
|
||||
qboolean ok = true;
|
||||
|
||||
|
||||
if (!(GL_BindProgramARBFunc = (PFNGLBINDPROGRAMARBPROC) SDL_GL_GetProcAddress ("glBindProgramARB"))) ok = false;
|
||||
if (!(GL_DeleteProgramsARBFunc = (PFNGLDELETEPROGRAMSARBPROC) SDL_GL_GetProcAddress ("glDeleteProgramsARB"))) ok = false;
|
||||
if (!(GL_GenProgramsARBFunc = (PFNGLGENPROGRAMSARBPROC) SDL_GL_GetProcAddress ("glGenProgramsARB"))) ok = false;
|
||||
|
@ -1049,7 +1049,7 @@ static void GL_CheckExtensions (void)
|
|||
if (!(GL_VertexAttribPointerARBFunc = (PFNGLVERTEXATTRIBPOINTERARBPROC) SDL_GL_GetProcAddress ("glVertexAttribPointerARB"))) ok = false;
|
||||
if (!(GL_EnableVertexAttribArrayARBFunc = (PFNGLENABLEVERTEXATTRIBARRAYARBPROC) SDL_GL_GetProcAddress ("glEnableVertexAttribArrayARB"))) ok = false;
|
||||
if (!(GL_DisableVertexAttribArrayARBFunc = (PFNGLDISABLEVERTEXATTRIBARRAYARBPROC) SDL_GL_GetProcAddress ("glDisableVertexAttribArrayARB"))) ok = false;
|
||||
|
||||
|
||||
if (ok)
|
||||
{
|
||||
Con_Printf("FOUND: GL_ARB_vertex_program\n");
|
||||
|
@ -1063,8 +1063,8 @@ static void GL_CheckExtensions (void)
|
|||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
GL_SetupState -- johnfitz
|
||||
===============
|
||||
GL_SetupState -- johnfitz
|
||||
|
||||
does all the stuff from GL_Init that needs to be done every time a new GL render context is created
|
||||
===============
|
||||
|
@ -1121,7 +1121,7 @@ static void GL_Init (void)
|
|||
Cbuf_AddText ("gl_clear 1");
|
||||
}
|
||||
//johnfitz
|
||||
|
||||
|
||||
R_DeleteShaders ();
|
||||
GLAlias_CreateShaders ();
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ typedef struct {
|
|||
} lerpdata_t;
|
||||
//johnfitz
|
||||
|
||||
static GLuint shader;
|
||||
static GLuint r_alias_vertex_program;
|
||||
|
||||
extern GLuint r_meshvbo;
|
||||
extern GLuint r_meshindexesvbo;
|
||||
|
@ -88,9 +88,16 @@ void *GLARB_GetNormalOffset (aliashdr_t *hdr, int pose)
|
|||
|
||||
qboolean GLAlias_SupportsShaders (void)
|
||||
{
|
||||
return gl_arb_vp_able && gl_vbo_able && gl_max_texture_units >= 3;
|
||||
return gl_arb_vp_able && gl_vbo_able && gl_max_texture_units >= 3;
|
||||
}
|
||||
|
||||
/*
|
||||
=============
|
||||
GLAlias_CreateShaders -- ericw
|
||||
|
||||
Creates the alias model vertex shader
|
||||
=============
|
||||
*/
|
||||
void GLAlias_CreateShaders (void)
|
||||
{
|
||||
const GLchar *source =
|
||||
|
@ -99,8 +106,8 @@ void GLAlias_CreateShaders (void)
|
|||
|
||||
if (!GLAlias_SupportsShaders())
|
||||
return;
|
||||
|
||||
shader = GL_CreateProgram(source);
|
||||
|
||||
r_alias_vertex_program = GL_CreateProgram(source);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -114,6 +121,17 @@ void GL_DrawAliasFrame_ARB (aliashdr_t *paliashdr, lerpdata_t lerpdata)
|
|||
{
|
||||
float blend;
|
||||
|
||||
// program local indices - copied from vpalias.h
|
||||
const GLuint blendLoc = 9;
|
||||
const GLuint shadevectorLoc = 10;
|
||||
const GLuint lightColorLoc = 11;
|
||||
|
||||
// vertex attribute indices - copied from vpalias.h
|
||||
const GLint pose1VertexAttrIndex = 0;
|
||||
const GLint pose1NormalAttrIndex = 1;
|
||||
const GLint pose2VertexAttrIndex = 2;
|
||||
const GLint pose2NormalAttrIndex = 3;
|
||||
|
||||
if (lerpdata.pose1 != lerpdata.pose2)
|
||||
{
|
||||
blend = lerpdata.blend;
|
||||
|
@ -122,62 +140,45 @@ void GL_DrawAliasFrame_ARB (aliashdr_t *paliashdr, lerpdata_t lerpdata)
|
|||
{
|
||||
blend = 0;
|
||||
}
|
||||
|
||||
// N.B.: Copied from vpalias.h
|
||||
|
||||
// program local indices
|
||||
const GLuint blendLoc = 9;
|
||||
const GLuint shadevectorLoc = 10;
|
||||
const GLuint lightColorLoc = 11;
|
||||
|
||||
// vertex attribute indices
|
||||
const GLint pose1VertexAttrIndex = 0;
|
||||
const GLint pose1NormalAttrIndex = 1;
|
||||
const GLint pose2VertexAttrIndex = 2;
|
||||
const GLint pose2NormalAttrIndex = 3;
|
||||
|
||||
GL_BindProgramARBFunc (GL_VERTEX_PROGRAM_ARB, shader);
|
||||
GL_BindProgramARBFunc (GL_VERTEX_PROGRAM_ARB, r_alias_vertex_program);
|
||||
glEnable ( GL_VERTEX_PROGRAM_ARB );
|
||||
|
||||
// ericw -- bind it and stuff
|
||||
GL_BindBufferFunc (GL_ARRAY_BUFFER, r_meshvbo);
|
||||
GL_BindBufferFunc (GL_ELEMENT_ARRAY_BUFFER, r_meshindexesvbo);
|
||||
|
||||
|
||||
GL_VertexAttribPointerARBFunc (pose1VertexAttrIndex, 4, GL_UNSIGNED_BYTE, GL_FALSE, sizeof (meshxyz_t), GLARB_GetXYZOffset (paliashdr, lerpdata.pose1));
|
||||
GL_EnableVertexAttribArrayARBFunc (pose1VertexAttrIndex);
|
||||
|
||||
|
||||
GL_VertexAttribPointerARBFunc (pose2VertexAttrIndex, 4, GL_UNSIGNED_BYTE, GL_FALSE, sizeof (meshxyz_t), GLARB_GetXYZOffset (paliashdr, lerpdata.pose2));
|
||||
GL_EnableVertexAttribArrayARBFunc (pose2VertexAttrIndex);
|
||||
|
||||
|
||||
GL_ClientActiveTextureFunc (GL_TEXTURE0_ARB);
|
||||
glTexCoordPointer (2, GL_FLOAT, 0, (void *)(intptr_t)currententity->model->vbostofs);
|
||||
glEnableClientState (GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
|
||||
GL_ClientActiveTextureFunc (GL_TEXTURE1_ARB);
|
||||
glDisableClientState (GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
|
||||
GL_ClientActiveTextureFunc (GL_TEXTURE2_ARB);
|
||||
glDisableClientState (GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
|
||||
// GL_TRUE to normalize the signed bytes to [-1 .. 1]
|
||||
GL_VertexAttribPointerARBFunc (pose1NormalAttrIndex, 3, GL_BYTE, GL_TRUE, sizeof (meshxyz_t), GLARB_GetNormalOffset (paliashdr, lerpdata.pose1));
|
||||
GL_EnableVertexAttribArrayARBFunc (pose1NormalAttrIndex);
|
||||
|
||||
|
||||
GL_VertexAttribPointerARBFunc (pose2NormalAttrIndex, 3, GL_BYTE, GL_TRUE, sizeof (meshxyz_t), GLARB_GetNormalOffset (paliashdr, lerpdata.pose2));
|
||||
GL_EnableVertexAttribArrayARBFunc (pose2NormalAttrIndex);
|
||||
|
||||
// set uniforms
|
||||
|
||||
// set uniforms
|
||||
GL_ProgramLocalParameter4fARBFunc (GL_VERTEX_PROGRAM_ARB, blendLoc, blend, /* unused */ 0, 0, 0);
|
||||
GL_ProgramLocalParameter4fARBFunc (GL_VERTEX_PROGRAM_ARB, shadevectorLoc, shadevector[0], shadevector[1], shadevector[2], /* unused */ 0);
|
||||
GL_ProgramLocalParameter4fARBFunc (GL_VERTEX_PROGRAM_ARB, lightColorLoc, lightcolor[0], lightcolor[1], lightcolor[2], entalpha);
|
||||
|
||||
// draw
|
||||
|
||||
// draw
|
||||
glDrawElements (GL_TRIANGLES, paliashdr->numindexes, GL_UNSIGNED_SHORT, (void *)(intptr_t)currententity->model->vboindexofs);
|
||||
|
||||
// clean up
|
||||
|
||||
// clean up
|
||||
GL_DisableVertexAttribArrayARBFunc (pose1VertexAttrIndex);
|
||||
GL_DisableVertexAttribArrayARBFunc (pose2VertexAttrIndex);
|
||||
|
||||
|
@ -213,8 +214,9 @@ void GL_DrawAliasFrame (aliashdr_t *paliashdr, lerpdata_t lerpdata)
|
|||
float blend, iblend;
|
||||
qboolean lerping;
|
||||
|
||||
// call fast path if possible
|
||||
if (GLAlias_SupportsShaders() && !r_drawflat_cheatsafe && shading)
|
||||
// call fast path if possible. if the shader compliation failed for some reason,
|
||||
// r_alias_vertex_program will be 0.
|
||||
if (GLAlias_SupportsShaders() && (r_alias_vertex_program != 0) && !r_drawflat_cheatsafe && shading)
|
||||
{
|
||||
GL_DrawAliasFrame_ARB (paliashdr, lerpdata);
|
||||
return;
|
||||
|
@ -517,14 +519,16 @@ void R_SetupAliasLighting (entity_t *e)
|
|||
|
||||
quantizedangle = ((int)(e->angles[1] * (SHADEDOT_QUANT / 360.0))) & (SHADEDOT_QUANT - 1);
|
||||
|
||||
//ericw -- shadevector is passed to the shader to compute shadedots inside the
|
||||
//shader, see r_alias_vertexshader.glsl
|
||||
radiansangle = (quantizedangle / 16.0) * 2.0 * 3.14159;
|
||||
shadevector[0] = cos(-radiansangle);
|
||||
shadevector[1] = sin(-radiansangle);
|
||||
shadevector[2] = 1;
|
||||
VectorNormalize(shadevector);
|
||||
//ericw --
|
||||
|
||||
shadedots = r_avertexnormal_dots[quantizedangle];
|
||||
|
||||
VectorScale (lightcolor, 1.0f / 200.0f, lightcolor);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
#version 110
|
||||
|
||||
// Note: we’re not loading this directly but first compiling it to ARB_vertex_program
|
||||
// using compile_vertexshader.sh
|
||||
|
||||
uniform float Blend;
|
||||
uniform vec3 ShadeVector;
|
||||
uniform vec4 LightColor;
|
||||
|
|
Loading…
Reference in a new issue