Ejemplo n.º 1
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 ();
}
Ejemplo n.º 2
0
int G3SetupShader (CSegFace *faceP, int bDepthOnly, int bColorKey, int bMultiTexture, int bTextured, int bColored, tRgbaColorf *colorP)
{
	int	nType, nShader = gameStates.render.history.nShader;

if (!gameStates.ogl.bShadersOk || (gameStates.render.nType == 4))
	return -1;
#if DBG
if (faceP && (faceP->nSegment == nDbgSeg) && ((nDbgSide < 0) || (faceP->nSide == nDbgSide)))
	nDbgSeg = nDbgSeg;
#endif
nType = bColorKey ? 3 : bMultiTexture ? 2 : bTextured;
if (!bColored && gameOpts->render.automap.bGrayOut) 
	nShader = G3SetupGrayScaleShader (nType, colorP);
else if ((gameStates.render.nType != 4) && faceP && (gameStates.render.bPerPixelLighting == 2))
	nShader = G3SetupPerPixelShader (faceP, bDepthOnly, nType, false);
else if (gameStates.render.bHeadlights && !bDepthOnly)
	nShader = lightManager.Headlights ().SetupShader (nType, lightmapManager.HaveLightmaps (), colorP);
else if (bColorKey || bMultiTexture) 
	nShader = G3SetupTexMergeShader (bColorKey, bColored, nType);
else if (gameStates.render.history.nShader >= 0) {
	gameData.render.nShaderChanges++;
	glUseProgramObject (0);
	nShader = -1;
	}
OglClearError (0);
gameStates.render.history.nType = nType;
return gameStates.render.history.nShader = nShader;
}
Ejemplo n.º 3
0
void LoadGlareShader (float dMax, int bAdditive)
{
	static float dMaxPrev = -1;

ogl.ClearError (0);
ogl.m_states.bUseDepthBlending = 0;
if (ogl.m_states.bDepthBlending) {
	ogl.SetReadBuffer (GL_BACK, 1);
	if (CopyDepthTexture ()) {
		ogl.m_states.bUseDepthBlending = 1;
		if (dMax < 1)
			dMax = 1;
		if (gameStates.render.history.nShader != 998 + bAdditive) {
			glUseProgramObject (hGlareShader [bAdditive]);
			gameStates.render.history.nShader = 998 + bAdditive;
			glUniform1i (glGetUniformLocation (hGlareShader [bAdditive], "glareTex"), 0);
			glUniform1i (glGetUniformLocation (hGlareShader [bAdditive], "depthTex"), 1);
			glUniform2fv (glGetUniformLocation (hGlareShader [bAdditive], "screenScale"), 1, reinterpret_cast<GLfloat*> (&ogl.m_data.screenScale));
			glUniform1f (glGetUniformLocation (hGlareShader [bAdditive], "dMax"), (GLfloat) dMax);
			glUniform1i (glGetUniformLocation (hGlareShader [bAdditive], "bAdditive"), (GLint) bAdditive);
			gameData.render.nShaderChanges++;
			}
		else {
			if (dMaxPrev != dMax)
				glUniform1f (glGetUniformLocation (hGlareShader [bAdditive], "dMax"), (GLfloat) dMax);
			}
		dMaxPrev = dMax;
		glDisable (GL_DEPTH_TEST);
		}
	ogl.SelectTMU (GL_TEXTURE0);
	}
}
Ejemplo n.º 4
0
void
cogl_program_use (CoglHandle handle)
{
  CoglProgram *program;
  GLhandleARB gl_handle;
  _COGL_GET_CONTEXT (ctx, NO_RETVAL);

  if (handle != COGL_INVALID_HANDLE && !cogl_is_program (handle))
    return;

  /* The Cogl journal doesn't currently cope with the use of
   * shaders so we have to flush all priitives whenever the
   * current shader changes... */
  _cogl_journal_flush ();

  if (handle == COGL_INVALID_HANDLE)
    gl_handle = 0;
  else
    {
      program = _cogl_program_pointer_from_handle (handle);
      gl_handle = program->gl_handle;
    }

  glUseProgramObject (gl_handle);
}
Ejemplo n.º 5
0
void UnloadSphereShader (void)
{
    if (gameStates.render.history.nShader == 100) {
        gameStates.render.history.nShader = -1;
        glUseProgramObject (0);
    }
}
Ejemplo n.º 6
0
Archivo: glare.c Proyecto: paud/d2x-xl
void UnloadGlareShader (void)
{
if (gameStates.ogl.bDepthBlending) {
	glUseProgramObject (0);
	//DestroyGlareDepthTexture ();
	glActiveTexture (GL_TEXTURE1);
	glBindTexture (GL_TEXTURE_2D, 0);
	glActiveTexture (GL_TEXTURE2);
	glBindTexture (GL_TEXTURE_2D, 0);
	glActiveTexture (GL_TEXTURE0);
	glEnable (GL_DEPTH_TEST);
	}
}
Ejemplo n.º 7
0
int G3SetupTexMergeShader (int bColorKey, int bColored)
{
int nShader = bColorKey ? 2 : 0;
if (nShader != gameStates.render.history.nShader) {
	gameData.render.nStateChanges++;
	glUseProgramObject (activeShaderProg = tmShaderProgs [nShader + bColored * 3]);
	}
glUniform1i (glGetUniformLocation (activeShaderProg, "baseTex"), 0);
glUniform1i (glGetUniformLocation (activeShaderProg, "decalTex"), 1);
glUniform1i (glGetUniformLocation (activeShaderProg, "maskTex"), 2);
glUniform1f (glGetUniformLocation (activeShaderProg, "grAlpha"), 1.0f);
return gameStates.render.history.nShader = nShader;
}
Ejemplo n.º 8
0
Archivo: glare.c Proyecto: paud/d2x-xl
void LoadGlareShader (void)
{
if (gameStates.ogl.bDepthBlending) {
	OglReadBuffer (GL_BACK, 1);
	if (CopyDepthTexture ()) {
		glUseProgramObject (hGlareShader);
		glUniform1i (glGetUniformLocation (hGlareShader, "glareTex"), 0);
		glUniform1i (glGetUniformLocation (hGlareShader, "depthTex"), 1);
		glUniform3fv (glGetUniformLocation (hGlareShader, "depthScale"), 1, (GLfloat *) &gameData.render.ogl.depthScale);
		glUniform2fv (glGetUniformLocation (hGlareShader, "screenScale"), 1, (GLfloat *) &gameData.render.ogl.screenScale);
		glDisable (GL_DEPTH_TEST);
		}
	glActiveTexture (GL_TEXTURE0);
	}
}
Ejemplo n.º 9
0
void UnloadGlareShader (void)
{
if (ogl.m_states.bDepthBlending) {
	glUseProgramObject (0);
	gameStates.render.history.nShader = -1;
	//DestroyGlareDepthTexture ();
	glEnable (GL_TEXTURE_2D);
	ogl.SelectTMU (GL_TEXTURE1);
	glBindTexture (GL_TEXTURE_2D, 0);
	ogl.SelectTMU (GL_TEXTURE2);
	glBindTexture (GL_TEXTURE_2D, 0);
	ogl.SelectTMU (GL_TEXTURE0);
	glEnable (GL_DEPTH_TEST);
	}
}
Ejemplo n.º 10
0
void LoadGlareShader (float dMax)
{
	static float dMaxPrev = -1;

ogl.ClearError (0);
ogl.m_states.bUseDepthBlending = 0;
if (ogl.m_states.bDepthBlending) {
	ogl.SetReadBuffer (GL_BACK, 1);
	if (CopyDepthTexture ()) {
		ogl.m_states.bUseDepthBlending = 1;
		if (dMax < 1)
			dMax = 1;
		if (gameStates.render.history.nShader != 999) {
			glUseProgramObject (hGlareShader);
			gameStates.render.history.nShader = 999;
			glUniform1i (glGetUniformLocation (hGlareShader, "glareTex"), 0);
			glUniform1i (glGetUniformLocation (hGlareShader, "depthTex"), 1);
			glUniform2fv (glGetUniformLocation (hGlareShader, "screenScale"), 1, reinterpret_cast<GLfloat*> (&ogl.m_data.screenScale));
#if 0
			if (automap.m_bDisplay)
				glUniform3fv (glGetUniformLocation (h, "depthScale"), 1, reinterpret_cast<GLfloat*> (&ogl.m_data.depthScale));
			else 
#endif
			 {
#if 1
				//glUniform1f (glGetUniformLocation (h, "depthScale"), (GLfloat) (ogl.m_data.depthScale [Z]));
#else
				glUniform1f (glGetUniformLocation (h, "depthScale"), (GLfloat) X2F (gameData.render.zMax) - ogl.m_data.zNear);
#endif
				glUniform1f (glGetUniformLocation (hGlareShader, "dMax"), (GLfloat) dMax);
				}
			gameData.render.nShaderChanges++;
			}
		else {
			if (dMaxPrev != dMax) {
				glUniform1f (glGetUniformLocation (hGlareShader, "dMax"), (GLfloat) dMax);
				}
			}
		dMaxPrev = dMax;
		glDisable (GL_DEPTH_TEST);
		}
	ogl.SelectTMU (GL_TEXTURE0);
	}
}
Ejemplo n.º 11
0
void EndRenderFaces (int nType, int bDepthOnly)
{
#if 1
G3FlushFaceBuffer (1);
#endif
if (!bDepthOnly) {
	G3DisableClientStates (1, 1, 0, GL_TEXTURE3);
	glEnable (GL_TEXTURE_2D);
	OGL_BINDTEX (0);
	glDisable (GL_TEXTURE_2D);

	G3DisableClientStates (1, 1, 0, GL_TEXTURE2);
	glEnable (GL_TEXTURE_2D);
	OGL_BINDTEX (0);
	glDisable (GL_TEXTURE_2D);

	G3DisableClientStates (1, 1, 0, GL_TEXTURE1);
	glEnable (GL_TEXTURE_2D);
	OGL_BINDTEX (0);
	glDisable (GL_TEXTURE_2D);
	}
G3DisableClientStates (!bDepthOnly, !bDepthOnly, 1, GL_TEXTURE0);
glEnable (GL_TEXTURE_2D);
OGL_BINDTEX (0);
glDisable (GL_TEXTURE_2D);
if (gameStates.ogl.bShadersOk) {
	glUseProgramObject (0);
	gameStates.render.history.nShader = -1;
	}
if (nType != 3) {
	if (gameStates.render.bPerPixelLighting == 2)
		OglDisableLighting ();
	OglResetTransform (1);
	if (FACES.vboDataHandle)
		glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0);
	}
