Esempio n. 1
0
/*
=================
R_Bloom_RestoreScreen_Postprocessed
Restore the temporary framebuffer section we used with the backup texture
=================
*/
static void R_Bloom_RestoreScreen_Postprocessed( void ) {
	glslProgram_t	*program;
	if (vertexShaders) R_GLSL_UseProgram(tr.postprocessingProgram);
	// Feed GLSL postprocess program
	program=tr.programs[tr.postprocessingProgram];
	if (program->u_ScreenSizeX > -1) R_GLSL_SetUniform_u_ScreenSizeX(program, glConfig.vidWidth);

	if (program->u_ScreenSizeY > -1) R_GLSL_SetUniform_u_ScreenSizeY(program, glConfig.vidHeight);

	if (program->u_ScreenToNextPixelX > -1) R_GLSL_SetUniform_u_ScreenToNextPixelX(program, 0.00125);

	if (program->u_ScreenToNextPixelY > -1) R_GLSL_SetUniform_u_ScreenToNextPixelY(program, (float)1.0/(float)glConfig.vidHeight);

	if (program->u_zFar > -1) R_GLSL_SetUniform_u_zFar(program, tr.viewParms.zFar);	
	GL_SelectTexture(0);
	GL_State( GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_ONE | GLS_DSTBLEND_ZERO );
	GL_Bind( postproc.screen.texture );
	GL_SelectTexture(7);
	GL_State( GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_ONE | GLS_DSTBLEND_ZERO );
	GL_Bind( postproc.depth.texture );	
	qglColor4f( 1, 1, 1, 1 );
	R_Bloom_Quad( glConfig.vidWidth, glConfig.vidHeight, 0, 0,
			postproc.screen.readW,postproc.screen.readH );
	if (vertexShaders) R_GLSL_UseProgram(0);
	GL_SelectTexture(0);
}
Esempio n. 2
0
/*
 * RB_GLSL_IterateStagesGeneric
 * Iterate over each stage of a shader
 */
static void RB_GLSL_IterateStagesGeneric(shaderCommands_t *input) {
	int	stage;

	for(stage = 0; stage < MAX_SHADER_STAGES; stage++) {
		shaderStage_t	*pStage = tess.xstages[stage];
		glslProgram_t	*program;

		if (!pStage || pStage->program == tr.skipProgram)
			break;

		/* set state */
		GL_State(pStage->stateBits);

		/*
		 * this is an ugly hack to work around a GeForce driver
		 * bug with multitexture and clip planes
		 */
		if (backEnd.viewParms.isPortal)
			qglPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

		if (pStage->program)
			/* use specified program */
			R_GLSL_UseProgram(pStage->program);
		else
			/* use default program */
			R_GLSL_UseProgram(tr.defaultProgram);

		program = tr.programs[glState.currentProgram];

		/* alphaGen */
		if (program->u_AlphaGen > -1)
			R_GLSL_SetUniform_AlphaGen(program, pStage->alphaGen);

		/* ambient light */
		if (program->u_AmbientLight > -1)
			R_GLSL_SetUniform_AmbientLight(program, backEnd.currentEntity->ambientLight);

		/* dynamic light */
		if (program->u_DynamicLight > -1)
			R_GLSL_SetUniform_DynamicLight(program, backEnd.currentEntity->dynamicLight);

		/* light distance */
		if (program->u_LightDistance > -1)
			R_GLSL_SetUniform_LightDistance(program, backEnd.currentEntity->lightDistance);

		/* rgbGen */
		if (program->u_ColorGen > -1)
			R_GLSL_SetUniform_ColorGen(program, pStage->rgbGen);

		/* constant color */
		if (program->u_ConstantColor > -1)
			R_GLSL_SetUniform_ConstantColor(program, pStage->constantColor);

		/* directed light */
		if (program->u_DirectedLight > -1)
			R_GLSL_SetUniform_DirectedLight(program, backEnd.currentEntity->directedLight);

		/* entity color */
		if (program->u_EntityColor > -1)
			R_GLSL_SetUniform_EntityColor(program, backEnd.currentEntity->e.shaderRGBA);

		/* fog color */
		if (program->u_FogColor > -1 && tess.fogNum)
			R_GLSL_SetUniform_FogColor(program, (tr.world->fogs + tess.fogNum)->colorInt);

		/* greyscale */
		if (program->u_Greyscale > -1)
			R_GLSL_SetUniform_Greyscale(program, r_greyscale->integer);

		/* identity light */
		if (program->u_IdentityLight > -1)
			R_GLSL_SetUniform_IdentityLight(program, tr.identityLight);

		/* light direction */
		if (program->u_LightDirection > -1)
			R_GLSL_SetUniform_LightDirection(program, backEnd.currentEntity->lightDir);

		/* model view matrix */
		if (program->u_ModelViewMatrix > -1)
			R_GLSL_SetUniform_ModelViewMatrix(program, glState.currentModelViewMatrix);

		/* model view projection matrix */
		if (program->u_ModelViewProjectionMatrix > -1)
			R_GLSL_SetUniform_ModelViewProjectionMatrix(program, glState.currentModelViewProjectionMatrix);

		/* projection matrix */
		if (program->u_ProjectionMatrix > -1)
			R_GLSL_SetUniform_ProjectionMatrix(program, glState.currentProjectionMatrix);

		/* texture coordinates 0 */
		if (program->u_TCGen0 > -1)
			R_GLSL_SetUniform_TCGen0(program, pStage->bundle[0].tcGen);

		/* texture coordinates 1 */
		if (program->u_TCGen1 > -1)
			R_GLSL_SetUniform_TCGen1(program, pStage->bundle[1].tcGen);

		/* tex env */
		if (program->u_TexEnv > -1) {
			if (r_lightmap->integer)
				R_GLSL_SetUniform_TexEnv(program, GL_REPLACE);
			else
				R_GLSL_SetUniform_TexEnv(program, input->shader->multitextureEnv);
		}

		/* texture unit 0 */
		if (program->u_Texture0 > -1 && pStage->bundle[0].image[0]) {
			GL_SelectTexture(0);

			if (pStage->bundle[0].vertexLightmap && ((r_vertexLight->integer && !r_uiFullScreen->integer) || glConfig.hardwareType == GLHW_PERMEDIA2) && r_lightmap->integer)
				GL_Bind(tr.whiteImage);
			else
				R_BindAnimatedImage(&pStage->bundle[0]);
		}

		/* texture unit 1 */
		if (program->u_Texture1 > -1 && pStage->bundle[1].image[0]) {
			GL_SelectTexture(1);
			qglEnable(GL_TEXTURE_2D);
			R_BindAnimatedImage(&pStage->bundle[1]);
		}

		/* texture unit 2 */
		if (program->u_Texture2 > -1 && pStage->bundle[2].image[0]) {
			GL_SelectTexture(2);
			qglEnable(GL_TEXTURE_2D);
			R_BindAnimatedImage(&pStage->bundle[2]);
		}

		/* texture unit 3 */
		if (program->u_Texture3 > -1 && pStage->bundle[3].image[0]) {
			GL_SelectTexture(3);
			qglEnable(GL_TEXTURE_2D);
			R_BindAnimatedImage(&pStage->bundle[3]);
		}

		/* texture unit 4 */
		if (program->u_Texture4 > -1 && pStage->bundle[4].image[0]) {
			GL_SelectTexture(4);
			qglEnable(GL_TEXTURE_2D);
			R_BindAnimatedImage(&pStage->bundle[4]);
		}

		/* texture unit 5 */
		if (program->u_Texture5 > -1 && pStage->bundle[5].image[0]) {
			GL_SelectTexture(5);
			qglEnable(GL_TEXTURE_2D);
			R_BindAnimatedImage(&pStage->bundle[5]);
		}

		/* texture unit 6 */
		if (program->u_Texture6 > -1 && pStage->bundle[6].image[0]) {
			GL_SelectTexture(6);
			qglEnable(GL_TEXTURE_2D);
			R_BindAnimatedImage(&pStage->bundle[6]);
		}

		/* texture unit 7 */
		if (program->u_Texture7 > -1 && pStage->bundle[7].image[0]) {
			GL_SelectTexture(7);
			qglEnable(GL_TEXTURE_2D);
			R_BindAnimatedImage(&pStage->bundle[7]);
		}

		/* time */
		if (program->u_Time > -1)
			R_GLSL_SetUniform_Time(program, input->shaderTime);

		/* view origin */
		if (program->u_ViewOrigin > -1)
			R_GLSL_SetUniform_ViewOrigin(program, backEnd.or.viewOrigin);

		/* draw */
		R_DrawElements(input->numIndexes, input->indexes);

		/* disable texture unit 7 */
		if (program->u_Texture7 > -1)
			qglDisable(GL_TEXTURE_2D);

		/* disable texture unit 6 */
		if (program->u_Texture6 > -1) {
			GL_SelectTexture(6);
			qglDisable(GL_TEXTURE_2D);
		}

		/* disable texture unit 5 */
		if (program->u_Texture5 > -1) {
			GL_SelectTexture(5);
			qglDisable(GL_TEXTURE_2D);
		}

		/* disable texture unit 4 */
		if (program->u_Texture4 > -1) {
			GL_SelectTexture(4);
			qglDisable(GL_TEXTURE_2D);
		}

		/* disable texture unit 3 */
		if (program->u_Texture3 > -1) {
			GL_SelectTexture(3);
			qglDisable(GL_TEXTURE_2D);
		}

		/* disable texture unit 2 */
		if (program->u_Texture2 > -1) {
			GL_SelectTexture(2);
			qglDisable(GL_TEXTURE_2D);
		}

		/* disable texture unit 1 */
		if (program->u_Texture1 > -1) {
			GL_SelectTexture(1);
			qglDisable(GL_TEXTURE_2D);
			qglDisableClientState(GL_TEXTURE_COORD_ARRAY);
		}

		/* switch to texture unit 0 */
		GL_SelectTexture(0);

		/* allow skipping out to show just lightmaps during development */
		if (r_lightmap->integer && (pStage->bundle[0].isLightmap || pStage->bundle[1].isLightmap || pStage->bundle[0].vertexLightmap))
			break;
	}

	/* switch to standard rendering pipeline */
	R_GLSL_UseProgram(0);
}