Skip to content

Commit

Permalink
Merge branch 'master' into clientserver
Browse files Browse the repository at this point in the history
  • Loading branch information
Rachael Alexanderson committed Apr 18, 2018
2 parents 759d758 + a4a4abe commit 7a42c58
Show file tree
Hide file tree
Showing 51 changed files with 358 additions and 261 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Expand Up @@ -856,9 +856,9 @@ set( FASTMATH_SOURCES
gl/scene/gl_walls_draw.cpp
gl/scene/gl_vertex.cpp
gl/scene/gl_spritelight.cpp
gl/dynlights/gl_dynlight1.cpp
gl_load/gl_load.c
gl/models/gl_models.cpp
hwrenderer/dynlights/hw_dynlightdata.cpp
r_data/models/models.cpp
r_data/matrix.cpp
sound/adlmidi/adldata.cpp
Expand Down
38 changes: 16 additions & 22 deletions src/compatibility.cpp
Expand Up @@ -74,28 +74,6 @@ enum
SLOT_BCOMPAT
};

enum
{
CP_END,
CP_CLEARFLAGS,
CP_SETFLAGS,
CP_SETSPECIAL,
CP_CLEARSPECIAL,
CP_SETACTIVATION,
CP_SETSECTOROFFSET,
CP_SETSECTORSPECIAL,
CP_SETWALLYSCALE,
CP_SETWALLTEXTURE,
CP_SETTHINGZ,
CP_SETTAG,
CP_SETTHINGFLAGS,
CP_SETVERTEX,
CP_SETTHINGSKILLS,
CP_SETSECTORTEXTURE,
CP_SETSECTORLIGHT,
CP_SETLINESECTORREF,
};

// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------

// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
Expand Down Expand Up @@ -397,6 +375,22 @@ DEFINE_ACTION_FUNCTION(DLevelCompatibility, SetThingSkills)
return 0;
}

DEFINE_ACTION_FUNCTION(DLevelCompatibility, SetThingXY)
{
PARAM_PROLOGUE;
PARAM_INT(thing);
PARAM_FLOAT(x);
PARAM_FLOAT(y);

if ((unsigned)thing < MapThingsConverted.Size())
{
auto& pos = MapThingsConverted[thing].pos;
pos.X = x;
pos.Y = y;
}
return 0;
}