else 	if (CoronaStyle () == 2)
	UnloadGlareShader ();
else if (gameStates.ogl.bOcclusionQuery && gameData.render.lights.nCoronas && !gameStates.render.bQueryCoronas && (CoronaStyle () == 1))
	glDeleteQueries (gameData.render.lights.nCoronas, gameData.render.lights.coronaQueries.Buffer ());
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
OglClearError (0);
}
Ejemplo n.º 12
0
int G3SetupHeadLightShader (int nType, int bLightMaps, tRgbaColorf *colorP)
{
#ifdef _DEBUG
	int			oglRes;
#endif
	int			nLights, nShader;
	tRgbaColorf	color;

//headlights
nLights = IsMultiGame ? gameData.render.lights.dynamic.headLights.nLights : 1;
InitHeadlightShaders (nLights);
nShader = 10 + bLightMaps * 4 + nType;
if (nShader != gameStates.render.history.nShader) {
	//glUseProgramObject (0);
	gameData.render.nStateChanges++;
	glUseProgramObject (activeShaderProg = headLightShaderProgs [bLightMaps][nType]);
	if (nType) {
		glUniform1i (glGetUniformLocation (activeShaderProg, "baseTex"), bLightMaps);
		if (nType > 1) {
			glUniform1i (glGetUniformLocation (activeShaderProg, "decalTex"), 1 + bLightMaps);
			if (nType > 2)
				glUniform1i (glGetUniformLocation (activeShaderProg, "maskTex"), 2 + bLightMaps);
			}
		}
#if 1
#	if 0
	glUniform1f (glGetUniformLocation (activeShaderProg, "cutOff"), 0.5f);
	glUniform1f (glGetUniformLocation (activeShaderProg, "spotExp"), 8.0f);
	glUniform1f (glGetUniformLocation (activeShaderProg, "grAlpha"), 1.0f);
	glUniform1fv (glGetUniformLocation (activeShaderProg, "brightness"), nLights, 
					  (GLfloat *) gameData.render.lights.dynamic.headLights.brightness);
#	endif
	//glUniform1f (glGetUniformLocation (activeShaderProg, "aspect"), (float) grdCurScreen->scWidth / (float) grdCurScreen->scHeight);
	//glUniform1f (glGetUniformLocation (activeShaderProg, "zoom"), 65536.0f / (float) gameStates.render.xZoom);
#if 1
	for (int i = 0; i < nLights; i++) {
		glEnable (GL_LIGHT0 + i);
		glLightfv (GL_LIGHT0 + i, GL_POSITION, (GLfloat *) (gameData.render.lights.dynamic.headLights.pos + i));
		glLightfv (GL_LIGHT0 + i, GL_SPOT_DIRECTION, (GLfloat *) (gameData.render.lights.dynamic.headLights.dir + i));
		}
#else
	glUniform3fv (glGetUniformLocation (activeShaderProg, "lightPosWorld"), nLights, 
					  (GLfloat *) gameData.render.lights.dynamic.headLights.pos);
	glUniform3fv (glGetUniformLocation (activeShaderProg, "lightDirWorld"), nLights, 
					  (GLfloat *) gameData.render.lights.dynamic.headLights.dir);
#endif
#endif
	if (colorP) {
		color.red = colorP->red * 1.1f;
		color.green = colorP->green * 1.1f;
		color.blue = colorP->blue * 1.1f;
		color.alpha = colorP->alpha;
		}
	else {
		color.red = color.green = color.blue = 2.0f;
		color.alpha = 1;
		}
	glUniform4fv (glGetUniformLocation (activeShaderProg, "matColor"), 1, (GLfloat *) &color);
#ifdef _DEBUG
	oglRes = glGetError ();
#endif
	}
return gameStates.render.history.nShader = nShader;
}
Ejemplo n.º 13
0
void defaultShader::unbind() {
  if (glShadingLanguageSupport)
    glUseProgramObject(0);
}
Ejemplo n.º 14
0
int BeginRenderFaces (int nType, int bDepthOnly)
{
	int	//bVBO = 0,
			bLightmaps = (nType < 4) && !gameStates.render.bFullBright && lightmapManager.HaveLightmaps (),
			bNormals = !bDepthOnly; 

gameData.threads.vertColor.data.bDarkness = 0;
gameStates.render.nType = nType;
gameStates.render.history.nShader = -1;
gameStates.render.history.bOverlay = -1;
gameStates.render.history.bColored = 1;
gameStates.render.history.nBlendMode = -1;
gameStates.render.history.bmBot = 
gameStates.render.history.bmTop =
gameStates.render.history.bmMask = NULL;
gameStates.render.bQueryCoronas = 0;
ogl.ResetClientStates ();
if (ogl.m_states.bShadersOk) {
	glUseProgramObject (0);
	gameStates.render.history.nShader = -1;
	}
glEnable (GL_CULL_FACE);
CTexture::Wrap (GL_REPEAT);
if (!bDepthOnly) 
	glDepthFunc (GL_LEQUAL);
else {
	glColorMask (0,0,0,0);
	glDepthMask (1);
	glDepthFunc (GL_LESS);
	}
if (nType == 3) {
	if (CoronaStyle () == 2)
		LoadGlareShader (10);
	return 0;
	}
else {
#if GEOMETRY_VBOS
	if (FACES.vboDataHandle) {
		glBindBufferARB (GL_ARRAY_BUFFER_ARB, FACES.vboDataHandle);
		bVBO = 1;
		}
#endif
	if ((nType < 4) && (gameStates.render.bPerPixelLighting == 2)) {
		ogl.EnableLighting (1);
		for (int i = 0; i < 8; i++)
			glEnable (GL_LIGHT0 + i);
		glDisable (GL_LIGHTING);
		glColor4f (1,1,1,1);
		}
	}
ogl.SetupTransform (1);
ogl.EnableClientStates (!bDepthOnly, !(bDepthOnly || gameStates.render.bFullBright), bNormals, GL_TEXTURE0);
#if GEOMETRY_VBOS
if (bVBO) {
	if (bNormals)
		OglNormalPointer (GL_FLOAT, 0, G3_BUFFER_OFFSET (FACES.iNormals));
	if (!bDepthOnly) {
		if (bLightmaps)
			OglTexCoordPointer (2, GL_FLOAT, 0, G3_BUFFER_OFFSET (FACES.iLMapTexCoord));
		else
			OglTexCoordPointer (2, GL_FLOAT, 0, G3_BUFFER_OFFSET (FACES.iTexCoord));
		OglColorPointer (4, GL_FLOAT, 0, G3_BUFFER_OFFSET (FACES.iColor));
		}
	OglVertexPointer (3, GL_FLOAT, 0, G3_BUFFER_OFFSET (FACES.iVertices));
	if (bLightmaps) {
		ogl.EnableClientStates (1, 1, bNormals, GL_TEXTURE1);
		OglTexCoordPointer (2, GL_FLOAT, 0, G3_BUFFER_OFFSET (FACES.iTexCoord));
		OglColorPointer (4, GL_FLOAT, 0, G3_BUFFER_OFFSET (FACES.iColor));
		OglVertexPointer (3, GL_FLOAT, 0, G3_BUFFER_OFFSET (FACES.iVertices));
		}
	ogl.EnableClientStates (1, 1, 0, GL_TEXTURE1 + bLightmaps);
	OglTexCoordPointer (2, GL_FLOAT, 0, G3_BUFFER_OFFSET (FACES.iOvlTexCoord));
	OglColorPointer (4, GL_FLOAT, 0, G3_BUFFER_OFFSET (FACES.iColor));
	OglVertexPointer (3, GL_FLOAT, 0, G3_BUFFER_OFFSET (FACES.iVertices));
	ogl.EnableClientStates (1, 1, 0, GL_TEXTURE2 + bLightmaps);
	OglTexCoordPointer (2, GL_FLOAT, 0, G3_BUFFER_OFFSET (FACES.iOvlTexCoord));
	OglColorPointer (4, GL_FLOAT, 0, G3_BUFFER_OFFSET (FACES.iColor));
	OglVertexPointer (3, GL_FLOAT, 0, G3_BUFFER_OFFSET (FACES.iVertices));
	if (FACES.vboIndexHandle)
		glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, FACES.vboIndexHandle);
	}	
