Skip to content

Commit

Permalink
Move Push/Pop Layer stuff to pl3DPipeline
Browse files Browse the repository at this point in the history
This is what calls `Eval()` to make layer animations work, so that's now
hooked up for plGLPipeline. I don't love this approach because it feels
weird doing it in the shader class, and I suspect we need to know about
layer overrides when the shader is being generated, but... for now it
sorta works.
  • Loading branch information
dpogue committed Jul 5, 2022
1 parent 4ab9068 commit ab44da2
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 97 deletions.
82 changes: 0 additions & 82 deletions Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5280,88 +5280,6 @@ void plDXPipeline::IBottomLayer()

// Special effects /////////////////////////////////////////////////////////////

// IPushOverBaseLayer /////////////////////////////////////////////////////////
// Sets fOverBaseLayer (if any) as a wrapper on top of input layer.
// This allows the OverBaseLayer to intercept and modify queries of
// the real current layer's properties (e.g. color or state).
// fOverBaseLayer is set to only get applied to the base layer during
// multitexturing.
// Must be matched with call to IPopOverBaseLayer.
plLayerInterface* plDXPipeline::IPushOverBaseLayer(plLayerInterface* li)
{
if( !li )
return nullptr;

fOverLayerStack.push_back(li);

if( !fOverBaseLayer )
return fOverBaseLayer = li;

fForceMatHandle = true;
fOverBaseLayer = fOverBaseLayer->Attach(li);
fOverBaseLayer->Eval(fTime, fFrame, 0);
return fOverBaseLayer;
}

// IPopOverBaseLayer /////////////////////////////////////////////////////////
// Removes fOverBaseLayer as wrapper on top of input layer.
// Should match calls to IPushOverBaseLayer.
plLayerInterface* plDXPipeline::IPopOverBaseLayer(plLayerInterface* li)
{
if( !li )
return nullptr;

fForceMatHandle = true;

plLayerInterface* pop = fOverLayerStack.back();
fOverLayerStack.pop_back();
fOverBaseLayer = fOverBaseLayer->Detach(pop);

return pop;
}

// IPushOverAllLayer ///////////////////////////////////////////////////
// Push fOverAllLayer (if any) as wrapper around the input layer.
// fOverAllLayer is set to be applied to each layer during multitexturing.
// Must be matched by call to IPopOverAllLayer
plLayerInterface* plDXPipeline::IPushOverAllLayer(plLayerInterface* li)
{
if( !li )
return nullptr;

fOverLayerStack.push_back(li);

if( !fOverAllLayer )
{
fOverAllLayer = li;
fOverAllLayer->Eval(fTime, fFrame, 0);
return fOverAllLayer;
}

fForceMatHandle = true;
fOverAllLayer = fOverAllLayer->Attach(li);
fOverAllLayer->Eval(fTime, fFrame, 0);

return fOverAllLayer;
}

// IPopOverAllLayer //////////////////////////////////////////////////
// Remove fOverAllLayer as wrapper on top of input layer.
// Should match calls to IPushOverAllLayer.
plLayerInterface* plDXPipeline::IPopOverAllLayer(plLayerInterface* li)
{
if( !li )
return nullptr;

fForceMatHandle = true;

plLayerInterface* pop = fOverLayerStack.back();
fOverLayerStack.pop_back();
fOverAllLayer = fOverAllLayer->Detach(pop);

return pop;
}

// PiggyBacks - used in techniques like projective lighting.
// PiggyBacks are layers appended to each drawprimitive pass.
// For example, if a material has 3 layers which will be drawn
Expand Down
5 changes: 0 additions & 5 deletions Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,6 @@ class plDXPipeline : public pl3DPipeline<plDXDevice>
void IBottomLayer();

// Push special effects
plLayerInterface* IPushOverBaseLayer(plLayerInterface* li);
plLayerInterface* IPopOverBaseLayer(plLayerInterface* li);
plLayerInterface* IPushOverAllLayer(plLayerInterface* li);
plLayerInterface* IPopOverAllLayer(plLayerInterface* li);

int ISetNumActivePiggyBacks();
void IPushPiggyBacks(hsGMaterial* mat);
void IPopPiggyBacks();
Expand Down
22 changes: 16 additions & 6 deletions Sources/Plasma/FeatureLib/pfGLPipeline/plGLMaterialShaderRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ You can contact Cyan Worlds, Inc. by email [email protected]

#include "plGLMaterialShaderRef.h"
#include "plGLDevice.h"
#include "plGLPipeline.h"

#include <epoxy/gl.h>

