Fix portals (and compiles again with gcc).

git-svn-id: https://svn.code.sf.net/p/fteqw/code/branches/wip@3604 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2010-08-29 13:49:43 +00:00
parent 9cbdfb7fd0
commit 9f29f8d97f
4 changed files with 47 additions and 31 deletions

View file

@ -1839,7 +1839,10 @@ void Surf_SetupFrame(void)
r_oldviewcluster = r_viewcluster;
r_oldviewcluster2 = r_viewcluster2;
leaf = RMod_PointInLeaf (cl.worldmodel, r_origin);
if (r_refdef.recurse)
leaf = RMod_PointInLeaf (cl.worldmodel, r_refdef.pvsorigin);
else
leaf = RMod_PointInLeaf (cl.worldmodel, r_origin);
r_viewcluster = r_viewcluster2 = leaf->cluster;
// check above and below so crossing solid water doesn't draw wrong

View file

@ -219,7 +219,7 @@ void GLR_InitTextures (void);
void GLR_InitEfrags (void);
void GLR_RenderView (void); // must set r_refdef first
// called whenever r_refdef or vid change
void R_DrawPortal(struct batch_s *batch);
void R_DrawPortal(struct batch_s *batch, struct batch_s **blist);
void GLR_PreNewMap(void);
void GLR_NewMap (void);

View file