else 
#endif
	{
	if (bNormals)
		OglNormalPointer (GL_FLOAT, 0, reinterpret_cast<const GLvoid *> (FACES.normals.Buffer ()));
	if (!bDepthOnly) {
		if (bLightmaps)
			OglTexCoordPointer (2, GL_FLOAT, 0, reinterpret_cast<const GLvoid *> (FACES.lMapTexCoord.Buffer ()));
		else
			OglTexCoordPointer (2, GL_FLOAT, 0, reinterpret_cast<const GLvoid *> (FACES.texCoord.Buffer ()));
		if (!gameStates.render.bFullBright)
			OglColorPointer (4, GL_FLOAT, 0, reinterpret_cast<const GLvoid *> (FACES.color.Buffer ()));
		}
	OglVertexPointer (3, GL_FLOAT, 0, reinterpret_cast<const GLvoid *> (FACES.vertices.Buffer ()));
	if (bLightmaps) {
		ogl.EnableClientStates (1, !gameStates.render.bFullBright, bNormals, GL_TEXTURE1);
		OglTexCoordPointer (2, GL_FLOAT, 0, reinterpret_cast<const GLvoid *> (FACES.texCoord.Buffer ()));
		if (!gameStates.render.bFullBright)
			OglColorPointer (4, GL_FLOAT, 0, reinterpret_cast<const GLvoid *> (FACES.color.Buffer ()));
		OglVertexPointer (3, GL_FLOAT, 0, reinterpret_cast<const GLvoid *> (FACES.vertices.Buffer ()));
		}
	ogl.EnableClientStates (1, !gameStates.render.bFullBright, bNormals, GL_TEXTURE1 + bLightmaps);
	OglTexCoordPointer (2, GL_FLOAT, 0, reinterpret_cast<const GLvoid *> (FACES.ovlTexCoord.Buffer ()));
	if (!gameStates.render.bFullBright)
		OglColorPointer (4, GL_FLOAT, 0, reinterpret_cast<const GLvoid *> (FACES.color.Buffer ()));
	OglVertexPointer (3, GL_FLOAT, 0, reinterpret_cast<const GLvoid*> (FACES.vertices.Buffer ()));
	ogl.EnableClientStates (1, !gameStates.render.bFullBright, 0, GL_TEXTURE2 + bLightmaps);
	OglTexCoordPointer (2, GL_FLOAT, 0, reinterpret_cast<const GLvoid *> (FACES.ovlTexCoord.Buffer ()));
	if (!gameStates.render.bFullBright)
		OglColorPointer (4, GL_FLOAT, 0, reinterpret_cast<const GLvoid *> (FACES.color.Buffer ()));
	OglVertexPointer (3, GL_FLOAT, 0, reinterpret_cast<const GLvoid *> (FACES.vertices.Buffer ()));
	}
