void GLSL_SetUniformVec4(shaderProgram_t *program, int uniformNum, const vec4_t v) { GLint *uniforms = program->uniforms; vec_t *compare = (float *)(program->uniformBuffer + program->uniformBufferOffsets[uniformNum]); if (uniforms[uniformNum] == -1) return; if (uniformsInfo[uniformNum].type != GLSL_VEC4) { ri.Printf( PRINT_WARNING, "GLSL_SetUniformVec4: wrong type for uniform %i in program %s\n", uniformNum, program->name); return; } if (VectorCompare4(v, compare)) { return; } VectorCopy4(v, compare); qglUniform4fARB(uniforms[uniformNum], v[0], v[1], v[2], v[3]); }
GLvoid APIENTRY GLDSA_ProgramUniform4f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) { GL_UseProgramObject(program); qglUniform4fARB(location, v0, v1, v2, v3); }
/* ================== RB_GLSL_DrawInteraction ================== */ static void RB_GLSL_DrawInteraction( const drawInteraction_t *din ) { // load all the shader parameters if ( din->ambientLight ) { qglUniform4fvARB( ambientInteractionShader.localLightOrigin, 1, din->localLightOrigin.ToFloatPtr() ); qglUniform4fvARB( ambientInteractionShader.lightProjectionS, 1, din->lightProjection[0].ToFloatPtr() ); qglUniform4fvARB( ambientInteractionShader.lightProjectionT, 1, din->lightProjection[1].ToFloatPtr() ); qglUniform4fvARB( ambientInteractionShader.lightProjectionQ, 1, din->lightProjection[2].ToFloatPtr() ); qglUniform4fvARB( ambientInteractionShader.lightFalloff, 1, din->lightProjection[3].ToFloatPtr() ); qglUniform4fvARB( ambientInteractionShader.bumpMatrixS, 1, din->bumpMatrix[0].ToFloatPtr() ); qglUniform4fvARB( ambientInteractionShader.bumpMatrixT, 1, din->bumpMatrix[1].ToFloatPtr() ); qglUniform4fvARB( ambientInteractionShader.diffuseMatrixS, 1, din->diffuseMatrix[0].ToFloatPtr() ); qglUniform4fvARB( ambientInteractionShader.diffuseMatrixT, 1, din->diffuseMatrix[1].ToFloatPtr() ); static const float zero[4] = { 0, 0, 0, 0 }; static const float one[4] = { 1, 1, 1, 1 }; static const float negOne[4] = { -1, -1, -1, -1 }; switch ( din->vertexColor ) { case SVC_IGNORE: qglUniform4fARB( ambientInteractionShader.colorModulate, zero[0], zero[1], zero[2], zero[3] ); qglUniform4fARB( ambientInteractionShader.colorAdd, one[0], one[1], one[2], one[3] ); break; case SVC_MODULATE: qglUniform4fARB( ambientInteractionShader.colorModulate, one[0], one[1], one[2], one[3] ); qglUniform4fARB( ambientInteractionShader.colorAdd, zero[0], zero[1], zero[2], zero[3] ); break; case SVC_INVERSE_MODULATE: qglUniform4fARB( ambientInteractionShader.colorModulate, negOne[0], negOne[1], negOne[2], negOne[3] ); qglUniform4fARB( ambientInteractionShader.colorAdd, one[0], one[1], one[2], one[3] ); break; } // set the constant color qglUniform4fvARB( ambientInteractionShader.diffuseColor, 1, din->diffuseColor.ToFloatPtr() ); } else { qglUniform4fvARB( interactionShader.localLightOrigin, 1, din->localLightOrigin.ToFloatPtr() ); qglUniform4fvARB( interactionShader.localViewOrigin, 1, din->localViewOrigin.ToFloatPtr() ); qglUniform4fvARB( interactionShader.lightProjectionS, 1, din->lightProjection[0].ToFloatPtr() ); qglUniform4fvARB( interactionShader.lightProjectionT, 1, din->lightProjection[1].ToFloatPtr() ); qglUniform4fvARB( interactionShader.lightProjectionQ, 1, din->lightProjection[2].ToFloatPtr() ); qglUniform4fvARB( interactionShader.lightFalloff, 1, din->lightProjection[3].ToFloatPtr() ); qglUniform4fvARB( interactionShader.bumpMatrixS, 1, din->bumpMatrix[0].ToFloatPtr() ); qglUniform4fvARB( interactionShader.bumpMatrixT, 1, din->bumpMatrix[1].ToFloatPtr() ); qglUniform4fvARB( interactionShader.diffuseMatrixS, 1, din->diffuseMatrix[0].ToFloatPtr() ); qglUniform4fvARB( interactionShader.diffuseMatrixT, 1, din->diffuseMatrix[1].ToFloatPtr() ); qglUniform4fvARB( interactionShader.specularMatrixS, 1, din->specularMatrix[0].ToFloatPtr() ); qglUniform4fvARB( interactionShader.specularMatrixT, 1, din->specularMatrix[1].ToFloatPtr() ); static const float zero[4] = { 0, 0, 0, 0 }; static const float one[4] = { 1, 1, 1, 1 }; static const float negOne[4] = { -1, -1, -1, -1 }; switch ( din->vertexColor ) { case SVC_IGNORE: qglUniform4fARB( interactionShader.colorModulate, zero[0], zero[1], zero[2], zero[3] ); qglUniform4fARB( interactionShader.colorAdd, one[0], one[1], one[2], one[3] ); break; case SVC_MODULATE: qglUniform4fARB( interactionShader.colorModulate, one[0], one[1], one[2], one[3] ); qglUniform4fARB( interactionShader.colorAdd, zero[0], zero[1], zero[2], zero[3] ); break; case SVC_INVERSE_MODULATE: qglUniform4fARB( interactionShader.colorModulate, negOne[0], negOne[1], negOne[2], negOne[3] ); qglUniform4fARB( interactionShader.colorAdd, one[0], one[1], one[2], one[3] ); break; } // set the constant colors qglUniform4fvARB( interactionShader.diffuseColor, 1, din->diffuseColor.ToFloatPtr() ); qglUniform4fvARB( interactionShader.specularColor, 1, din->specularColor.ToFloatPtr() ); } // set the textures // texture 0 will be the per-surface bump map GL_SelectTextureNoClient( 0 ); din->bumpImage->Bind(); // texture 1 will be the light falloff texture GL_SelectTextureNoClient( 1 ); din->lightFalloffImage->Bind(); // texture 2 will be the light projection texture GL_SelectTextureNoClient( 2 ); din->lightImage->Bind(); // texture 3 is the per-surface diffuse map GL_SelectTextureNoClient( 3 ); din->diffuseImage->Bind(); if ( !din->ambientLight ) { // texture 4 is the per-surface specular map GL_SelectTextureNoClient( 4 ); din->specularImage->Bind(); } // draw it RB_DrawElementsWithCounters( din->surf->geo ); }