Skip to content

Commit

Permalink
- the texture matrix buffer index variables need to be tracked by ref…
Browse files Browse the repository at this point in the history
…erence, not by value. All accesses need to go to the actual variable storing the value so that FakeFlat related copies both get and write to the correct place.
  • Loading branch information
coelckers committed Aug 20, 2018
1 parent 2d67206 commit eac7f7a
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 20 deletions.
7 changes: 5 additions & 2 deletions src/gl/renderer/gl_renderer.cpp
Expand Up @@ -178,8 +178,11 @@ void FGLRenderer::SetupLevel()

for (auto &sec : level.sectors)
{
sec.planes[sector_t::floor].ubIndexMatrix = tmindex--;
sec.planes[sector_t::ceiling].ubIndexMatrix = tmindex--;
sec.ubIndexMatrix[sector_t::floor] = tmindex--;
sec.ubIndexMatrix[sector_t::ceiling] = tmindex--;

sec.planes[sector_t::floor].pUbIndexMatrix = &sec.ubIndexMatrix[sector_t::floor];
sec.planes[sector_t::ceiling].pUbIndexMatrix = &sec.ubIndexMatrix[sector_t::ceiling];
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/gl/scene/gl_flats.cpp
Expand Up @@ -210,6 +210,10 @@ void FDrawInfo::DrawFlat(GLFlat *flat, int pass, bool trans) // trans only has m
gl_RenderState.SetNormal(plane.plane.Normal().X, plane.plane.Normal().Z, plane.plane.Normal().Y);
GLRenderer->mModelMatrix->Bind(0);

if (flat->sector->sectornum == 546)
{
int a = 0;
}
switch (pass)
{
case GLPASS_ALL: // Single-pass rendering
Expand All @@ -219,7 +223,7 @@ void FDrawInfo::DrawFlat(GLFlat *flat, int pass, bool trans) // trans only has m
gl_RenderState.SetObjectColor(flat->FlatColor | 0xff000000);
if (flat->sector->special != GLSector_Skybox)
{
gl_RenderState.SetTexMatrixIndex(flat->plane.ubIndexMatrix);
gl_RenderState.SetTexMatrixIndex(*flat->plane.pUbIndexMatrix);
gl_RenderState.SetMaterial(flat->gltexture, CLAMP_NONE, 0, -1, false);
DrawSubsectors(flat, pass, false);
}
Expand Down Expand Up @@ -251,7 +255,7 @@ void FDrawInfo::DrawFlat(GLFlat *flat, int pass, bool trans) // trans only has m
{
if (!flat->gltexture->tex->GetTranslucency()) gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_threshold);
else gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f);
gl_RenderState.SetTexMatrixIndex(flat->plane.ubIndexMatrix);
gl_RenderState.SetTexMatrixIndex(*flat->plane.pUbIndexMatrix);
gl_RenderState.SetMaterial(flat->gltexture, CLAMP_NONE, 0, -1, false);
DrawSubsectors(flat, pass, true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/gl/scene/gl_portal.cpp
Expand Up @@ -428,7 +428,7 @@ void GLHorizonPortal::DrawContents(HWDrawInfo *hwdi)
gl_RenderState.SetMaterial(gltexture, CLAMP_NONE, 0, -1, false);
gl_RenderState.SetObjectColor(origin->specialcolor);

gl_RenderState.SetTexMatrixIndex(sp->ubIndexMatrix);
gl_RenderState.SetTexMatrixIndex(*sp->pUbIndexMatrix);
gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f);
gl_RenderState.BlendFunc(GL_ONE,GL_ZERO);
gl_RenderState.Apply();
Expand Down
4 changes: 0 additions & 4 deletions src/hwrenderer/scene/hw_bsp.cpp
Expand Up @@ -454,10 +454,6 @@ void HWDrawInfo::DoSubsector(subsector_t * sub)

if (sector->validcount != validcount)
{
if (sector->Index() == 62)
{
int a = 0;
}
mVBO->CheckUpdate(sector);
}

Expand Down
4 changes: 2 additions & 2 deletions src/hwrenderer/scene/hw_drawstructs.h
Expand Up @@ -74,7 +74,7 @@ struct GLSectorPlane
float Angle;
FVector2 Offs;
FVector2 Scale;
int ubIndexMatrix;
int *pUbIndexMatrix;

void GetFromSector(sector_t * sec, int ceiling)
{
Expand All @@ -86,7 +86,7 @@ struct GLSectorPlane
texture = sec->GetTexture(ceiling);
plane = sec->GetSecPlane(ceiling);
Texheight = (float)((ceiling == sector_t::ceiling)? plane.fD() : -plane.fD());
ubIndexMatrix = sec->planes[ceiling].ubIndexMatrix;
pUbIndexMatrix = sec->planes[ceiling].pUbIndexMatrix;
}
};