if (bNormals)
	ogl.EnableClientState (GL_NORMAL_ARRAY, GL_TEXTURE0);
if (gameStates.render.bFullBright)
	glColor3f (1,1,1);
glEnable (GL_BLEND);
glBlendFunc (GL_ONE, GL_ZERO);
ogl.ClearError (0);
return 1;
}
Ejemplo n.º 15
0
int G3DrawTexPolyLightmap (
    int			nVertices,
    g3sPoint**	pointList,
    tUVL*			uvlList,
    tUVL*			uvlLMap,
    CBitmap*		bmBot,
    CBitmap*		bmTop,
    tLightmap*	lightmap,
    CFixVector*	pvNormal,
    int			orient,
    int			bBlend,
    short			nSegment)
{
    int			i, nFrame, bShaderMerge;
    CBitmap	*bmP = NULL;
    g3sPoint		**ppl;

    if (gameStates.render.nShadowBlurPass == 1) {
        G3DrawWhitePoly (nVertices, pointList);
        return 0;
    }
    if (!bmBot)
        return 1;
    r_tpolyc++;
//if (gameStates.render.nShadowPass != 3)
    glDepthFunc (GL_LEQUAL);
    if (FAST_SHADOWS) {
        if (bBlend)
            glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        else
            glDisable (GL_BLEND);
    }
    else {
        if (gameStates.render.nShadowPass == 3) {
            glEnable (GL_BLEND);
            glBlendFunc (GL_ONE, GL_ONE);
        }
    }
    glDepthFunc (GL_LEQUAL);
    bmBot = bmBot->Override (-1);
    if (bmTop && (bmTop = bmTop->Override (-1)) && bmTop->Frames ()) {
        nFrame = (int) (bmTop->CurFrame () - bmTop->Frames ());
        bmP = bmTop;
        bmTop = bmTop->CurFrame ();
    }
    else
        nFrame = -1;
    if (!lightmap) //lightmapping enabled
        return G3DrawTexPolyMulti (nVertices, pointList, uvlList, uvlLMap, bmBot, bmTop, lightmap, pvNormal, orient, bBlend, nSegment);
// chose shaders depending on whether overlay bitmap present or not
    if ((bShaderMerge = bmTop && gameOpts->ogl.bGlTexMerge)) {
        lmProg = lmShaderProgs [(bmTop->Flags () & BM_FLAG_SUPER_TRANSPARENT) != 0];
        glUseProgramObject (lmProg);
    }
    InitTMU0 (0);	// use render pipeline 0 for bottom texture
    if (bmBot->Bind (1))
        return 1;
    bmBot = bmBot->CurFrame (-1);
    bmBot->Texture ()->Wrap (GL_REPEAT);
    if (bShaderMerge)
        glUniform1i (glGetUniformLocation (lmProg, "btmTex"), 0);
    if (bmTop) { // use render pipeline 1 for overlay texture
        InitTMU1 (0);
        if (bmTop->Bind (1))
            return 1;
        bmTop = bmTop->CurFrame (-1);
        bmTop->Texture ()->Wrap (GL_REPEAT);
        glUniform1i (glGetUniformLocation (lmProg, "topTex"), 1);
    }
// use render pipeline 2 for lightmap texture
    InitTMU2 (0);
//OGL_BINDTEX (lightmap->handle);
    if (bShaderMerge)
        glUniform1i (glGetUniformLocation (lmProg, "lMapTex"), 2);
    glBegin (GL_TRIANGLE_FAN);
    ppl = pointList;
    if (gameStates.render.bFullBright)
        glColor3d (1,1,1);
    for (i = 0; i < nVertices; i++, ppl++) {
        if (!gameStates.render.bFullBright)
            SetTMapColor (uvlList + i, i, bmBot, 1, NULL);
        glMultiTexCoord2f (GL_TEXTURE0, X2F (uvlList [i].u), X2F (uvlList [i].v));
        if (bmTop)
            SetTexCoord (uvlList + i, orient, 1, NULL, 0);
        glMultiTexCoord2f (GL_TEXTURE2_ARB, X2F (uvlLMap [i].u), X2F (uvlLMap [i].v));
        OglVertex3f (*ppl);
    }
    glEnd ();
    ExitTMU (0);
    if (bShaderMerge)
        glUseProgramObject (lmProg = 0);
    return 0;
}
Ejemplo n.º 16
0
int G3DrawTexPolyMulti (
    int			nVertices,
    g3sPoint**	pointList,
    tUVL*			uvlList,
    tUVL*			uvlLMap,
    CBitmap*		bmBot,
    CBitmap*		bmTop,
    tLightmap*	lightmap,
    CFixVector*	pvNormal,
    int			orient,
    int			bBlend,
    short			nSegment)
{
    int			i, nShader, nFrame;
    int			bShaderMerge = 0,
                bSuperTransp = 0;
    int			bLight = 1,
                bDynLight = gameStates.render.bApplyDynLight && (gameStates.app.bEndLevelSequence < EL_OUTSIDE),
                bDepthSort,
                bResetColor = 0,
                bOverlay = 0;
    tFaceColor	*pc;
    CBitmap		*bmP = NULL, *mask = NULL;
    g3sPoint		*pl, **ppl;
#if USE_VERTNORMS
    CFloatVector	vNormal, vVertPos;
#endif
#if G3_DRAW_ARRAYS
    int			bVertexArrays = gameData.render.vertP != NULL;
#else
    int			bVertexArrays = 0;
#endif

    if (gameStates.render.nShadowBlurPass == 1) {
        G3DrawWhitePoly (nVertices, pointList);
        return 0;
    }
    if (!bmBot)
        return 1;
    r_tpolyc++;
    if (FAST_SHADOWS) {
        if (!bBlend)
            glDisable (GL_BLEND);
#if 0
        else
            glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
#endif
    }
    else {
        if (gameStates.render.nShadowPass == 1)
            bLight = !bDynLight;
        else if (gameStates.render.nShadowPass == 3) {
            glEnable (GL_BLEND);
            glBlendFunc (GL_ONE, GL_ONE);
        }
    }
    glDepthFunc (GL_LEQUAL);
    bmBot = bmBot->Override (-1);
    bDepthSort = (!bmTop && (gameOpts->render.bDepthSort > 0) &&
                  ((gameStates.render.grAlpha < 1.0f) ||
                   (bmBot->Flags () & (BM_FLAG_TRANSPARENT | BM_FLAG_SEE_THRU | BM_FLAG_TGA)) == (BM_FLAG_TRANSPARENT | BM_FLAG_TGA)));
    if (bmTop && (bmTop = bmTop->Override (-1)) && bmTop->Frames ()) {
        nFrame = (int) (bmTop->CurFrame () - bmTop->Frames ());
        bmP = bmTop;
        bmTop = bmTop->CurFrame ();
    }
    else
        nFrame = -1;
    if (bmTop) {
        if (nFrame < 0)
            bSuperTransp = (bmTop->Flags () & BM_FLAG_SUPER_TRANSPARENT) != 0;
        else
            bSuperTransp = (bmP->Flags () & BM_FLAG_SUPER_TRANSPARENT) != 0;
        bShaderMerge = bSuperTransp && ogl.m_states.bGlTexMerge;
        bOverlay = !bShaderMerge;
    }
    else
        bOverlay = -1;
#if G3_DRAW_ARRAYS
retry:
#endif
    if (bShaderMerge) {
        mask = gameStates.render.textures.bHaveMaskShader ? bmTop->Mask () : NULL;
        nShader = bSuperTransp ? mask ? 2 : 1 : 0;
        glUseProgramObject (activeShaderProg = tmShaderProgs [nShader]);
        INIT_TMU (InitTMU0, GL_TEXTURE0, bmBot, lightmapManager.Buffer (), bVertexArrays, 0);
        glUniform1i (glGetUniformLocation (activeShaderProg, "btmTex"), 0);
        INIT_TMU (InitTMU1, GL_TEXTURE1, bmTop, lightmapManager.Buffer (), bVertexArrays, 0);
        glUniform1i (glGetUniformLocation (activeShaderProg, "topTex"), 1);
        if (mask) {
#if DBG
            InitTMU2 (bVertexArrays);
            G3_BIND (GL_TEXTURE2, mask, lightmapManager.Buffer (), bVertexArrays);
#else
            INIT_TMU (InitTMU2, GL_TEXTURE2, mask, lightmapManager.Buffer (), bVertexArrays, 0);
#endif
            glUniform1i (glGetUniformLocation (activeShaderProg, "maskTex"), 2);
        }
        glUniform1f (glGetUniformLocation (activeShaderProg, "grAlpha"), gameStates.render.grAlpha);
    }
    else if (!bDepthSort) {
        if (bmBot == gameData.endLevel.satellite.bmP) {
            ogl.SelectTMU (GL_TEXTURE0);
            glEnable (GL_TEXTURE_2D);
        }
        else
            InitTMU0 (bVertexArrays);
        if (bmBot->Bind (1))
            return 1;
        bmBot = bmBot->CurFrame (-1);
        bmBot->Texture ()->Wrap ((bmBot == bmpDeadzone) ? GL_CLAMP : GL_REPEAT);
    }

    if (!bDepthSort) {
        if (SHOW_DYN_LIGHT) {
#if USE_VERTNORMS
            if (pvNormal) {
                vNormal.Assign (*pvNormal);
                transformation.Rotate(vNormal, vNormal, 0);
            }
            else
                G3CalcNormal (pointList, &vNormal);
#else
            G3Normal (pointList, pvNormal);
#endif
        }
        if (gameStates.render.bFullBright) {
            glColor3f (1,1,1);
            bLight = 0;
        }
        else if (!gameStates.render.nRenderPass)
            bLight = 0;
        else if (!bLight)
            glColor3i (0,0,0);
        if (!bLight)
            bDynLight = 0;
        ogl.m_states.bDynObjLight = bDynLight;
    }

    ogl.m_states.fAlpha = gameStates.render.grAlpha;
    if (bVertexArrays || bDepthSort) {
        CFloatVector	vertices [8];
        tFaceColor		vertColors [8];
        tTexCoord2f		texCoord [2][8];
        int				vertIndex [8];
        //int				colorIndex [8];

        for (i = 0, ppl = pointList; i < nVertices; i++, ppl++) {
            pl = *ppl;
            vertIndex [i] = pl->p3_index;
            //colorIndex [i] = i;
            if (pl->p3_index < 0)
                vertices[i].Assign (pl->p3_vec);
            else
                vertices [i] = gameData.render.vertP [pl->p3_index];
            texCoord [0][i].v.u = X2F (uvlList [i].u);
            texCoord [0][i].v.v = X2F (uvlList [i].v);
            SetTexCoord (uvlList + i, orient, 1, texCoord [1] + i, 0);
            G3VERTPOS (vVertPos, pl);
            if (bDynLight)
                G3VertexColor (G3GetNormal (pl, &vNormal), vVertPos.XYZ(), vertIndex [i], vertColors + i, NULL,
                               gameStates.render.nState ? X2F (uvlList [i].l) : 1, 0, 0);
            else if (bLight)
                SetTMapColor (uvlList + i, i, bmBot, !bOverlay, vertColors + i);
        }
#if 1
        if (gameOpts->render.bDepthSort > 0) {
            bmBot->SetupTexture (1, 0);
            transparencyRenderer.AddPoly (NULL, NULL, bmBot, vertices, nVertices, texCoord [0], NULL, vertColors, nVertices, 1, GL_TRIANGLE_FAN, GL_REPEAT, 0, nSegment);
            return 0;
        }
#endif
    }
#if G3_DRAW_ARRAYS
    if (bVertexArrays) {
        if (!ogl.EnableClientStates (1, 1, 0, GL_TEXTURE0)) {
            bVertexArrays = 0;
            goto retry;
        }
        OglVertexPointer (3, GL_FLOAT, sizeof (CFloatVector), vertices);
//	OglIndexPointer (GL_INT, 0, colorIndex);
        OglTexCoordPointer (2, GL_FLOAT, sizeof (tTexCoord3f), texCoord [0]);
        if (bLight)
            OglColorPointer (4, GL_FLOAT, sizeof (tFaceColor), vertColors);
        if (bmTop && !bOverlay) {
            if (!ogl.EnableClientStates (1, 1, 0, GL_TEXTURE1)) {
                ogl.DisableClientStates (1, 1, 0, GL_TEXTURE0);
                bVertexArrays = 0;
                goto retry;
            }
            OglVertexPointer (3, GL_FLOAT, sizeof (CFloatVector), vertices);
            if (bLight)
                OglColorPointer (4, GL_FLOAT, sizeof (tFaceColor), vertColors);
//		OglIndexPointer (GL_INT, 0, colorIndex);
            OglTexCoordPointer (2, GL_FLOAT, sizeof (tTexCoord3f), texCoord [1]);
        }
        OglDrawArrays (GL_TRIANGLE_FAN, 0, nVertices);
        ogl.DisableClientStates (1, 1, 0, GL_TEXTURE0);
        if (bmTop && !bOverlay)
            ogl.DisableClientStates (GL_TEXTURE1);
    }
    else
#endif
    {
        glBegin (GL_TRIANGLE_FAN);
        if (bDynLight) {
            if (bOverlay) {
                for (i = 0, ppl = pointList; i < nVertices; i++, ppl++) {
                    pl = *ppl;
                    G3VERTPOS (vVertPos, pl);
                    G3VertexColor (G3GetNormal (pl, &vNormal), vVertPos.XYZ(), pl->p3_index, NULL, NULL,
                                   gameStates.render.nState ? X2F (uvlList [i].l) : 1, 1, 0);
                    glTexCoord2f (X2F (uvlList [i].u), X2F (uvlList [i].v));
                    glVertex3fv (reinterpret_cast<GLfloat*> (&vVertPos));
                }
            }
            else {
                for (i = 0, ppl = pointList; i < nVertices; i++, ppl++) {
                    pl = *ppl;
                    G3VERTPOS (vVertPos, pl);
                    G3VertexColor (G3GetNormal (pl, &vNormal), vVertPos.XYZ(), pl->p3_index, NULL, NULL,
                                   /*gameStates.render.nState ? X2F (uvlList [i].l) :*/ 1, 1, 0);
                    glMultiTexCoord2f (GL_TEXTURE0, X2F (uvlList [i].u), X2F (uvlList [i].v));
                    SetTexCoord (uvlList + i, orient, 1, NULL, mask != NULL);
                    glVertex3fv (reinterpret_cast<GLfloat*> (&vVertPos));
                }
            }
        }
        else if (bLight) {
            if (bOverlay) {
                for (i = 0, ppl = pointList; i < nVertices; i++, ppl++) {
                    if (gameStates.render.nState || gameStates.app.bEndLevelSequence)
                        SetTMapColor (uvlList + i, i, bmBot, 1, NULL);
                    else {
                        pc = gameData.render.color.vertices + (*ppl)->p3_index;
                        glColor3fv (reinterpret_cast<GLfloat*> (&pc->color));
                    }
                    glTexCoord2f (X2F (uvlList [i].u), X2F (uvlList [i].v));
                    OglVertex3f (*ppl);
                }
            }
            else {
                bResetColor = (bOverlay != 1);
                for (i = 0, ppl = pointList; i < nVertices; i++, ppl++) {
                    if (gameStates.render.nState || !RENDERPATH)
                        SetTMapColor (uvlList + i, i, bmBot, 1, NULL);
                    else {
                        pc = gameData.render.color.vertices + (*ppl)->p3_index;
                        glColor3fv (reinterpret_cast<GLfloat*> (&pc->color));
                    }
                    glMultiTexCoord2f (GL_TEXTURE0, X2F (uvlList [i].u), X2F (uvlList [i].v));
                    SetTexCoord (uvlList + i, orient, 1, NULL, mask != NULL);
                    OglVertex3f (*ppl);
                }
            }
        }
        else {
            if (bOverlay) {
                for (i = 0, ppl = pointList; i < nVertices; i++, ppl++) {
                    glTexCoord2f (X2F (uvlList [i].u), X2F (uvlList [i].v));
                    OglVertex3f (*ppl);
                }
            }
            else {
                for (i = 0, ppl = pointList; i < nVertices; i++, ppl++) {
                    glMultiTexCoord2f (GL_TEXTURE0, X2F (uvlList [i].u), X2F (uvlList [i].v));
                    SetTexCoord (uvlList + i, orient, 1, NULL, mask != NULL);
                    OglVertex3f (*ppl);
                }
            }
        }
        glEnd ();
    }
    if (bOverlay > 0) {
        r_tpolyc++;
        ogl.SelectTMU (GL_TEXTURE0);
        glEnable (GL_TEXTURE_2D);
        if (bmTop->Bind (1))
            return 1;
        bmTop = bmTop->CurFrame (-1);
        bmTop->Texture ()->Wrap (GL_REPEAT);
        glBegin (GL_TRIANGLE_FAN);
        if (bDynLight) {
            for (i = 0, ppl = pointList; i < nVertices; i++, ppl++) {
                vVertPos.Assign ((*ppl)->p3_vec);
                G3VertexColor (G3GetNormal (*ppl, &vNormal), vVertPos.XYZ(), (*ppl)->p3_index, NULL, NULL, 1, 1, 0);
                SetTexCoord (uvlList + i, orient, 0, NULL, mask != NULL);
                OglVertex3f (*ppl);
            }
        }
        else if (bLight) {
            for (i = 0, ppl = pointList; i < nVertices; i++, ppl++) {
                SetTMapColor (uvlList + i, i, bmTop, 1, NULL);
                SetTexCoord (uvlList + i, orient, 0, NULL, mask != NULL);
                OglVertex3f (*ppl);
            }
        }
        else {
            for (i = 0, ppl = pointList; i < nVertices; i++, ppl++) {
                SetTexCoord (uvlList + i, orient, 0, NULL, mask != NULL);
                OglVertex3f (*ppl);
            }
        }
        glEnd ();
        glDepthFunc (GL_LESS);
#if OGL_CLEANUP
        OGL_BINDTEX (0);
        glDisable (GL_TEXTURE_2D);
#endif
    }
    else if (bShaderMerge) {
#if OGL_CLEANUP
        ogl.SelectTMU (GL_TEXTURE1, bVertexArrays != 0);
        OGL_BINDTEX (0);
        glDisable (GL_TEXTURE_2D); // Disable the 2nd texture
#endif
        glUseProgramObject (activeShaderProg = 0);
    }
    ogl.SelectTMU (GL_TEXTURE0, bVertexArrays != 0);
    OGL_BINDTEX (0);
    glDisable (GL_TEXTURE_2D);
    tMapColor.index =
        lightColor.index = 0;
    if (!bBlend)
        glEnable (GL_BLEND);
    return 0;
}