Comments & formatting

This commit is contained in:
Eric Wasylishen 2014-10-23 14:16:22 -06:00
parent 0234ffe6ff
commit 376a437df8
6 changed files with 86 additions and 58 deletions

View file

@ -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

View file

@ -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
================
*/
@ -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
================
*/

View file

@ -325,7 +325,13 @@ 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;
@ -344,9 +350,9 @@ GLuint GL_CreateProgram (const GLchar *source)
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))
{
@ -368,6 +374,13 @@ GLuint GL_CreateProgram (const GLchar *source)
}
}
/*
====================
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);

View file

@ -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
===============

View file

@ -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 =
@ -100,7 +107,7 @@ 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;
@ -123,23 +141,9 @@ 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);
@ -166,18 +170,15 @@ void GL_DrawAliasFrame_ARB (aliashdr_t *paliashdr, lerpdata_t lerpdata)
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);
}

View file

@ -1,5 +1,8 @@
#version 110
// Note: were 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;