#include "HeadSpin.h"
#include "hsBitVector.h"

#include "hsGMatState.inl"
#include "plPipeline.h"
#include "plPipeDebugFlags.h"

#include "plDrawable/plGBufferGroup.h"
Expand Down Expand Up @@ -230,7 +230,7 @@ void main() {
fragColor = vec4(currColor, currAlpha);
})";

plGLMaterialShaderRef::plGLMaterialShaderRef(hsGMaterial* mat, plPipeline* pipe)
plGLMaterialShaderRef::plGLMaterialShaderRef(hsGMaterial* mat, plGLPipeline* pipe)
: plGLDeviceRef(), fMaterial(mat), fPipeline(pipe), fVertShaderRef(0), fFragShaderRef(0)
{
ISetupShaderContexts();
Expand Down Expand Up @@ -274,16 +274,22 @@ void plGLMaterialShaderRef::SetupTextureRefs()
if (!layer)
continue;

layer = fPipeline->IPushOverAllLayer(layer);

// Load the image
plBitmap* img = plBitmap::ConvertNoRef(layer->GetTexture());

if (!img)
if (!img) {
layer = fPipeline->IPopOverAllLayer(layer);
continue;
}

plGLTextureRef* texRef = static_cast<plGLTextureRef*>(img->GetDeviceRef());

if (!texRef->fRef)
if (!texRef->fRef) {
layer = fPipeline->IPopOverAllLayer(layer);
continue;
}

fPipeline->CheckTextureRef(layer);

Expand Down Expand Up @@ -325,6 +331,7 @@ void plGLMaterialShaderRef::SetupTextureRefs()
glUniform1i(this->uTexture[i], numTextures);
LOG_GL_ERROR_CHECK("Uniform Texture failed")

layer = fPipeline->IPopOverAllLayer(layer);
numTextures++;
}
}
Expand Down Expand Up @@ -580,12 +587,12 @@ uint32_t plGLMaterialShaderRef::IHandleMaterial(uint32_t layer, std::shared_ptr<

// Ignoring the bit about self-rendering cube maps

plLayerInterface* currLay = /*IPushOverBaseLayer*/ fMaterial->GetLayer(layer);
plLayerInterface* currLay = fPipeline->IPushOverBaseLayer(fMaterial->GetLayer(layer));

if (fPipeline->IsDebugFlagSet(plPipeDbg::kFlagBumpW) && (currLay->GetMiscFlags() & hsGMatState::kMiscBumpDu))
currLay = fMaterial->GetLayer(++layer);

//currLay = IPushOverAllLayer(currLay);
currLay = fPipeline->IPushOverAllLayer(currLay);

hsGMatState state = ICompositeLayerState(currLay);

Expand Down Expand Up @@ -627,6 +634,9 @@ uint32_t plGLMaterialShaderRef::IHandleMaterial(uint32_t layer, std::shared_ptr<
//ISetBumpMatrices(currLay);
}

currLay = fPipeline->IPopOverAllLayer(currLay);
currLay = fPipeline->IPopOverBaseLayer(currLay);

std::shared_ptr<plVaryingNode> vVtxColor = IFindVariable<plVaryingNode>("vVtxColor", "vec4");

std::shared_ptr<plTempVariableNode> fBaseAlpha = std::make_shared<plTempVariableNode>("baseAlpha", "float");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#include "hsGMatState.h"

class hsGMaterial;
class plPipeline;
class plGLPipeline;
class plLayerInterface;

enum plGLShaderConstants : GLuint {
Expand Down Expand Up @@ -100,7 +100,7 @@ class plGLMaterialShaderRef : public plGLDeviceRef

protected:
hsGMaterial* fMaterial;
plPipeline* fPipeline;
plGLPipeline* fPipeline;
GLuint fVertShaderRef;
GLuint fFragShaderRef;

Expand Down Expand Up @@ -142,7 +142,7 @@ class plGLMaterialShaderRef : public plGLDeviceRef
void Link(plGLMaterialShaderRef** back) { plGLDeviceRef::Link((plGLDeviceRef**)back); }
plGLMaterialShaderRef* GetNext() { return (plGLMaterialShaderRef*)fNext; }

plGLMaterialShaderRef(hsGMaterial* mat, plPipeline* pipe);
plGLMaterialShaderRef(hsGMaterial* mat, plGLPipeline* pipe);
virtual ~plGLMaterialShaderRef();

void Release();
Expand Down
1 change: 1 addition & 0 deletions Sources/Plasma/FeatureLib/pfGLPipeline/plGLPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class plGLPipeline : public pl3DPipeline<plGLDevice>
{
friend class plGLPlateManager;
friend class plGLDevice;
friend class plGLMaterialShaderRef;

protected:
typedef void(*blend_vert_buffer_ptr)(plSpan*, hsMatrix44*, int, const uint8_t*, uint8_t , uint32_t, uint8_t*, uint32_t, uint32_t, uint16_t);
Expand Down
106 changes: 105 additions & 1 deletion Sources/Plasma/PubUtilLib/plPipeline/pl3DPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,6 @@ class pl3DPipeline : public plPipeline
/** Removes a layer wrapper installed by AppendLayerInterface. */
plLayerInterface* RemoveLayerInterface(plLayerInterface* li, bool onAllLayers = false) override;


/**
* Return the current bits set to be always on for the given category
* (e.g. ZFlags).
Expand Down Expand Up @@ -851,6 +850,39 @@ class pl3DPipeline : public plPipeline
plRenderTarget* IGetNextAvRT();
void IFreeAvRT(plRenderTarget* tex);

/**
* Sets fOverBaseLayer (if any) as a wrapper on top of input layer.
* This allows the OverBaseLayer to intercept and modify queries of
* the real current layer's properties (e.g. color or state).
* fOverBaseLayer is set to only get applied to the base layer during
* multitexturing.
*
* Must be matched with call to IPopOverBaseLayer.
*/
plLayerInterface* IPushOverBaseLayer(plLayerInterface* li);

/**
* Removes fOverBaseLayer as wrapper on top of input layer.
*
* Should match calls to IPushOverBaseLayer.
*/
plLayerInterface* IPopOverBaseLayer(plLayerInterface* li);

/**
* Push fOverAllLayer (if any) as wrapper around the input layer.
*
* fOverAllLayer is set to be applied to each layer during multitexturing.
*
* Must be matched by call to IPopOverAllLayer
*/
plLayerInterface* IPushOverAllLayer(plLayerInterface* li);

/**
* Remove fOverAllLayer as wrapper on top of input layer.
*
* Should match calls to IPushOverAllLayer.
*/
plLayerInterface* IPopOverAllLayer(plLayerInterface* li);

/**
* For every span in the list of visible span indices, find the list of
Expand Down Expand Up @@ -1745,6 +1777,78 @@ void pl3DPipeline<DeviceType>::IFreeAvRT(plRenderTarget* tex)
}


template <class DeviceType>
plLayerInterface* pl3DPipeline<DeviceType>::IPushOverBaseLayer(plLayerInterface* li)
{
if (!li)
return nullptr;

fOverLayerStack.push_back(li);

if (!fOverBaseLayer)
return fOverBaseLayer = li;

fForceMatHandle = true;
fOverBaseLayer = fOverBaseLayer->Attach(li);
fOverBaseLayer->Eval(fTime, fFrame, 0);
return fOverBaseLayer;
}


template <class DeviceType>
plLayerInterface* pl3DPipeline<DeviceType>::IPopOverBaseLayer(plLayerInterface* li)
{
if (!li)
return nullptr;

fForceMatHandle = true;

plLayerInterface* pop = fOverLayerStack.back();
fOverLayerStack.pop_back();
fOverBaseLayer = fOverBaseLayer->Detach(pop);

return pop;
}


template <class DeviceType>
plLayerInterface* pl3DPipeline<DeviceType>::IPushOverAllLayer(plLayerInterface* li)
{
if (!li)
return nullptr;

fOverLayerStack.push_back(li);

if (!fOverAllLayer) {
fOverAllLayer = li;
fOverAllLayer->Eval(fTime, fFrame, 0);
return fOverAllLayer;
}

fForceMatHandle = true;
fOverAllLayer = fOverAllLayer->Attach(li);
fOverAllLayer->Eval(fTime, fFrame, 0);

return fOverAllLayer;
}


template <class DeviceType>
plLayerInterface* pl3DPipeline<DeviceType>::IPopOverAllLayer(plLayerInterface* li)
{
if (!li)
return nullptr;

fForceMatHandle = true;

plLayerInterface* pop = fOverLayerStack.back();
fOverLayerStack.pop_back();
fOverAllLayer = fOverAllLayer->Detach(pop);

return pop;
}


template <class DeviceType>
void pl3DPipeline<DeviceType>::ICheckLighting(plDrawableSpans* drawable, std::vector<int16_t>& visList, plVisMgr* visMgr)
{
Expand Down

0 comments on commit ab44da2

Please sign in to comment.