mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-11 14:44:36 +00:00
use resolveSourceType
Use resolve source type for other shaderops This allows us to be more dynamic in the shaderop logic moved function out to langelement, this allows it to be used inside shaderFeatures
This commit is contained in:
parent
a92ea1ffab
commit
966b109bd6
5 changed files with 85 additions and 83 deletions
|
|
@ -509,7 +509,7 @@ void NormalMapFeature::processPix(Vector<ShaderComponent*>& componentList, const
|
|||
|
||||
MultiLine* meta = new MultiLine;
|
||||
|
||||
// TEMP float3 for base decoded normal
|
||||
// TEMP float4 for base decoded normal
|
||||
Var* tempNorm = new Var;
|
||||
tempNorm->setName(params->inputName + "_normTemp");
|
||||
tempNorm->setType(GFXSCT_Float4);
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
#include "core/strings/stringFunctions.h"
|
||||
#include "core/util/str.h"
|
||||
#include "gfx/gfxDevice.h"
|
||||
#include "shaderGen/shaderOp.h"
|
||||
#include "langElement.h"
|
||||
|
||||
//**************************************************************************
|
||||
|
|
@ -132,6 +133,56 @@ GFXShaderConstType LangElement::stringToConstType(const char* name)
|
|||
return GFXSCT_Uknown;
|
||||
}
|
||||
|
||||
bool LangElement::resolveSourceType(LangElement* elem, Var*& outVar, const ShaderTypeInfo*& outInfo)
|
||||
{
|
||||
outVar = nullptr;
|
||||
outInfo = nullptr;
|
||||
|
||||
// DIRECT VAR
|
||||
if (Var* v = dynamic_cast<Var*>(elem))
|
||||
{
|
||||
outVar = v;
|
||||
outInfo = getTypeInfo(stringToConstType((const char*)v->type));
|
||||
return outInfo != nullptr;
|
||||
}
|
||||
|
||||
// INDEX OP: arrVar[index]
|
||||
if (IndexOp* idx = dynamic_cast<IndexOp*>(elem))
|
||||
{
|
||||
Var* arr = dynamic_cast<Var*>(idx->mInput[0]);
|
||||
if (!arr)
|
||||
return false;
|
||||
|
||||
const ShaderTypeInfo* arrInfo = getTypeInfo(stringToConstType((const char*)arr->type));
|
||||
if (!arrInfo)
|
||||
return false;
|
||||
|
||||
// array element type = same as var type but no array dimension
|
||||
outVar = arr;
|
||||
outInfo = arrInfo;
|
||||
return true;
|
||||
}
|
||||
|
||||
// CAST OP: cast var
|
||||
if (CastOp* cast = dynamic_cast<CastOp*>(elem))
|
||||
{
|
||||
Var* castVar = dynamic_cast<Var*>(cast->mInput[0]);
|
||||
if (!castVar)
|
||||
return false;
|
||||
|
||||
const ShaderTypeInfo* castInfo = getTypeInfo(cast->mTargetType);// get the casts target type.
|
||||
if (!castInfo)
|
||||
return false;
|
||||
|
||||
outVar = castVar; // we should probably return null as we should just write the castop langelement, not a var.
|
||||
outInfo = castInfo;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//--------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -92,6 +92,7 @@ struct ShaderTypeInfo
|
|||
//**************************************************************************
|
||||
// Language element
|
||||
//**************************************************************************
|
||||
struct Var; // forward declaration
|
||||
struct LangElement
|
||||
{
|
||||
static void buildTypeMaps();
|
||||
|
|
@ -99,7 +100,8 @@ struct LangElement
|
|||
static LangElement * find( const char *name );
|
||||
static void deleteElements();
|
||||
static const ShaderTypeInfo* getTypeInfo(GFXShaderConstType type);
|
||||
|
||||
static bool resolveSourceType(LangElement* elem, Var*& outVar, const ShaderTypeInfo*& outInfo);
|
||||
|
||||
U8 name[32];
|
||||
|
||||
static const char* constTypeToString(GFXShaderConstType constType, bool sampler = false, bool matrix = false);
|
||||
|
|
|
|||
|
|
@ -26,53 +26,6 @@
|
|||
|
||||
#include "shaderOp.h"
|
||||
|
||||
bool ShaderOp::resolveSourceType(LangElement* elem, Var*& outVar, const ShaderTypeInfo*& outInfo)
|
||||
{
|
||||
outVar = nullptr;
|
||||
outInfo = nullptr;
|
||||
|
||||
// DIRECT VAR
|
||||
if (Var* v = dynamic_cast<Var*>(elem))
|
||||
{
|
||||
outVar = v;
|
||||
outInfo = getTypeInfo(stringToConstType((const char*)v->type));
|
||||
return outInfo != nullptr;
|
||||
}
|
||||
|
||||
// INDEX OP: arrVar[index]
|
||||
if (IndexOp* idx = dynamic_cast<IndexOp*>(elem))
|
||||
{
|
||||
Var* arr = dynamic_cast<Var*>(idx->mInput[0]);
|
||||
if (!arr)
|
||||
return false;
|
||||
|
||||
const ShaderTypeInfo* arrInfo = getTypeInfo(stringToConstType((const char*)arr->type));
|
||||
if (!arrInfo)
|
||||
return false;
|
||||
|
||||
// array element type = same as var type but no array dimension
|
||||
outVar = arr;
|
||||
outInfo = arrInfo;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (CastOp* cast = dynamic_cast<CastOp*>(elem))
|
||||
{
|
||||
Var* castVar = dynamic_cast<Var*>(cast->mInput[0]);
|
||||
if (!castVar)
|
||||
return false;
|
||||
|
||||
const ShaderTypeInfo* castInfo = getTypeInfo(cast->mTargetType);// get the casts target type.
|
||||
if (!castInfo)
|
||||
return false;
|
||||
|
||||
outVar = castVar;
|
||||
outInfo = castInfo;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
// Shader Operations
|
||||
//**************************************************************************
|
||||
|
|
@ -396,32 +349,40 @@ void MatrixInitializeOp::print(Stream& stream)
|
|||
U32 count = 0;
|
||||
for (U32 elem = 0; elem < mInitialVals.size(); elem++)
|
||||
{
|
||||
LangElement* writeOut = NULL;
|
||||
Var* curVar = dynamic_cast<Var*>(mInitialVals[elem]);
|
||||
if (curVar) // is a var
|
||||
LangElement* initElem = mInitialVals[elem];
|
||||
Var* initVar = nullptr;
|
||||
const ShaderTypeInfo* initInfo = nullptr;
|
||||
|
||||
if (!resolveSourceType(initElem, initVar, initInfo))
|
||||
{
|
||||
const ShaderTypeInfo* curInfo = getTypeInfo(stringToConstType((const char*)curVar->type));
|
||||
if (!curInfo) // no info, cant do it cleanly.
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
const U32 curSize = curInfo->cols;
|
||||
if (dynamic_cast<IndexOp*>(initElem) || dynamic_cast<CastOp*>(initElem)) // if we are a cast or index, write out.
|
||||
{
|
||||
count += initInfo->cols;
|
||||
initElem->print(stream);
|
||||
}
|
||||
else if(dynamic_cast<Var*>(initElem)) // we are a var (hopefully)
|
||||
{
|
||||
const U32 varSize = initInfo->cols;
|
||||
const bool cast = cols != varSize;
|
||||
|
||||
// if we are an array
|
||||
if (curVar->arraySize > 1)
|
||||
if (initVar->arraySize > 1)
|
||||
{
|
||||
for (U32 arr = 0; arr < curVar->arraySize; arr++)
|
||||
for (U32 arr = 0; arr < initVar->arraySize; arr++)
|
||||
{
|
||||
writeOut = new IndexOp(curVar, arr);
|
||||
if (curSize != cols)
|
||||
initElem = new IndexOp(initVar, arr);
|
||||
if (cast)
|
||||
{
|
||||
CastOp* cast = new CastOp(writeOut, (GFXShaderConstType)(GFXSCT_Float + (cols - 1)));
|
||||
CastOp* cast = new CastOp(initElem, (GFXShaderConstType)(GFXSCT_Float + (cols - 1)));
|
||||
cast->print(stream);
|
||||
count += cols;
|
||||
}
|
||||
else
|
||||
{
|
||||
writeOut->print(stream);
|
||||
count += curSize;
|
||||
initElem->print(stream);
|
||||
count += varSize;
|
||||
}
|
||||
|
||||
if (count < matSize)
|
||||
|
|
@ -432,16 +393,16 @@ void MatrixInitializeOp::print(Stream& stream)
|
|||
}
|
||||
else
|
||||
{
|
||||
if (curSize != cols)
|
||||
if (cast)
|
||||
{
|
||||
CastOp* cast = new CastOp(curVar, (GFXShaderConstType)(GFXSCT_Float + (cols - 1)));
|
||||
CastOp* cast = new CastOp(initElem, (GFXShaderConstType)(GFXSCT_Float + (cols - 1)));
|
||||
cast->print(stream);
|
||||
count += cols;
|
||||
}
|
||||
else
|
||||
{
|
||||
curVar->print(stream);
|
||||
count += curSize;
|
||||
initElem->print(stream);
|
||||
count += varSize;
|
||||
}
|
||||
|
||||
if (count < matSize)
|
||||
|
|
@ -450,18 +411,9 @@ void MatrixInitializeOp::print(Stream& stream)
|
|||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Non-var LangElement, assume it produces correct vector
|
||||
mInitialVals[elem]->print(stream);
|
||||
count += cols;
|
||||
|
||||
if (count < matSize)
|
||||
WRITESTR(",\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
// If not enough elements → pad with zeros
|
||||
// If not enough elements → pad with identity
|
||||
while (count < matSize)
|
||||
{
|
||||
U32 row = count / cols;
|
||||
|
|
@ -512,7 +464,7 @@ void MatrixMultiplyOp::print(Stream& stream)
|
|||
return;
|
||||
}
|
||||
|
||||
LangElement* rightElem = mInput[0];
|
||||
LangElement* rightElem = mInput[1];
|
||||
Var* rightVar = nullptr;
|
||||
const ShaderTypeInfo* rightInfo = nullptr;
|
||||
|
||||
|
|
|
|||
|
|
@ -52,11 +52,8 @@
|
|||
///**************************************************************************
|
||||
class ShaderOp : public LangElement
|
||||
{
|
||||
protected:
|
||||
LangElement * mInput[2];
|
||||
|
||||
public:
|
||||
bool resolveSourceType(LangElement* elem, Var*& outVar, const ShaderTypeInfo*& outInfo);
|
||||
LangElement* mInput[2];
|
||||
ShaderOp( LangElement *in1, LangElement *in2 );
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue