Exemple #1
0
void InitTexMergeShaders (void)
{
	int	i, b;

if (!gameStates.ogl.bShadersOk)
	gameOpts->ogl.bGlTexMerge = 0;
if (!gameOpts->ogl.bGlTexMerge)
	gameStates.render.textures.bGlsTexMergeOk = 0;
else {
	LogErr ("building texturing shader programs\n");
	for (i = 0; i < 2; i++) {
		if (tmShaderProgs [i])
			DeleteShaderProg (tmShaderProgs + i);
		b = CreateShaderProg (tmShaderProgs + i) &&
			 CreateShaderFunc (tmShaderProgs + i, tmf + i, tmv + i, texMergeFS [i], texMergeVS [i], 1) &&
-			 LinkShaderProg (tmShaderProgs + i);
		if (i == 2)
			gameStates.render.textures.bHaveMaskShader = b;
		else
			gameStates.render.textures.bGlsTexMergeOk = b;
		if (!gameStates.render.textures.bGlsTexMergeOk) {
			while (i)
				DeleteShaderProg (tmShaderProgs + --i);
			break;
			}
		}
	if (!gameStates.render.textures.bGlsTexMergeOk)
		gameOpts->ogl.bGlTexMerge = 0;
	}
if (!(gameOpts->ogl.bGlTexMerge && gameStates.render.textures.bGlsTexMergeOk))
	gameStates.ogl.bHaveTexCompression = 0;
}
Exemple #2
0
void InitShaders (void)
{
	GLint	nTMUs;

if (!(gameOpts->render.bUseShaders && gameStates.ogl.bShadersOk))
	return;
PrintLog ("initializing shader programs\n");
glGetIntegerv (GL_MAX_TEXTURE_UNITS, &nTMUs);
gameStates.ogl.bShadersOk = (nTMUs >= 4);
if (!gameStates.ogl.bShadersOk) {
	PrintLog ("GPU has too few texture units (%d)\n", nTMUs);
	gameStates.ogl.bLowMemory = 0;
	gameStates.ogl.bHaveTexCompression = 0;
	return;
	}
gameStates.render.bLightmapsOk = (nTMUs >= 4);
PrintLog ("   initializing texture merging shader programs\n");
InitTexMergeShaders ();
gameData.render.ogl.nHeadlights = 0;
PrintLog ("   initializing lighting shader programs\n");
InitHeadlightShaders (1);
PrintLog ("   initializing vertex lighting shader programs\n");
gpgpuLighting.InitShader ();
PrintLog ("   initializing glare shader programs\n");
InitGlareShader ();
PrintLog ("   initializing gray scale shader programs\n");
InitGrayScaleShader ();
ResetPerPixelLightingShaders ();
InitPerPixelLightingShaders ();
ResetLightmapShaders ();
InitLightmapShaders ();
LinkShaderProg (NULL);
}
Exemple #3
0
void InitGlareShader (void)
{
	int	bOk;

ogl.m_states.bDepthBlending = 0;
#if SHADER_SOFT_CORONAS
PrintLog ("building corona blending shader program\n");
DeleteShaderProg (NULL);
if (ogl.m_states.bRender2TextureOk && ogl.m_states.bShadersOk) {
	ogl.m_states.bDepthBlending = 1;
	for (int i = 0; i < 2; i++) {
		if (hGlareShader [i])
			DeleteShaderProg (&hGlareShader [i]);
		bOk = CreateShaderProg (&hGlareShader [i]) &&
				CreateShaderFunc (&hGlareShader [i], &hGlareFS [i], &hGlareVS [i], glareFS [i], glareVS, 1) &&
				LinkShaderProg (&hGlareShader [i]);
		if (!bOk) {
			ogl.ClearError (0);
			ogl.m_states.bDepthBlending = 0;
			while (i)
				DeleteShaderProg (&hGlareShader [--i]);
			return;
			}
		}
	}
#endif
}
Exemple #4
0
void RenderShadowTexture (void)
{
if (!(shadowProg ||
	   (CreateShaderProg (&shadowProg) &&
	    CreateShaderFunc (&shadowProg, &shadowFS, &shadowVS, pszShadowFS, pszShadowVS, 1) &&
	    LinkShaderProg (&shadowProg))))
	return;
glMatrixMode (GL_MODELVIEW);
glPushMatrix ();
glLoadIdentity ();
glMatrixMode (GL_PROJECTION);
glPushMatrix ();
glLoadIdentity ();
glOrtho (0, 1, 1, 0, 0, 1);
glDisable (GL_DEPTH_TEST);
glDepthMask (0);
#if 1
glDisable (GL_BLEND);
#else
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
#endif
glEnable (GL_TEXTURE_2D);
ogl.SelectTMU (GL_TEXTURE0);
shadowBuf.SetTranspType (0);
if (shadowBuf.Bind (0))
	return;
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
#if 0
glUseProgramObject (shadowProg);
glUniform1i (glGetUniformLocation (shadowProg, "shadowTex"), 0);
#endif
glBegin (GL_QUADS);
glTexCoord2d (0,0);
glVertex2d (0,0);
glTexCoord2d (1,0);
glVertex2d (0.5,0);
glTexCoord2d (1,-1);
glVertex2d (0.5,0.5);
glTexCoord2d (0,-1);
glVertex2d (0,0.5);
glEnd ();
if (ogl.m_states.bShadersOk)
	glUseProgramObject (0);
glEnable (GL_DEPTH_TEST);
glDepthMask (1);
glPopMatrix ();
glMatrixMode (GL_MODELVIEW);
glPopMatrix ();
}
Exemple #5
0
void InitHeadlightShaders (int nLights)
{
	int	i, j, bOk;
	char	*pszFS;

if (nLights < 0) {
	nLights = gameData.render.ogl.nHeadLights;
	gameData.render.ogl.nHeadLights = 0;
	}
if (nLights == gameData.render.ogl.nHeadLights)
	return;
gameStates.render.bHaveDynLights = 0;
PrintLog ("building lighting shader programs\n");
if ((gameStates.ogl.bHeadLight = (gameStates.ogl.bShadersOk && gameOpts->render.nPath))) {
	gameStates.render.bHaveDynLights = 1;
	for (i = 0; i < 2; i++) {
		for (j = 0; j < 4; j++) {
			if (headLightShaderProgs [i][j])
				DeleteShaderProg (&headLightShaderProgs [i][j]);
#if 1//ndef _DEBUG
			if (nLights == 1)
				pszFS = headLightFS [i][j];
			else
#endif
				pszFS = BuildLightingShader (headLightFS [i][j + 4], nLights);
			bOk = (pszFS != NULL) &&
					CreateShaderProg (&headLightShaderProgs [i][j]) &&
					CreateShaderFunc (&headLightShaderProgs [i][j], &lfs [i][j], &lvs [i][j], pszFS, headLightVS [i][j], 1) &&
					LinkShaderProg (&headLightShaderProgs [i][j]);
			if (pszFS && (nLights > 1))
				D2_FREE (pszFS);
			if (!bOk) {
				DeleteHeadLightShader ();
				nLights = 0;
				break;
				}
			}
		}
	}
gameData.render.ogl.nHeadLights = nLights;
}
Exemple #6
0
void InitLightingShaders (int nLights)
{
	int	i, bOk;
	char	*pszFS;

if (nLights < 0) {
	nLights = gameData.render.ogl.nHeadLights;
	gameData.render.ogl.nHeadLights = 0;
	}
if (nLights == gameData.render.ogl.nHeadLights)
	return;
gameStates.render.bHaveDynLights = 0;
LogErr ("building lighting shader programs\n");
if ((gameStates.ogl.bHeadLight = (gameStates.ogl.bShadersOk && gameOpts->render.nPath))) {
	gameStates.render.bHaveDynLights = 1;
	for (i = 0; i < 4; i++) {
		if (lightingShaderProgs [i])
			DeleteShaderProg (lightingShaderProgs + i);
#ifndef _DEBUG
		if (nLights == 1)
			pszFS = lightingFS [i];
		else
#endif
			pszFS = BuildLightingShader (lightingFS [i + 4], nLights);
		bOk = (pszFS != NULL) &&
				CreateShaderProg (lightingShaderProgs + i) &&
				CreateShaderFunc (lightingShaderProgs + i, lfs + i, lvs + i, pszFS, lightingVS [i % 4], 1) &&
				LinkShaderProg (lightingShaderProgs + i);
		if (pszFS && (nLights > 1))
			D2_FREE (pszFS);
		if (!bOk) {
			gameStates.ogl.bHeadLight = 0;
			while (i)
				DeleteShaderProg (lightingShaderProgs + --i);
			nLights = 0;
			break;
			}
		}
	}
gameData.render.ogl.nHeadLights = nLights;
}
Exemple #7
0
void InitBlurShader (void)
{
	int	bOk;

PrintLog ("building blur shader program\n");
DeleteShaderProg (NULL);
if (gameStates.ogl.bRender2TextureOk && gameStates.ogl.bShadersOk && RENDERPATH) {
	gameStates.ogl.bHaveBlur = 1;
	if (hBlurShader)
		DeleteShaderProg (&hBlurShader);
	bOk = CreateShaderProg (&hBlurShader) &&
			CreateShaderFunc (&hBlurShader, &hBlurFS, &hBlurVS, blurFS, blurVS, 1) &&
			LinkShaderProg (&hBlurShader);
	if (!bOk) {
		gameStates.ogl.bHaveBlur = 0;
		DeleteShaderProg (&hBlurShader);
		return;
		}
	ogl.ClearError (0);
	}
}
Exemple #8
0
void InitGlareShader (void)
{
	int	bOk;

gameStates.ogl.bDepthBlending = 0;
#if SHADER_SOFT_CORONAS
LogErr ("building corona blending shader program\n");
DeleteShaderProg (NULL);
if (gameStates.ogl.bRender2TextureOk && gameStates.ogl.bShadersOk && gameOpts->render.nPath) {
	gameStates.ogl.bDepthBlending = 1;
	if (hGlareShader)
		DeleteShaderProg (&hGlareShader);
	bOk = CreateShaderProg (&hGlareShader) &&
			CreateShaderFunc (&hGlareShader, &hGlareFS, &hGlareVS, glareFS, glareVS, 1) &&
			LinkShaderProg (&hGlareShader);
	if (!bOk) {
		gameStates.ogl.bDepthBlending = 0;
		DeleteShaderProg (&hGlareShader);
		}
	}
#endif
}
Exemple #9
0
int CreateSphereShader (void)
{
    int	bOk;

    if (!(gameStates.ogl.bShadersOk && gameStates.ogl.bPerPixelLightingOk)) {
        gameStates.render.bPerPixelLighting = 0;
        return 0;
    }
    if (sphereShaderProg)
        return 1;
    PrintLog ("building sphere shader program\n");
    if (!sphereShaderProg) {
        bOk = CreateShaderProg (&sphereShaderProg) &&
              CreateShaderFunc (&sphereShaderProg, &sphereFS, &sphereVS, pszSphereFS, pszSphereVS, 1) &&
              LinkShaderProg (&sphereShaderProg);
        if (!bOk) {
            gameStates.ogl.bPerPixelLightingOk = 0;
            gameStates.render.bPerPixelLighting = 0;
            return -1;
        }
    }
    return 1;
}
Exemple #10
0
void InitLightmapShaders (void)
{
	int	i;

if (!gameStates.ogl.bShadersOk)
	gameStates.render.color.bLightMapsOk = 0;
if (gameStates.render.color.bLightMapsOk) {
	LogErr ("building lightmap shader programs\n");
	for (i = 0; i < 2; i++) {
		if (lmShaderProgs [i])
			DeleteShaderProg (lmShaderProgs + i);
		gameStates.render.color.bLightMapsOk = 
			CreateShaderProg (lmShaderProgs + i) &&
			CreateShaderFunc (lmShaderProgs + i, lmFS + i, lmVS + i, lightMapFS [i], lightMapVS [i], 1) &&
			LinkShaderProg (lmShaderProgs + i);
		if (!gameStates.render.color.bLightMapsOk) {
			while (i)
				DeleteShaderProg (lmShaderProgs + --i);
			break;
			}
		}
	}
}
Exemple #11
0
void InitGlareShader (void)
{
	int	bOk;

ogl.m_states.bDepthBlending = 0;
#if SHADER_SOFT_CORONAS
PrintLog ("building corona blending shader program\n");
DeleteShaderProg (NULL);
if (ogl.m_states.bRender2TextureOk && ogl.m_states.bShadersOk) {
	ogl.m_states.bDepthBlending = 1;
	if (hGlareShader)
		DeleteShaderProg (&hGlareShader);
	bOk = CreateShaderProg (&hGlareShader) &&
			CreateShaderFunc (&hGlareShader, &hGlareFS, &hGlareVS, glareFS, glareVS, 1) &&
			LinkShaderProg (&hGlareShader);
	if (!bOk) {
		ogl.m_states.bDepthBlending = 0;
		DeleteShaderProg (&hGlareShader);
		return;
		}
	ogl.ClearError (0);
	}
#endif
}