@ -2818,7 +2818,7 @@ static void BE_SubmitBatch(batch_t *batch)
}
}
static void BE_SubmitMeshesPortals(batch_t *worldlist, batch_t *dynamiclist)
static void BE_SubmitMeshesPortals(batch_t **worldlist, batch_t *dynamiclist)
{
batch_t *batch, *old;
int i;
@ -2827,14 +2827,20 @@ static void BE_SubmitMeshesPortals(batch_t *worldlist, batch_t *dynamiclist)
{
for (i = 0; i < 2; i++)
{
for (batch = i?dynamiclist:worldlist; batch; batch = batch->next)
for (batch = i?dynamiclist:worldlist[SHADER_SORT_PORTAL]; batch; batch = batch->next)
{
if (batch->meshes == batch->firstmesh)
continue;
if (batch->buildmeshes)
batch->buildmeshes(batch);
else
batch->shader = R_TextureAnimation(batch->ent->framestate.g[FS_REG].frame[0], batch->texture)->shader;
/*draw already-drawn portals as depth-only, to ensure that their contents are not harmed*/
BE_SelectMode(BEM_DEPTHONLY, 0);
for (old = worldlist; old && old != batch; old = old->next)
for (old = worldlist[SHADER_SORT_PORTAL]; old && old != batch; old = old->next)
{
if (old->meshes == old->firstmesh)
continue;
@ -2851,9 +2857,7 @@ static void BE_SubmitMeshesPortals(batch_t *worldlist, batch_t *dynamiclist)
}
BE_SelectMode(BEM_STANDARD, 0);
#if 0
R_DrawPortal(batch);
#endif
R_DrawPortal(batch, worldlist);
/*clear depth again*/
GL_ForceDepthWritable();
@ -2902,7 +2906,7 @@ void BE_SubmitMeshes (qboolean drawworld, batch_t **blist)
if (drawworld)
{
if (i == SHADER_SORT_PORTAL && !r_noportals.ival && !r_refdef.recurse)
BE_SubmitMeshesPortals(model->batches[i], blist[i]);
BE_SubmitMeshesPortals(model->batches, blist[i]);
BE_SubmitMeshesSortList(model->batches[i]);
}
@ -3154,23 +3158,26 @@ void BE_DrawWorld (qbyte *vis)
RSpeedLocals();
GL_DoSwap();
if (shaderstate.wmesh > shaderstate.maxwmesh)
if (!r_refdef.recurse)
{
int newm = shaderstate.wmesh;
shaderstate.wmeshes = BZ_Realloc(shaderstate.wmeshes, newm * sizeof(*shaderstate.wmeshes));
memset(shaderstate.wmeshes + shaderstate.maxwmesh, 0, (newm - shaderstate.maxwmesh) * sizeof(*shaderstate.wmeshes));
shaderstate.maxwmesh = newm;
}
if (shaderstate.wbatch > shaderstate.maxwbatches)
{
int newm = shaderstate.wbatch;
shaderstate.wbatches = BZ_Realloc(shaderstate.wbatches, newm * sizeof(*shaderstate.wbatches));
memset(shaderstate.wbatches + shaderstate.maxwbatches, 0, (newm - shaderstate.maxwbatches) * sizeof(*shaderstate.wbatches));
shaderstate.maxwbatches = newm;
}
if (shaderstate.wmesh > shaderstate.maxwmesh)
{
int newm = shaderstate.wmesh;
shaderstate.wmeshes = BZ_Realloc(shaderstate.wmeshes, newm * sizeof(*shaderstate.wmeshes));
memset(shaderstate.wmeshes + shaderstate.maxwmesh, 0, (newm - shaderstate.maxwmesh) * sizeof(*shaderstate.wmeshes));
shaderstate.maxwmesh = newm;
}
if (shaderstate.wbatch > shaderstate.maxwbatches)
{
int newm = shaderstate.wbatch;
shaderstate.wbatches = BZ_Realloc(shaderstate.wbatches, newm * sizeof(*shaderstate.wbatches));
memset(shaderstate.wbatches + shaderstate.maxwbatches, 0, (newm - shaderstate.maxwbatches) * sizeof(*shaderstate.wbatches));
shaderstate.maxwbatches = newm;
}
shaderstate.wmesh = 0;
shaderstate.wbatch = 0;
shaderstate.wmesh = 0;
shaderstate.wbatch = 0;
}
BE_GenModelBatches(batches);
shaderstate.curentity = NULL;

View file

@ -1276,13 +1276,14 @@ static void TransformDir(vec3_t in, vec3_t planea[3], vec3_t viewa[3], vec3_t re
VectorMA(result, d, viewa[i], result);
}
}
void R_DrawPortal(batch_t *batch, batch_t *blist)
void R_DrawPortal(batch_t *batch, batch_t **blist)
{
entity_t *view;
GLdouble glplane[4];
plane_t plane;
refdef_t oldrefdef;
mesh_t *mesh = batch->mesh[batch->firstmesh];
int sort;
if (r_refdef.recurse)
return;
@ -1323,7 +1324,7 @@ void R_DrawPortal(batch_t *batch, batch_t *blist)
/*calculate where the surface is meant to be*/
VectorCopy(mesh->normals_array[0], paxis[0]);
PerpendicularVector(paxis[1], paxis[1]);
PerpendicularVector(paxis[1], paxis[0]);
CrossProduct(paxis[0], paxis[1], paxis[2]);
d = DotProduct(view->origin, plane.normal) - plane.dist;
VectorMA(view->origin, -d, paxis[0], porigin);
@ -1352,7 +1353,8 @@ void R_DrawPortal(batch_t *batch, batch_t *blist)
/*FIXME: the batch stuff should be done in renderscene*/
/*fixup the first mesh index*/
for (batch = blist; batch; batch = batch->next)
for (sort = 0; sort < SHADER_SORT_COUNT; sort++)
for (batch = blist[sort]; batch; batch = batch->next)
{
batch->firstmesh = batch->meshes;
}
@ -1370,7 +1372,8 @@ void R_DrawPortal(batch_t *batch, batch_t *blist)
R_RenderScene();
qglDisable(GL_CLIP_PLANE0);
for (batch = blist; batch; batch = batch->next)
for (sort = 0; sort < SHADER_SORT_COUNT; sort++)
for (batch = blist[sort]; batch; batch = batch->next)
{
batch->firstmesh = 0;
}
@ -1827,9 +1830,6 @@ void GLR_RenderView (void)
R_RenderScene ();
}
if (r_bloom.ival)
R_BloomBlend();
// qglDisable(GL_FOG);
if (r_speeds.ival)
@ -1850,6 +1850,9 @@ void GLR_RenderView (void)
if (r_refdef.flags & Q2RDF_NOWORLDMODEL)
return;
if (r_bloom.ival)
R_BloomBlend();
// SCENE POST PROCESSING
// we check if we need to use any shaders - currently it's just waterwarp
if ((r_waterwarp.value>0 && r_viewleaf && r_viewleaf->contents <= Q1CONTENTS_WATER))
@ -1863,6 +1866,9 @@ void GLR_RenderView (void)
if (gl_motionblur.value>0 && gl_motionblur.value < 1 && qglCopyTexImage2D)
R_RenderMotionBlur();
if (qglGetError())
Con_Printf("GL Error drawing post processing\n");
}
#endif