Expand Down
1 change: 0 additions & 1 deletion src/hwrenderer/scene/hw_fakeflat.cpp
Expand Up @@ -191,7 +191,6 @@ area_t hw_CheckViewArea(vertex_t *v1, vertex_t *v2, sector_t *frontsector, secto
//==========================================================================
sector_t * hw_FakeFlat(sector_t * sec, sector_t * dest, area_t in_area, bool back)
{
return sec;
if (!sec->GetHeightSec() || sec->heightsec==sec)
{
// check for backsectors with the ceiling lower than the floor. These will create
Expand Down
8 changes: 4 additions & 4 deletions src/hwrenderer/scene/hw_flats.cpp
Expand Up @@ -223,15 +223,15 @@ void GLFlat::Process(HWDrawInfo *di, sector_t * model, int whichplane, bool fog)
lightlevel=255;
}

if (plane.ubIndexMatrix < 0)
auto &ndx = *plane.pUbIndexMatrix;
if (ndx < 0)
{
// Need to recalculate the texture matrix.
// (Note that theoretically two threads can do this at the same time, but since they'd create the same data this isn't critical.)
VSMatrix mat;
plane.ubIndexMatrix = -plane.ubIndexMatrix;
model->planes[whichplane].ubIndexMatrix = plane.ubIndexMatrix;
ndx = -ndx;
hw_SetPlaneTextureRotation(&plane, gltexture, mat);
di->UploadTextureMatrix(mat, plane.ubIndexMatrix);
di->UploadTextureMatrix(mat, ndx);
}
}
else
Expand Down
10 changes: 6 additions & 4 deletions src/r_defs.h
Expand Up @@ -692,16 +692,18 @@ struct sector_t
PalEntry GlowColor;
float GlowHeight;
FTextureID Texture;
int ubIndexPlane; // index in uniform buffer for plane data
int ubIndexMatrix; // index in uniform buffer for texture matrix data
int *pUbIndexMatrix; // tracked by address so that copies can reach the real variable when updating.
};

splane planes[2];

//int ubIndexPlane; // index in uniform buffer for plane data
int ubIndexMatrix[2]; // index in uniform buffer for texture matrix data

void InvalidateMatrix(int pos)
{
// negate the buffer index to mark it as invalid.
auto & p = planes[pos].ubIndexMatrix;
auto & p = ubIndexMatrix[pos];
if (p > 0) p = -p;
}

Expand Down Expand Up @@ -935,7 +937,7 @@ struct sector_t
void CopyTextureInfo(int pos, sector_t *src, int srcpos)
{
planes[pos].xform = src->planes[srcpos].xform;
planes[pos].ubIndexMatrix = src->planes[srcpos].ubIndexMatrix;
planes[pos].pUbIndexMatrix = src->planes[srcpos].pUbIndexMatrix;
planes[pos].Texture = src->planes[srcpos].Texture;
}

Expand Down

0 comments on commit eac7f7a

Please sign in to comment.