DEFINE_ACTION_FUNCTION(DLevelCompatibility, SetThingZ)
{
PARAM_PROLOGUE;
Expand Down
2 changes: 2 additions & 0 deletions src/g_shared/a_dynlight.h
Expand Up @@ -229,5 +229,7 @@ class ADynamicLight : public AActor
LightFlags lightflags;
DAngle SpotInnerAngle = 10.0;
DAngle SpotOuterAngle = 25.0;

int mShadowmapIndex = 1024;

};
4 changes: 1 addition & 3 deletions src/g_statusbar/shared_sbar.cpp
Expand Up @@ -658,7 +658,6 @@ void DBaseStatusBar::AttachMessage (DHUDMessageBase *msg, uint32_t id, int layer
{
DHUDMessageBase *old = NULL;
DHUDMessageBase **prev;
DObject *container = this;

old = (id == 0 || id == 0xFFFFFFFF) ? NULL : DetachMessage (id);
if (old != NULL)
Expand All @@ -679,14 +678,13 @@ void DBaseStatusBar::AttachMessage (DHUDMessageBase *msg, uint32_t id, int layer
// it gets drawn back to front.)
while (*prev != NULL && (*prev)->SBarID > id)
{
container = *prev;
prev = &(*prev)->Next;
}

msg->Next = *prev;
msg->SBarID = id;
*prev = msg;
GC::WriteBarrier(container, msg);
GC::WriteBarrier(msg);
}

DEFINE_ACTION_FUNCTION(DBaseStatusBar, AttachMessage)
Expand Down
17 changes: 10 additions & 7 deletions src/gl/compatibility/gl_20.cpp
Expand Up @@ -40,7 +40,8 @@
#include "g_levellocals.h"
#include "actorinlines.h"
#include "g_levellocals.h"
#include "gl/dynlights/gl_dynlight.h"
#include "hwrenderer/dynlights/hw_dynlightdata.h"

#include "gl/renderer/gl_renderer.h"
#include "gl/renderer/gl_lightdata.h"
#include "gl/system/gl_interface.h"
Expand Down Expand Up @@ -438,7 +439,7 @@ bool gl_SetupLight(int group, Plane & p, ADynamicLight * light, FVector3 & nearP

if (radius <= 0.f) return false;
if (dist > radius) return false;
if (checkside && gl_lights_checkside && p.PointOnSide(lpos.X, lpos.Z, lpos.Y))
if (checkside && p.PointOnSide(lpos.X, lpos.Z, lpos.Y))
{
return false;
}
Expand Down Expand Up @@ -559,7 +560,8 @@ bool FDrawInfo::PutWallCompat(GLWall *wall, int passflag)
bool masked = passflag == 2 && wall->gltexture->isMasked();

int list = list_indices[masked][foggy];
dldrawlists[list].AddWall(wall);
auto newwall = dldrawlists[list].NewWall();
*newwall = *wall;
return true;

}
Expand All @@ -583,7 +585,8 @@ bool GLFlat::PutFlatCompat(bool fog)


int list = list_indices[masked][foggy];
gl_drawinfo->dldrawlists[list].AddFlat(this);
auto newflat = gl_drawinfo->dldrawlists[list].NewFlat();
*newflat = *this;
return true;
}

Expand Down Expand Up @@ -664,7 +667,7 @@ 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 (gl_lights_checkside && ((planeh<light->Z() && ceiling) || (planeh>light->Z() && !ceiling)))
if (((planeh<light->Z() && ceiling) || (planeh>light->Z() && !ceiling)))
{
node = node->nextLight;
continue;
Expand Down Expand Up @@ -745,7 +748,7 @@ bool GLWall::PrepareLight(ADynamicLight * light, int pass)
float scale;

auto normal = glseg.Normal();
p.Set(normal, -normal.X * glseg.x1 - normal.Y * glseg.y1);
p.Set(normal, -normal.X * glseg.x1 - normal.Z * glseg.y1);

if (!p.ValidNormal())
{
Expand Down Expand Up @@ -1001,4 +1004,4 @@ int LegacyDesaturation(F2DDrawer::RenderCommand &cmd)
auto &tbl = DesaturatedTranslationTable[cmd.mTranslation];
tbl.tables[desat] = newremap;
return newremap->GetUniqueIndex();
}
}
3 changes: 2 additions & 1 deletion src/gl/compatibility/gl_swshader20.cpp
Expand Up @@ -34,7 +34,8 @@
#include "i_system.h"
#include "r_utility.h"
#include "w_wad.h"
#include "gl/dynlights/gl_dynlight.h"
#include "hwrenderer/dynlights/hw_dynlightdata.h"

#include "gl/renderer/gl_renderer.h"
#include "gl/system/gl_interface.h"
#include "gl/renderer/gl_renderstate.h"
Expand Down
2 changes: 1 addition & 1 deletion src/gl/dynlights/gl_lightbuffer.cpp
Expand Up @@ -28,9 +28,9 @@
#include "gl/system/gl_system.h"
#include "gl/shaders/gl_shader.h"
#include "gl/dynlights/gl_lightbuffer.h"
#include "gl/dynlights/gl_dynlight.h"
#include "gl/system/gl_interface.h"
#include "gl/utility//gl_clock.h"
#include "hwrenderer/dynlights/hw_dynlightdata.h"

static const int INITIAL_BUFFER_SIZE = 160000; // This means 80000 lights per frame and 160000*16 bytes == 2.56 MB.

Expand Down
45 changes: 22 additions & 23 deletions src/gl/dynlights/gl_shadowmap.cpp
Expand Up @@ -23,14 +23,14 @@
#include "gl/system/gl_system.h"
#include "gl/shaders/gl_shader.h"
#include "gl/dynlights/gl_shadowmap.h"
#include "gl/dynlights/gl_dynlight.h"
#include "gl/system/gl_interface.h"
#include "gl/system/gl_debug.h"
#include "gl/system/gl_cvars.h"
#include "gl/renderer/gl_renderer.h"
#include "gl/renderer/gl_postprocessstate.h"
#include "gl/renderer/gl_renderbuffers.h"
#include "gl/shaders/gl_shadowmapshader.h"
#include "hwrenderer/dynlights/hw_dynlightdata.h"
#include "r_state.h"
#include "g_levellocals.h"
#include "stats.h"
Expand All @@ -42,12 +42,7 @@
the fragment shader (main.fp) needs to sample from row 20. That is, the V texture coordinate needs
to be 20.5/1024.
mLightToShadowmap is a hash map storing which line each ADynamicLight is assigned to. The public
ShadowMapIndex function allows the main rendering to find the index and upload that along with the
normal light data. From there, the main.fp shader can sample from the shadow map texture, which
is currently always bound to texture unit 16.
The texel row for each light is split into four parts. One for each direction, like a cube texture,
The texel row for each light is split into four parts. One for each direction, like a cube texture,
but then only in 2D where this reduces itself to a square. When main.fp samples from the shadow map
it first decides in which direction the fragment is (relative to the light), like cubemap sampling does
for 3D, but once again just for the 2D case.
Expand Down Expand Up @@ -97,6 +92,20 @@ CUSTOM_CVAR(Int, gl_shadowmap_quality, 512, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
}
}

