From c5641a0e729b21b4084380a8d8af116d22767ee8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 28 Apr 2018 12:34:09 +0200 Subject: [PATCH] - GLFlat split into API-dependent and -independent data. No resorting of the files yet. --- src/gl/compatibility/gl_20.cpp | 40 ++--- src/gl/renderer/gl_renderstate.h | 11 ++ src/gl/scene/gl_bsp.cpp | 4 +- src/gl/scene/gl_drawinfo.cpp | 6 +- src/gl/scene/gl_drawinfo.h | 13 +- src/gl/scene/gl_flats.cpp | 225 ++++++++++++++------------ src/gl/scene/gl_portal.cpp | 2 +- src/gl/scene/gl_skydome.cpp | 1 + src/gl/scene/gl_wall.h | 67 -------- src/hwrenderer/scene/hw_drawinfo.h | 3 + src/hwrenderer/scene/hw_drawstructs.h | 56 +++++++ src/hwrenderer/scene/hw_skydome.cpp | 2 - src/hwrenderer/scene/hw_walls.cpp | 1 + src/polyrenderer/scene/poly_sky.cpp | 4 +- src/r_sky.cpp | 3 + 15 files changed, 236 insertions(+), 202 deletions(-) diff --git a/src/gl/compatibility/gl_20.cpp b/src/gl/compatibility/gl_20.cpp index 1c99b1825c..69c714db87 100644 --- a/src/gl/compatibility/gl_20.cpp +++ b/src/gl/compatibility/gl_20.cpp @@ -566,21 +566,21 @@ bool FDrawInfo::PutWallCompat(GLWall *wall, int passflag) // //========================================================================== -bool GLFlat::PutFlatCompat(bool fog) +bool FDrawInfo::PutFlatCompat(GLFlat *flat, bool fog) { // are lights possible? - if (mDrawer->FixedColormap != CM_DEFAULT || !gl_lights || !gltexture || renderstyle != STYLE_Translucent || alpha < 1.f - FLT_EPSILON || sector->lighthead == NULL) return false; + if (FixedColormap != CM_DEFAULT || !gl_lights || !flat->gltexture || flat->renderstyle != STYLE_Translucent || flat->alpha < 1.f - FLT_EPSILON || flat->sector->lighthead == NULL) return false; static int list_indices[2][2] = { { GLLDL_FLATS_PLAIN, GLLDL_FLATS_FOG },{ GLLDL_FLATS_MASKED, GLLDL_FLATS_FOGMASKED } }; - bool masked = gltexture->isMasked() && ((renderflags&SSRF_RENDER3DPLANES) || stack); - bool foggy = CheckFog(&Colormap, lightlevel) || (level.flags&LEVEL_HASFADETABLE) || gl_lights_additive; + bool masked = flat->gltexture->isMasked() && ((flat->renderflags&SSRF_RENDER3DPLANES) || flat->stack); + bool foggy = CheckFog(&flat->Colormap, flat->lightlevel) || (level.flags&LEVEL_HASFADETABLE) || gl_lights_additive; int list = list_indices[masked][foggy]; auto newflat = gl_drawinfo->dldrawlists[list].NewFlat(); - *newflat = *this; + *newflat = *flat; return true; } @@ -645,7 +645,7 @@ void FDrawInfo::RenderFogBoundaryCompat(GLWall *wall) // //========================================================================== -void GLFlat::DrawSubsectorLights(subsector_t * sub, int pass) +void FDrawInfo::DrawSubsectorLights(GLFlat *flat, subsector_t * sub, int pass) { Plane p; FVector3 nearPt, up, right, t1; @@ -666,14 +666,14 @@ void GLFlat::DrawSubsectorLights(subsector_t * sub, int pass) // we must do the side check here because gl_SetupLight needs the correct plane orientation // which we don't have for Legacy-style 3D-floors - double planeh = plane.plane.ZatPoint(light); - if (((planehZ() && ceiling) || (planeh>light->Z() && !ceiling))) + double planeh = flat->plane.plane.ZatPoint(light); + if (((planehZ() && flat->ceiling) || (planeh>light->Z() && !flat->ceiling))) { node = node->nextLight; continue; } - p.Set(plane.plane.Normal(), plane.plane.fD()); + p.Set(flat->plane.plane.Normal(), flat->plane.plane.fD()); if (!gl_SetupLight(sub->sector->PortalGroup, p, light, nearPt, up, right, scale, false, pass != GLPASS_LIGHTTEX)) { node = node->nextLight; @@ -686,7 +686,7 @@ void GLFlat::DrawSubsectorLights(subsector_t * sub, int pass) { vertex_t *vt = sub->firstline[k].v1; ptr->x = vt->fX(); - ptr->z = plane.plane.ZatPoint(vt) + dz; + ptr->z = flat->plane.plane.ZatPoint(vt) + flat->dz; ptr->y = vt->fY(); t1 = { ptr->x, ptr->z, ptr->y }; FVector3 nearToVert = t1 - nearPt; @@ -706,29 +706,29 @@ void GLFlat::DrawSubsectorLights(subsector_t * sub, int pass) // //========================================================================== -void GLFlat::DrawLightsCompat(int pass) +void FDrawInfo::DrawLightsCompat(GLFlat *flat, int pass) { gl_RenderState.Apply(); // Draw the subsectors belonging to this sector - for (int i = 0; isubsectorcount; i++) + for (int i = 0; isector->subsectorcount; i++) { - subsector_t * sub = sector->subsectors[i]; - if (gl_drawinfo->ss_renderflags[sub->Index()] & renderflags) + subsector_t * sub = flat->sector->subsectors[i]; + if (gl_drawinfo->ss_renderflags[sub->Index()] & flat->renderflags) { - DrawSubsectorLights(sub, pass); + DrawSubsectorLights(flat, sub, pass); } } // Draw the subsectors assigned to it due to missing textures - if (!(renderflags&SSRF_RENDER3DPLANES)) + if (!(flat->renderflags&SSRF_RENDER3DPLANES)) { - gl_subsectorrendernode * node = (renderflags&SSRF_RENDERFLOOR) ? - gl_drawinfo->GetOtherFloorPlanes(sector->sectornum) : - gl_drawinfo->GetOtherCeilingPlanes(sector->sectornum); + gl_subsectorrendernode * node = (flat->renderflags&SSRF_RENDERFLOOR) ? + gl_drawinfo->GetOtherFloorPlanes(flat->sector->sectornum) : + gl_drawinfo->GetOtherCeilingPlanes(flat->sector->sectornum); while (node) { - DrawSubsectorLights(node->sub, pass); + DrawSubsectorLights(flat, node->sub, pass); node = node->next; } } diff --git a/src/gl/renderer/gl_renderstate.h b/src/gl/renderer/gl_renderstate.h index b4cdff48aa..7444e849ec 100644 --- a/src/gl/renderer/gl_renderstate.h +++ b/src/gl/renderer/gl_renderstate.h @@ -26,6 +26,7 @@ #include #include "gl/system/gl_interface.h" #include "r_data/matrix.h" +#include "hwrenderer/scene//hw_drawstructs.h" #include "hwrenderer/textures/hw_material.h" #include "c_cvars.h" #include "r_defs.h" @@ -34,6 +35,7 @@ class FVertexBuffer; class FShader; +struct GLSectorPlane; extern TArray gl_MatrixStack; EXTERN_CVAR(Bool, gl_direct_state_change) @@ -530,6 +532,15 @@ public: // Backwards compatibility crap follows void ApplyFixedFunction(); void DrawColormapOverlay(); + + void SetPlaneTextureRotation(GLSectorPlane *plane, FMaterial *texture) + { + if (gl_SetPlaneTextureRotation(plane, texture, mTextureMatrix)) + { + EnableTextureMatrix(true); + } + } + }; extern FRenderState gl_RenderState; diff --git a/src/gl/scene/gl_bsp.cpp b/src/gl/scene/gl_bsp.cpp index c250f607c4..8e6f8b2405 100644 --- a/src/gl/scene/gl_bsp.cpp +++ b/src/gl/scene/gl_bsp.cpp @@ -504,8 +504,8 @@ void GLSceneDrawer::DoSubsector(subsector_t * sub) srf |= SSRF_PROCESSED; SetupFlat.Clock(); - GLFlat flat(this); - flat.ProcessSector(fakesector); + GLFlat flat; + flat.ProcessSector(gl_drawinfo, fakesector); SetupFlat.Unclock(); } // mark subsector as processed - but mark for rendering only if it has an actual area. diff --git a/src/gl/scene/gl_drawinfo.cpp b/src/gl/scene/gl_drawinfo.cpp index 8e04f7d8f2..c91bcdaf87 100644 --- a/src/gl/scene/gl_drawinfo.cpp +++ b/src/gl/scene/gl_drawinfo.cpp @@ -708,7 +708,7 @@ void GLDrawList::DoDraw(int pass, int i, bool trans) { GLFlat * f= flats[drawitems[i].index]; RenderFlat.Clock(); - f->Draw(pass, trans); + gl_drawinfo->DrawFlat(f, pass, trans); RenderFlat.Unclock(); } break; @@ -862,7 +862,7 @@ void GLDrawList::DrawFlats(int pass) RenderFlat.Clock(); for(unsigned i=0;iDraw(pass, false); + gl_drawinfo->DrawFlat(flats[drawitems[i].index], pass, false); } RenderFlat.Unclock(); } @@ -1154,7 +1154,7 @@ void FDrawInfo::DrawFloodedPlane(wallseg * ws, float planez, sector_t * sec, boo float fviewy = r_viewpoint.Pos.Y; float fviewz = r_viewpoint.Pos.Z; - gl_SetPlaneTextureRotation(&plane, gltexture); + gl_RenderState.SetPlaneTextureRotation(&plane, gltexture); gl_RenderState.Apply(); float prj_fac1 = (planez-fviewz)/(ws->z1-fviewz); diff --git a/src/gl/scene/gl_drawinfo.h b/src/gl/scene/gl_drawinfo.h index 32003d9739..0983825e6f 100644 --- a/src/gl/scene/gl_drawinfo.h +++ b/src/gl/scene/gl_drawinfo.h @@ -181,14 +181,19 @@ struct FDrawInfo : public HWDrawInfo void AddMirrorSurface(GLWall *w) override; GLDecal *AddDecal(bool onmirror) override; void AddPortal(GLWall *w, int portaltype) override; + void AddFlat(GLFlat *flat, bool fog) override; void ProcessActorsInPortal(FLinePortalSpan *glport) override; std::pair AllocVertices(unsigned int count) override; // Legacy GL only. bool PutWallCompat(GLWall *wall, int passflag); + bool PutFlatCompat(GLFlat *flat, bool fog); void RenderFogBoundaryCompat(GLWall *wall); void RenderLightsCompat(GLWall *wall, int pass); + void DrawSubsectorLights(GLFlat *flat, subsector_t * sub, int pass); + void DrawLightsCompat(GLFlat *flat, int pass); + void DrawDecal(GLDecal *gldecal); void DrawDecals(); @@ -209,6 +214,13 @@ struct FDrawInfo : public HWDrawInfo void RenderTexturedWall(GLWall *wall, int rflags); void DrawWall(GLWall *wall, int pass); + // Flat drawer + void DrawFlat(GLFlat *flat, int pass, bool trans); // trans only has meaning for GLPASS_LIGHTSONLY + void DrawSkyboxSector(GLFlat *flat, int pass, bool processlights); + void DrawSubsectors(GLFlat *flat, int pass, bool processlights, bool istrans); + void ProcessLights(GLFlat *flat, bool istrans); + void DrawSubsector(GLFlat *flat, subsector_t * sub); + // These two may be moved to the API independent part of the renderer later. void ProcessLowerMinisegs(TArray &lowersegs) override; @@ -243,7 +255,6 @@ public: extern FDrawInfo * gl_drawinfo; -void gl_SetPlaneTextureRotation(const GLSectorPlane * secplane, FMaterial * gltexture); void gl_SetRenderStyle(FRenderStyle style, bool drawopaque, bool allowcolorblending); #endif diff --git a/src/gl/scene/gl_flats.cpp b/src/gl/scene/gl_flats.cpp index b4c73ae168..d9c080d155 100644 --- a/src/gl/scene/gl_flats.cpp +++ b/src/gl/scene/gl_flats.cpp @@ -58,7 +58,7 @@ CVAR(Int, gl_breaksec, -1, 0) // //========================================================================== -void gl_SetPlaneTextureRotation(const GLSectorPlane * secplane, FMaterial * gltexture) +bool gl_SetPlaneTextureRotation(const GLSectorPlane * secplane, FMaterial * gltexture, VSMatrix &dest) { // only manipulate the texture matrix if needed. if (!secplane->Offs.isZero() || @@ -81,13 +81,14 @@ void gl_SetPlaneTextureRotation(const GLSectorPlane * secplane, FMaterial * glte float xscale2 = 64.f / gltexture->TextureWidth(); float yscale2 = 64.f / gltexture->TextureHeight(); - gl_RenderState.mTextureMatrix.loadIdentity(); - gl_RenderState.mTextureMatrix.scale(xscale1, yscale1, 1.0f); - gl_RenderState.mTextureMatrix.translate(uoffs, voffs, 0.0f); - gl_RenderState.mTextureMatrix.scale(xscale2, yscale2, 1.0f); - gl_RenderState.mTextureMatrix.rotate(angle, 0.0f, 0.0f, 1.0f); - gl_RenderState.EnableTextureMatrix(true); + dest.loadIdentity(); + dest.scale(xscale1, yscale1, 1.0f); + dest.translate(uoffs, voffs, 0.0f); + dest.scale(xscale2, yscale2, 1.0f); + dest.rotate(angle, 0.0f, 0.0f, 1.0f); + return true; } + return false; } @@ -156,7 +157,7 @@ void GLFlat::SetupSubsectorLights(int pass, subsector_t * sub, int *dli) // //========================================================================== -void GLFlat::DrawSubsector(subsector_t * sub) +void FDrawInfo::DrawSubsector(GLFlat *flat, subsector_t * sub) { if (gl.buffermethod != BM_DEFERRED) { @@ -165,7 +166,7 @@ void GLFlat::DrawSubsector(subsector_t * sub) { vertex_t *vt = sub->firstline[k].v1; ptr->x = vt->fX(); - ptr->z = plane.plane.ZatPoint(vt) + dz; + ptr->z = flat->plane.plane.ZatPoint(vt) + flat->dz; ptr->y = vt->fY(); ptr->u = vt->fX() / 64.f; ptr->v = -vt->fY() / 64.f; @@ -190,7 +191,7 @@ void GLFlat::DrawSubsector(subsector_t * sub) for (unsigned int x = 0; x < 4; x++) { vertex_t *vt = sub->firstline[vi[x]].v1; - qd.Set(x, vt->fX(), plane.plane.ZatPoint(vt) + dz, vt->fY(), vt->fX() / 64.f, -vt->fY() / 64.f); + qd.Set(x, vt->fX(), flat->plane.plane.ZatPoint(vt) + flat->dz, vt->fY(), vt->fX() / 64.f, -vt->fY() / 64.f); } qd.Render(GL_TRIANGLE_FAN); } @@ -207,30 +208,30 @@ void GLFlat::DrawSubsector(subsector_t * sub) // //========================================================================== -void GLFlat::ProcessLights(bool istrans) +void FDrawInfo::ProcessLights(GLFlat *flat, bool istrans) { - dynlightindex = GLRenderer->mLights->GetIndexPtr(); + flat->dynlightindex = GLRenderer->mLights->GetIndexPtr(); // Draw the subsectors belonging to this sector - for (int i=0; isubsectorcount; i++) + for (int i=0; i< flat->sector->subsectorcount; i++) { - subsector_t * sub = sector->subsectors[i]; - if (gl_drawinfo->ss_renderflags[sub->Index()]&renderflags || istrans) + subsector_t * sub = flat->sector->subsectors[i]; + if (gl_drawinfo->ss_renderflags[sub->Index()]& flat->renderflags || istrans) { - SetupSubsectorLights(GLPASS_LIGHTSONLY, sub); + flat->SetupSubsectorLights(GLPASS_LIGHTSONLY, sub); } } // Draw the subsectors assigned to it due to missing textures - if (!(renderflags&SSRF_RENDER3DPLANES)) + if (!(flat->renderflags&SSRF_RENDER3DPLANES)) { - gl_subsectorrendernode * node = (renderflags&SSRF_RENDERFLOOR)? - gl_drawinfo->GetOtherFloorPlanes(sector->sectornum) : - gl_drawinfo->GetOtherCeilingPlanes(sector->sectornum); + gl_subsectorrendernode * node = (flat->renderflags&SSRF_RENDERFLOOR)? + gl_drawinfo->GetOtherFloorPlanes(flat->sector->sectornum) : + gl_drawinfo->GetOtherCeilingPlanes(flat->sector->sectornum); while (node) { - SetupSubsectorLights(GLPASS_LIGHTSONLY, node->sub); + flat->SetupSubsectorLights(GLPASS_LIGHTSONLY, node->sub); node = node->next; } } @@ -243,21 +244,21 @@ void GLFlat::ProcessLights(bool istrans) // //========================================================================== -void GLFlat::DrawSubsectors(int pass, bool processlights, bool istrans) +void FDrawInfo::DrawSubsectors(GLFlat *flat, int pass, bool processlights, bool istrans) { - int dli = dynlightindex; + int dli = flat->dynlightindex; gl_RenderState.Apply(); - if (vboindex >= 0) + if (flat->vboindex >= 0) { - int index = vboindex; - for (int i=0; isubsectorcount; i++) + int index = flat->vboindex; + for (int i=0; isector->subsectorcount; i++) { - subsector_t * sub = sector->subsectors[i]; + subsector_t * sub = flat->sector->subsectors[i]; - if (gl_drawinfo->ss_renderflags[sub->Index()]&renderflags || istrans) + if (gl_drawinfo->ss_renderflags[sub->Index()]& flat->renderflags || istrans) { - if (processlights) SetupSubsectorLights(GLPASS_ALL, sub, &dli); + if (processlights) flat->SetupSubsectorLights(GLPASS_ALL, sub, &dli); drawcalls.Clock(); glDrawArrays(GL_TRIANGLE_FAN, index, sub->numlines); drawcalls.Unclock(); @@ -271,28 +272,28 @@ void GLFlat::DrawSubsectors(int pass, bool processlights, bool istrans) { // Draw the subsectors belonging to this sector // (can this case even happen?) - for (int i=0; isubsectorcount; i++) + for (int i=0; isector->subsectorcount; i++) { - subsector_t * sub = sector->subsectors[i]; - if (gl_drawinfo->ss_renderflags[sub->Index()]&renderflags || istrans) + subsector_t * sub = flat->sector->subsectors[i]; + if (gl_drawinfo->ss_renderflags[sub->Index()]& flat->renderflags || istrans) { - if (processlights) SetupSubsectorLights(GLPASS_ALL, sub, &dli); - DrawSubsector(sub); + if (processlights) flat->SetupSubsectorLights(GLPASS_ALL, sub, &dli); + DrawSubsector(flat, sub); } } } // Draw the subsectors assigned to it due to missing textures - if (!(renderflags&SSRF_RENDER3DPLANES)) + if (!(flat->renderflags&SSRF_RENDER3DPLANES)) { - gl_subsectorrendernode * node = (renderflags&SSRF_RENDERFLOOR)? - gl_drawinfo->GetOtherFloorPlanes(sector->sectornum) : - gl_drawinfo->GetOtherCeilingPlanes(sector->sectornum); + gl_subsectorrendernode * node = (flat->renderflags&SSRF_RENDERFLOOR)? + gl_drawinfo->GetOtherFloorPlanes(flat->sector->sectornum) : + gl_drawinfo->GetOtherCeilingPlanes(flat->sector->sectornum); while (node) { - if (processlights) SetupSubsectorLights(GLPASS_ALL, node->sub, &dli); - DrawSubsector(node->sub); + if (processlights) flat->SetupSubsectorLights(GLPASS_ALL, node->sub, &dli); + DrawSubsector(flat, node->sub); node = node->next; } } @@ -308,13 +309,13 @@ void GLFlat::DrawSubsectors(int pass, bool processlights, bool istrans) // //========================================================================== -void GLFlat::DrawSkyboxSector(int pass, bool processlights) +void FDrawInfo::DrawSkyboxSector(GLFlat *flat, int pass, bool processlights) { float minx = FLT_MAX, miny = FLT_MAX; float maxx = -FLT_MAX, maxy = -FLT_MAX; - for (auto ln : sector->Lines) + for (auto ln : flat->sector->Lines) { float x = ln->v1->fX(); float y = ln->v1->fY(); @@ -330,10 +331,10 @@ void GLFlat::DrawSkyboxSector(int pass, bool processlights) if (y > maxy) maxy = y; } - float z = plane.plane.ZatPoint(0., 0.) + dz; + float z = flat->plane.plane.ZatPoint(0., 0.) + flat->dz; static float uvals[] = { 0, 0, 1, 1 }; static float vvals[] = { 1, 0, 0, 1 }; - int rot = -xs_FloorToInt(plane.Angle / 90.f); + int rot = -xs_FloorToInt(flat->plane.Angle / 90.f); FQuadDrawer qd; @@ -353,7 +354,7 @@ void GLFlat::DrawSkyboxSector(int pass, bool processlights) // // //========================================================================== -void GLFlat::Draw(int pass, bool trans) // trans only has meaning for GLPASS_LIGHTSONLY +void FDrawInfo::DrawFlat(GLFlat *flat, int pass, bool trans) // trans only has meaning for GLPASS_LIGHTSONLY { int rel = getExtraLight(); @@ -364,128 +365,142 @@ void GLFlat::Draw(int pass, bool trans) // trans only has meaning for GLPASS_LIG } #endif + auto &plane = flat->plane; gl_RenderState.SetNormal(plane.plane.Normal().X, plane.plane.Normal().Z, plane.plane.Normal().Y); switch (pass) { case GLPASS_PLAIN: // Single-pass rendering case GLPASS_ALL: // Same, but also creates the dynlight data. - mDrawer->SetColor(lightlevel, rel, Colormap,1.0f); - mDrawer->SetFog(lightlevel, rel, &Colormap, false); - if (!gltexture->tex->isFullbright()) - gl_RenderState.SetObjectColor(FlatColor | 0xff000000); - if (sector->special != GLSector_Skybox) + mDrawer->SetColor(flat->lightlevel, rel, flat->Colormap,1.0f); + mDrawer->SetFog(flat->lightlevel, rel, &flat->Colormap, false); + if (!flat->gltexture->tex->isFullbright()) + gl_RenderState.SetObjectColor(flat->FlatColor | 0xff000000); + if (flat->sector->special != GLSector_Skybox) { - gl_RenderState.SetMaterial(gltexture, CLAMP_NONE, 0, -1, false); - gl_SetPlaneTextureRotation(&plane, gltexture); - DrawSubsectors(pass, (pass == GLPASS_ALL || dynlightindex > -1), false); + gl_RenderState.SetMaterial(flat->gltexture, CLAMP_NONE, 0, -1, false); + gl_RenderState.SetPlaneTextureRotation(&plane, flat->gltexture); + DrawSubsectors(flat, pass, (pass == GLPASS_ALL || flat->dynlightindex > -1), false); gl_RenderState.EnableTextureMatrix(false); } else { - gl_RenderState.SetMaterial(gltexture, CLAMP_XY, 0, -1, false); - DrawSkyboxSector(pass, (pass == GLPASS_ALL || dynlightindex > -1)); + gl_RenderState.SetMaterial(flat->gltexture, CLAMP_XY, 0, -1, false); + DrawSkyboxSector(flat, pass, (pass == GLPASS_ALL || flat->dynlightindex > -1)); } gl_RenderState.SetObjectColor(0xffffffff); break; case GLPASS_LIGHTSONLY: - if (!trans || gltexture) + if (!trans || flat->gltexture) { - ProcessLights(trans); + ProcessLights(flat, trans); } break; case GLPASS_TRANSLUCENT: - if (renderstyle==STYLE_Add) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE); - mDrawer->SetColor(lightlevel, rel, Colormap, alpha); - mDrawer->SetFog(lightlevel, rel, &Colormap, false); - if (!gltexture || !gltexture->tex->isFullbright()) - gl_RenderState.SetObjectColor(FlatColor | 0xff000000); - if (!gltexture) + if (flat->renderstyle==STYLE_Add) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE); + mDrawer->SetColor(flat->lightlevel, rel, flat->Colormap, flat->alpha); + mDrawer->SetFog(flat->lightlevel, rel, &flat->Colormap, false); + if (!flat->gltexture || !flat->gltexture->tex->isFullbright()) + gl_RenderState.SetObjectColor(flat->FlatColor | 0xff000000); + if (!flat->gltexture) { gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); gl_RenderState.EnableTexture(false); - DrawSubsectors(pass, false, true); + DrawSubsectors(flat, pass, false, true); gl_RenderState.EnableTexture(true); } else { - if (!gltexture->tex->GetTranslucency()) gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_threshold); + if (!flat->gltexture->tex->GetTranslucency()) gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_threshold); else gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); - gl_RenderState.SetMaterial(gltexture, CLAMP_NONE, 0, -1, false); - gl_SetPlaneTextureRotation(&plane, gltexture); - DrawSubsectors(pass, !gl.legacyMode && (gl.lightmethod == LM_DIRECT || dynlightindex > -1), true); + gl_RenderState.SetMaterial(flat->gltexture, CLAMP_NONE, 0, -1, false); + gl_RenderState.SetPlaneTextureRotation(&plane, flat->gltexture); + DrawSubsectors(flat, pass, !gl.legacyMode && (gl.lightmethod == LM_DIRECT || flat->dynlightindex > -1), true); gl_RenderState.EnableTextureMatrix(false); } - if (renderstyle==STYLE_Add) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + if (flat->renderstyle==STYLE_Add) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); gl_RenderState.SetObjectColor(0xffffffff); break; case GLPASS_LIGHTTEX: case GLPASS_LIGHTTEX_ADDITIVE: case GLPASS_LIGHTTEX_FOGGY: - DrawLightsCompat(pass); + DrawLightsCompat(flat, pass); break; case GLPASS_TEXONLY: - gl_RenderState.SetMaterial(gltexture, CLAMP_NONE, 0, -1, false); - gl_SetPlaneTextureRotation(&plane, gltexture); - DrawSubsectors(pass, false, false); + gl_RenderState.SetMaterial(flat->gltexture, CLAMP_NONE, 0, -1, false); + gl_RenderState.SetPlaneTextureRotation(&plane, flat->gltexture); + DrawSubsectors(flat, pass, false, false); gl_RenderState.EnableTextureMatrix(false); break; } } - //========================================================================== // -// GLFlat::PutFlat +// FDrawInfo::AddFlat // // Checks texture, lighting and translucency settings and puts this // plane in the appropriate render list. // //========================================================================== -inline void GLFlat::PutFlat(bool fog) + +void FDrawInfo::AddFlat(GLFlat *flat, bool fog) { int list; - if (mDrawer->FixedColormap) - { - Colormap.Clear(); - } if (gl.legacyMode) { - if (PutFlatCompat(fog)) return; + if (PutFlatCompat(flat, fog)) return; } - if (renderstyle!=STYLE_Translucent || alpha < 1.f - FLT_EPSILON || fog || gltexture == NULL) + if (flat->renderstyle != STYLE_Translucent || flat->alpha < 1.f - FLT_EPSILON || fog || flat->gltexture == nullptr) { // translucent 3D floors go into the regular translucent list, translucent portals go into the translucent border list. - list = (renderflags&SSRF_RENDER3DPLANES) ? GLDL_TRANSLUCENT : GLDL_TRANSLUCENTBORDER; + list = (flat->renderflags&SSRF_RENDER3DPLANES) ? GLDL_TRANSLUCENT : GLDL_TRANSLUCENTBORDER; } - else if (gltexture->tex->GetTranslucency()) + else if (flat->gltexture->tex->GetTranslucency()) { - if (stack) + if (flat->stack) { list = GLDL_TRANSLUCENTBORDER; } - else if ((renderflags&SSRF_RENDER3DPLANES) && !plane.plane.isSlope()) + else if ((flat->renderflags&SSRF_RENDER3DPLANES) && !flat->plane.plane.isSlope()) { list = GLDL_TRANSLUCENT; - } - else + } + else { list = GLDL_PLAINFLATS; } } else { - bool masked = gltexture->isMasked() && ((renderflags&SSRF_RENDER3DPLANES) || stack); + bool masked = flat->gltexture->isMasked() && ((flat->renderflags&SSRF_RENDER3DPLANES) || flat->stack); list = masked ? GLDL_MASKEDFLATS : GLDL_PLAINFLATS; } - dynlightindex = -1; // make sure this is always initialized to something proper. auto newflat = gl_drawinfo->drawlists[list].NewFlat(); - *newflat = *this; + *newflat = *flat; +} + +//========================================================================== +// +// GLFlat::PutFlat +// +// submit to the renderer +// +//========================================================================== + +inline void GLFlat::PutFlat(HWDrawInfo *di, bool fog) +{ + if (di->FixedColormap) + { + Colormap.Clear(); + } + dynlightindex = -1; // make sure this is always initialized to something proper. + di->AddFlat(this, fog); } //========================================================================== @@ -497,7 +512,7 @@ inline void GLFlat::PutFlat(bool fog) // //========================================================================== -void GLFlat::Process(sector_t * model, int whichplane, bool fog) +void GLFlat::Process(HWDrawInfo *di, sector_t * model, int whichplane, bool fog) { plane.GetFromSector(model, whichplane); if (whichplane != int(ceiling)) @@ -528,7 +543,7 @@ void GLFlat::Process(sector_t * model, int whichplane, bool fog) z = plane.plane.ZatPoint(0.f, 0.f); - PutFlat(fog); + PutFlat(di, fog); rendered_flats++; } @@ -578,7 +593,7 @@ void GLFlat::SetFrom3DFloor(F3DFloor *rover, bool top, bool underside) // //========================================================================== -void GLFlat::ProcessSector(sector_t * frontsector) +void GLFlat::ProcessSector(HWDrawInfo *di, sector_t * frontsector) { lightlist_t * light; FSectorPortal *port; @@ -595,7 +610,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) extsector_t::xfloor &x = sector->e->XFloor; dynlightindex = -1; - uint8_t &srf = gl_drawinfo->sectorrenderflags[sector->sectornum]; + uint8_t &srf = di->sectorrenderflags[sector->sectornum]; // // @@ -618,7 +633,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) { if (port->mType == PORTS_STACKEDSECTORTHING) { - gl_drawinfo->AddFloorStack(sector); // stacked sector things require visplane merging. + di->AddFloorStack(sector); // stacked sector things require visplane merging. } alpha = frontsector->GetAlpha(sector_t::floor); } @@ -653,7 +668,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) Colormap.CopyFrom3DLight(light); } renderstyle = STYLE_Translucent; - Process(frontsector, sector_t::floor, false); + Process(di, frontsector, sector_t::floor, false); } } @@ -678,7 +693,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) { if (port->mType == PORTS_STACKEDSECTORTHING) { - gl_drawinfo->AddCeilingStack(sector); + di->AddCeilingStack(sector); } alpha = frontsector->GetAlpha(sector_t::ceiling); } @@ -713,7 +728,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) Colormap.CopyFrom3DLight(light); } renderstyle = STYLE_Translucent; - Process(frontsector, sector_t::ceiling, false); + Process(di, frontsector, sector_t::ceiling, false); } } @@ -749,7 +764,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) if ((rover->flags&(FF_EXISTS | FF_RENDERPLANES | FF_THISINSIDE)) == (FF_EXISTS | FF_RENDERPLANES)) { - if (rover->flags&FF_FOG && mDrawer->FixedColormap) continue; + if (rover->flags&FF_FOG && di->FixedColormap) continue; if (!rover->top.copied && rover->flags&(FF_INVERTPLANES | FF_BOTHPLANES)) { double ff_top = rover->top.plane->ZatPoint(sector->centerspot); @@ -759,7 +774,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) { SetFrom3DFloor(rover, true, !!(rover->flags&FF_FOG)); Colormap.FadeColor = frontsector->Colormap.FadeColor; - Process(rover->top.model, rover->top.isceiling, !!(rover->flags&FF_FOG)); + Process(di, rover->top.model, rover->top.isceiling, !!(rover->flags&FF_FOG)); } lastceilingheight = ff_top; } @@ -773,7 +788,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) { SetFrom3DFloor(rover, false, !(rover->flags&FF_FOG)); Colormap.FadeColor = frontsector->Colormap.FadeColor; - Process(rover->bottom.model, rover->bottom.isceiling, !!(rover->flags&FF_FOG)); + Process(di, rover->bottom.model, rover->bottom.isceiling, !!(rover->flags&FF_FOG)); } lastceilingheight = ff_bottom; if (rover->alpha < 255) lastceilingheight += EQUAL_EPSILON; @@ -789,7 +804,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) if ((rover->flags&(FF_EXISTS | FF_RENDERPLANES | FF_THISINSIDE)) == (FF_EXISTS | FF_RENDERPLANES)) { - if (rover->flags&FF_FOG && mDrawer->FixedColormap) continue; + if (rover->flags&FF_FOG && di->FixedColormap) continue; if (!rover->bottom.copied && rover->flags&(FF_INVERTPLANES | FF_BOTHPLANES)) { double ff_bottom = rover->bottom.plane->ZatPoint(sector->centerspot); @@ -806,7 +821,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) Colormap = rover->GetColormap(); } - Process(rover->bottom.model, rover->bottom.isceiling, !!(rover->flags&FF_FOG)); + Process(di, rover->bottom.model, rover->bottom.isceiling, !!(rover->flags&FF_FOG)); } lastfloorheight = ff_bottom; } @@ -820,7 +835,7 @@ void GLFlat::ProcessSector(sector_t * frontsector) { SetFrom3DFloor(rover, true, !!(rover->flags&FF_FOG)); Colormap.FadeColor = frontsector->Colormap.FadeColor; - Process(rover->top.model, rover->top.isceiling, !!(rover->flags&FF_FOG)); + Process(di, rover->top.model, rover->top.isceiling, !!(rover->flags&FF_FOG)); } lastfloorheight = ff_top; if (rover->alpha < 255) lastfloorheight -= EQUAL_EPSILON; diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp index 1ddb6523c7..d48550d569 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -1185,7 +1185,7 @@ void GLHorizonPortal::DrawContents() gl_RenderState.SetMaterial(gltexture, CLAMP_NONE, 0, -1, false); gl_RenderState.SetObjectColor(origin->specialcolor); - gl_SetPlaneTextureRotation(sp, gltexture); + gl_RenderState.SetPlaneTextureRotation(sp, gltexture); gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); gl_RenderState.BlendFunc(GL_ONE,GL_ZERO); gl_RenderState.Apply(); diff --git a/src/gl/scene/gl_skydome.cpp b/src/gl/scene/gl_skydome.cpp index 1391b7d1ce..5a60d940f6 100644 --- a/src/gl/scene/gl_skydome.cpp +++ b/src/gl/scene/gl_skydome.cpp @@ -38,6 +38,7 @@ #include "gl/shaders/gl_shader.h" +EXTERN_CVAR(Float, skyoffset) //----------------------------------------------------------------------------- // // diff --git a/src/gl/scene/gl_wall.h b/src/gl/scene/gl_wall.h index 03cc9dadd9..3eaa05f7fb 100644 --- a/src/gl/scene/gl_wall.h +++ b/src/gl/scene/gl_wall.h @@ -34,73 +34,6 @@ struct FDynLightData; struct FDrawInfo; struct HWDrawInfo; -//========================================================================== -// -// One flat plane in the draw list -// -//========================================================================== - -class GLFlat -{ -public: - friend struct GLDrawList; - - GLSceneDrawer *mDrawer; - sector_t * sector; - float dz; // z offset for rendering hacks - float z; // the z position of the flat (only valid for non-sloped planes) - FMaterial *gltexture; - - FColormap Colormap; // light and fog - PalEntry FlatColor; - ERenderStyle renderstyle; - - float alpha; - GLSectorPlane plane; - int lightlevel; - bool stack; - bool ceiling; - uint8_t renderflags; - int vboindex; - //int vboheight; - - int dynlightindex; - - GLFlat(GLSceneDrawer *drawer) - { - mDrawer = drawer; - } - // compatibility fallback stuff. - void DrawSubsectorLights(subsector_t * sub, int pass); - void DrawLightsCompat(int pass); - bool PutFlatCompat(bool fog); - - void SetupSubsectorLights(int pass, subsector_t * sub, int *dli = NULL); - void DrawSubsector(subsector_t * sub); - void DrawSkyboxSector(int pass, bool processlights); - void DrawSubsectors(int pass, bool processlights, bool istrans); - void ProcessLights(bool istrans); - - void PutFlat(bool fog = false); - void Process(sector_t * model, int whichplane, bool notexture); - void SetFrom3DFloor(F3DFloor *rover, bool top, bool underside); - void ProcessSector(sector_t * frontsector); - void Draw(int pass, bool trans); - - GLFlat(const GLFlat &other) - { - memcpy(this, &other, sizeof(GLFlat)); - } - - GLFlat & operator=(const GLFlat &other) - { - memcpy(this, &other, sizeof(GLFlat)); - return *this; - } - -}; - - //========================================================================== // // One sprite in the draw list diff --git a/src/hwrenderer/scene/hw_drawinfo.h b/src/hwrenderer/scene/hw_drawinfo.h index ec4aaa31f4..c032661b5c 100644 --- a/src/hwrenderer/scene/hw_drawinfo.h +++ b/src/hwrenderer/scene/hw_drawinfo.h @@ -6,6 +6,7 @@ struct FSectorPortalGroup; struct FLinePortalSpan; struct FFlatVertex; class GLWall; +class GLFlat; struct GLDecal; //========================================================================== @@ -128,6 +129,8 @@ public: virtual void AddWall(GLWall *w) = 0; virtual void AddPortal(GLWall *w, int portaltype) = 0; virtual void AddMirrorSurface(GLWall *w) = 0; + virtual void AddFlat(GLFlat *flat, bool fog) = 0; + virtual GLDecal *AddDecal(bool onmirror) = 0; virtual void ProcessActorsInPortal(FLinePortalSpan *glport) = 0; virtual std::pair AllocVertices(unsigned int count) = 0; diff --git a/src/hwrenderer/scene/hw_drawstructs.h b/src/hwrenderer/scene/hw_drawstructs.h index e4e9a25075..f3253d0715 100644 --- a/src/hwrenderer/scene/hw_drawstructs.h +++ b/src/hwrenderer/scene/hw_drawstructs.h @@ -22,6 +22,7 @@ struct FSectorPortalGroup; struct FFlatVertex; struct FLinePortalSpan; struct FDynLightData; +class VSMatrix; enum WallTypes { @@ -281,6 +282,59 @@ public: }; +//========================================================================== +// +// One flat plane in the draw list +// +//========================================================================== + +class GLFlat +{ +public: + sector_t * sector; + float dz; // z offset for rendering hacks + float z; // the z position of the flat (only valid for non-sloped planes) + FMaterial *gltexture; + + FColormap Colormap; // light and fog + PalEntry FlatColor; + ERenderStyle renderstyle; + + float alpha; + GLSectorPlane plane; + int lightlevel; + bool stack; + bool ceiling; + uint8_t renderflags; + int vboindex; + //int vboheight; + + int dynlightindex; + + void SetupSubsectorLights(int pass, subsector_t * sub, int *dli = NULL); + + void PutFlat(HWDrawInfo *di, bool fog = false); + void Process(HWDrawInfo *di, sector_t * model, int whichplane, bool notexture); + void SetFrom3DFloor(F3DFloor *rover, bool top, bool underside); + void ProcessSector(HWDrawInfo *di, sector_t * frontsector); + + GLFlat() {} + + GLFlat(const GLFlat &other) + { + memcpy(this, &other, sizeof(GLFlat)); + } + + GLFlat & operator=(const GLFlat &other) + { + memcpy(this, &other, sizeof(GLFlat)); + return *this; + } + +}; + + + @@ -311,3 +365,5 @@ inline float Dist2(float x1,float y1,float x2,float y2) { return sqrtf((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } + +bool gl_SetPlaneTextureRotation(const GLSectorPlane * secplane, FMaterial * gltexture, VSMatrix &mat); diff --git a/src/hwrenderer/scene/hw_skydome.cpp b/src/hwrenderer/scene/hw_skydome.cpp index 32bc125b13..22c0f252b8 100644 --- a/src/hwrenderer/scene/hw_skydome.cpp +++ b/src/hwrenderer/scene/hw_skydome.cpp @@ -70,8 +70,6 @@ // //----------------------------------------------------------------------------- -CVAR(Float, skyoffset, 0, 0) // for testing - //----------------------------------------------------------------------------- // // diff --git a/src/hwrenderer/scene/hw_walls.cpp b/src/hwrenderer/scene/hw_walls.cpp index 0ee2af2ee6..16e144d3ec 100644 --- a/src/hwrenderer/scene/hw_walls.cpp +++ b/src/hwrenderer/scene/hw_walls.cpp @@ -48,6 +48,7 @@ bool GLWall::SetupLights(FDynLightData &lightdata) { + if (screen->hwcaps & RFL_NO_SHADERS) return false; // useless in OpenGL 2. if (RenderStyle == STYLE_Add && !level.lightadditivesurfaces) return false; // no lights on additively blended surfaces. // check for wall types which cannot have dynamic lights on them (portal types never get here so they don't need to be checked.) diff --git a/src/polyrenderer/scene/poly_sky.cpp b/src/polyrenderer/scene/poly_sky.cpp index 59539e19f5..eef7b0583f 100644 --- a/src/polyrenderer/scene/poly_sky.cpp +++ b/src/polyrenderer/scene/poly_sky.cpp @@ -30,6 +30,9 @@ #include "g_levellocals.h" #include "polyrenderer/scene/poly_light.h" +EXTERN_CVAR(Float, skyoffset) + + PolySkyDome::PolySkyDome() { CreateDome(); @@ -212,7 +215,6 @@ Mat4f PolySkyDome::GLSkyMath() float y_offset = 0.0f; bool mirror = false; FTexture *tex = mCurrentSetup.frontskytex; - float skyoffset = 0.0f; // skyoffset debugging CVAR in GL renderer int texh = 0; int texw = 0; diff --git a/src/r_sky.cpp b/src/r_sky.cpp index 9bc3d0fc1d..13d130adb9 100644 --- a/src/r_sky.cpp +++ b/src/r_sky.cpp @@ -65,6 +65,9 @@ CUSTOM_CVAR (Int, r_skymode, 2, CVAR_ARCHIVE) R_InitSkyMap (); } +CVAR(Float, skyoffset, 0, 0) // for testing + + int freelookviewheight;