CUSTOM_CVAR (Bool, gl_light_shadowmap, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
{
if (!self)
{
// Unset any residual shadow map indices in the light actors.
TThinkerIterator<ADynamicLight> it(STAT_DLIGHT);
while (auto light = it.Next())
{
light->mShadowmapIndex = 1024;
}
}
}


void FShadowMap::Update()
{
UpdateCycles.Reset();
Expand Down Expand Up @@ -152,42 +161,32 @@ bool FShadowMap::IsEnabled() const
return gl_light_shadowmap && !!(gl.flags & RFL_SHADER_STORAGE_BUFFER);
}

int FShadowMap::ShadowMapIndex(ADynamicLight *light)
{
if (IsEnabled())
{
auto val = mLightToShadowmap.CheckKey(light);
if (val != nullptr) return *val;
}
return 1024;
}

void FShadowMap::UploadLights()
{
if (mLights.Size() != 1024 * 4) mLights.Resize(1024 * 4);
int lightindex = 0;
mLightToShadowmap.Clear(mLightToShadowmap.CountUsed() * 2); // To do: allow clearing a TMap while building up a reserve

// Todo: this should go through the blockmap in a spiral pattern around the player so that closer lights are preferred.
TThinkerIterator<ADynamicLight> it(STAT_DLIGHT);
while (auto light = it.Next())
{
LightsProcessed++;
if (light->shadowmapped)
if (light->shadowmapped && lightindex < 1024 * 4)
{
LightsShadowmapped++;

mLightToShadowmap[light] = lightindex >> 2;
light->mShadowmapIndex = lightindex >> 2;

mLights[lightindex] = light->X();
mLights[lightindex+1] = light->Y();
mLights[lightindex+2] = light->Z();
mLights[lightindex+3] = light->GetRadius();
lightindex += 4;

if (lightindex == 1024*4) // Only 1024 lights for now
break;
}
else
{
light->mShadowmapIndex = 1024;
}

}

Expand Down
6 changes: 0 additions & 6 deletions src/gl/dynlights/gl_shadowmap.h
Expand Up @@ -20,9 +20,6 @@ class FShadowMap
// Update shadow map texture
void Update();

// Return the assigned shadow map index for a given light
int ShadowMapIndex(ADynamicLight *light);

// Test if a world position is in shadow relative to the specified light and returns false if it is
bool ShadowTest(ADynamicLight *light, const DVector3 &pos);

Expand All @@ -42,9 +39,6 @@ class FShadowMap
// Working buffer for creating the list of lights. Stored here to avoid allocating memory each frame
TArray<float> mLights;

// The assigned shadow map index for each light
TMap<ADynamicLight*, int> mLightToShadowmap;

// OpenGL storage buffers for the AABB tree
int mNodesBuffer = 0;
int mLinesBuffer = 0;
Expand Down
3 changes: 1 addition & 2 deletions src/gl/renderer/gl_renderstate.cpp
Expand Up @@ -69,7 +69,6 @@ void FRenderState::Reset()
currentColorMask[0] = currentColorMask[1] = currentColorMask[2] = currentColorMask[3] = true;
mFogColor.d = -1;
mTextureMode = -1;
mLightIndex = -1;
mDesaturation = 0;
mSrcBlend = GL_SRC_ALPHA;
mDstBlend = GL_ONE_MINUS_SRC_ALPHA;
Expand Down Expand Up @@ -176,7 +175,7 @@ bool FRenderState::ApplyShader()
activeShader->muClipHeightDirection.Set(mClipHeightDirection);
activeShader->muTimer.Set((double)(screen->FrameTime - firstFrame) * (double)mShaderTimer / 1000.);
activeShader->muAlphaThreshold.Set(mAlphaThreshold);
activeShader->muLightIndex.Set(mLightIndex); // will always be -1 for now
activeShader->muLightIndex.Set(-1);
activeShader->muClipSplit.Set(mClipSplit);
activeShader->muViewHeight.Set(viewheight);
activeShader->muSpecularMaterial.Set(mGlossiness, mSpecularLevel);
Expand Down
6 changes: 0 additions & 6 deletions src/gl/renderer/gl_renderstate.h
Expand Up @@ -82,7 +82,6 @@ class FRenderState
bool mBrightmapEnabled;
bool mColorMask[4];
bool currentColorMask[4];
int mLightIndex;
int mSpecialEffect;
int mTextureMode;
int mDesaturation;
Expand Down Expand Up @@ -327,11 +326,6 @@ class FRenderState
}
}

void SetLightIndex(int n)
{
mLightIndex = n;
}

void EnableBrightmap(bool on)
{
mBrightmapEnabled = on;
Expand Down

0 comments on commit 7a42c58

Please sign in to comment.