Skip to content

Commit

Permalink
RTSS: range loop refactoring (#2937)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joilnen authored Sep 11, 2023
1 parent 78c2d85 commit 64bc666
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 191 deletions.
42 changes: 18 additions & 24 deletions Components/RTShaderSystem/src/OgreShaderGLSLProgramWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void GLSLProgramWriter::writeMainSourceCode(std::ostream& os, Program* program)
}

const UniformParameterList& parameterList = program->getParameters();

// Generate global variable code.
writeUniformParametersTitle(os, program);
os << std::endl;
Expand Down Expand Up @@ -180,7 +180,7 @@ void GLSLProgramWriter::writeMainSourceCode(std::ostream& os, Program* program)
writeParameter(os, uparam);
os << ";\n";
}
os << std::endl;
os << std::endl;

Function* curFunction = program->getMain();
const ShaderParameterList& inParams = curFunction->getInputParameters();
Expand Down Expand Up @@ -256,7 +256,7 @@ void GLSLProgramWriter::writeInputParameters(std::ostream& os, Function* functio
int psInLocation = 0;

for ( ; itParam != itParamEnd; ++itParam)
{
{
const ParameterPtr& pParam = *itParam;
auto paramContent = pParam->getContent();
auto paramSemantic = pParam->getSemantic();
Expand Down Expand Up @@ -284,7 +284,7 @@ void GLSLProgramWriter::writeInputParameters(std::ostream& os, Function* functio
if(pParam->isHighP())
os << "f32"; // rely on unified shader vor f32vec4 etc.
os << mGpuConstTypeMap[pParam->getType()];
os << "\t";
os << "\t";
os << paramName;
os << ", " << psInLocation++ << ")\n";
}
Expand Down Expand Up @@ -312,7 +312,7 @@ void GLSLProgramWriter::writeInputParameters(std::ostream& os, Function* functio
type = GpuConstantType(type & ~GpuConstantDefinition::getBaseType(type));
os << mGpuConstTypeMap[type];
}
os << "\t";
os << "\t";
os << pParam->getName() << ", ";
writeParameterSemantic(os, pParam); // maps to location
os << ")\n";
Expand All @@ -324,26 +324,20 @@ void GLSLProgramWriter::writeInputParameters(std::ostream& os, Function* functio
void GLSLProgramWriter::writeOutParameters(std::ostream& os, Function* function, GpuProgramType gpuType)
{
const ShaderParameterList& outParams = function->getOutputParameters();

ShaderParameterConstIterator itParam = outParams.begin();
ShaderParameterConstIterator itParamEnd = outParams.end();

int vsOutLocation = 0;

for ( ; itParam != itParamEnd; ++itParam)
for (const auto& p : outParams)
{
const ParameterPtr& pParam = *itParam;

if(gpuType == GPT_VERTEX_PROGRAM)
{
// GLSL vertex program has to write always gl_Position (but this is also deprecated after version 130)
if(pParam->getSemantic() == Parameter::SPS_POSITION)
if(p->getSemantic() == Parameter::SPS_POSITION)
{
pParam->_rename("gl_Position");
p->_rename("gl_Position");
}
else if(pParam->getContent() == Parameter::SPC_POINTSPRITE_SIZE)
else if(p->getContent() == Parameter::SPC_POINTSPRITE_SIZE)
{
pParam->_rename("gl_PointSize");
p->_rename("gl_PointSize");
}
else
{
Expand All @@ -352,25 +346,25 @@ void GLSLProgramWriter::writeOutParameters(std::ostream& os, Function* function,
// In the vertex and fragment program the variable names must match.
// Unfortunately now the input params are prefixed with an 'i' and output params with 'o'.
// Thats why we rename the params which are used in function atoms
String paramName = pParam->getName();
String paramName = p->getName();
paramName[0] = 'i';
pParam->_rename(paramName);
p->_rename(paramName);

writeParameter(os, pParam);
writeParameter(os, p);
os << ", " << vsOutLocation++ << ")\n";
}
}
else if(gpuType == GPT_FRAGMENT_PROGRAM &&
pParam->getSemantic() == Parameter::SPS_COLOR)
{
if(pParam->getIndex() == 0)
p->getSemantic() == Parameter::SPS_COLOR)
{
if(p->getIndex() == 0)
{
// handled by UnifiedShader
pParam->_rename("gl_FragColor");
p->_rename("gl_FragColor");
continue;
}

os << "OUT(vec4\t" << pParam->getName() << ", " << pParam->getIndex() << ")\n";
os << "OUT(vec4\t" << p->getName() << ", " << p->getIndex() << ")\n";
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ SGMaterialSerializerListener::SGMaterialSerializerListener()
}

//-----------------------------------------------------------------------------
void SGMaterialSerializerListener::materialEventRaised(MaterialSerializer* ser,
MaterialSerializer::SerializeEvent event,
void SGMaterialSerializerListener::materialEventRaised(MaterialSerializer* ser,
MaterialSerializer::SerializeEvent event,
bool& skip, const Material* mat)
{
if (event == MaterialSerializer::MSE_PRE_WRITE)
Expand All @@ -55,21 +55,21 @@ void SGMaterialSerializerListener::materialEventRaised(MaterialSerializer* ser,
}

//-----------------------------------------------------------------------------
void SGMaterialSerializerListener::techniqueEventRaised(MaterialSerializer* ser,
MaterialSerializer::SerializeEvent event,
void SGMaterialSerializerListener::techniqueEventRaised(MaterialSerializer* ser,
MaterialSerializer::SerializeEvent event,
bool& skip, const Technique* tech)
{
// Pre technique write event.
if (event == MaterialSerializer::MSE_PRE_WRITE)
{
{
const Any& techUserData = tech->getUserObjectBindings().getUserAny(ShaderGenerator::SGTechnique::UserKey);

// Skip writing this technique since it was generated by the Shader Generator.
if (techUserData.has_value())
{
skip = true;
return;
}
}
}
}

Expand Down Expand Up @@ -136,8 +136,8 @@ void SGMaterialSerializerListener::serializeTextureUnitStateAttributes(MaterialS
}

//-----------------------------------------------------------------------------
void SGMaterialSerializerListener::passEventRaised(MaterialSerializer* ser,
MaterialSerializer::SerializeEvent event,
void SGMaterialSerializerListener::passEventRaised(MaterialSerializer* ser,
MaterialSerializer::SerializeEvent event,
bool& skip, const Pass* pass)
{
// End of pass writing event.
Expand All @@ -150,8 +150,8 @@ void SGMaterialSerializerListener::passEventRaised(MaterialSerializer* ser,
}

//-----------------------------------------------------------------------------
void SGMaterialSerializerListener::textureUnitStateEventRaised(MaterialSerializer* ser,
MaterialSerializer::SerializeEvent event,
void SGMaterialSerializerListener::textureUnitStateEventRaised(MaterialSerializer* ser,
MaterialSerializer::SerializeEvent event,
bool& skip, const TextureUnitState* textureUnit)
{
// End of pass writing event.
Expand All @@ -166,22 +166,14 @@ void SGMaterialSerializerListener::textureUnitStateEventRaised(MaterialSerialize
//-----------------------------------------------------------------------------
ShaderGenerator::SGPass* SGMaterialSerializerListener::getShaderGeneratedPass(const Pass* srcPass)
{
SGPassListIterator it = mSGPassList.begin();
SGPassListIterator itEnd = mSGPassList.end();

for (; it != itEnd; ++it)
for (auto *s : mSGPassList)
{
ShaderGenerator::SGPass* currPassEntry = *it;

if (currPassEntry->getSrcPass() == srcPass)
{
return currPassEntry;
}
if (s->getSrcPass() == srcPass)
return s;
}

return NULL;
}


}
}
32 changes: 14 additions & 18 deletions Components/RTShaderSystem/src/OgreShaderProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ void Program::addParameter(UniformParameterPtr parameter)
{
if (getParameterByName(parameter->getName()).get() != NULL)
{
OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS,
"Parameter <" + parameter->getName() + "> already declared in program.",
OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS,
"Parameter <" + parameter->getName() + "> already declared in program.",
"Program::addParameter" );
}

Expand Down Expand Up @@ -144,15 +144,15 @@ UniformParameterPtr Program::resolveParameter(GpuProgramParameters::AutoConstant

uint32 size = 0;
if(isArray(autoType)) std::swap(size, data); // for array autotypes the extra parameter is the size

// Create new parameter
param = std::make_shared<UniformParameter>(autoType, data, size);
addParameter(param);

return param;
}

UniformParameterPtr Program::resolveAutoParameterReal(GpuProgramParameters::AutoConstantType autoType,
UniformParameterPtr Program::resolveAutoParameterReal(GpuProgramParameters::AutoConstantType autoType,
Real data, size_t size)
{
UniformParameterPtr param;
Expand All @@ -168,7 +168,7 @@ UniformParameterPtr Program::resolveAutoParameterReal(GpuProgramParameters::Auto
return param;
}
}

// Create new parameter.
param = std::make_shared<UniformParameter>(autoType, float(data), size);
addParameter(param);
Expand All @@ -193,7 +193,7 @@ UniformParameterPtr Program::resolveAutoParameterReal(GpuProgramParameters::Auto
return param;
}
}

// Create new parameter.
param = std::make_shared<UniformParameter>(autoType, data, size, type);
addParameter(param);
Expand All @@ -202,7 +202,7 @@ UniformParameterPtr Program::resolveAutoParameterReal(GpuProgramParameters::Auto
}

//-----------------------------------------------------------------------------
UniformParameterPtr Program::resolveAutoParameterInt(GpuProgramParameters::AutoConstantType autoType, GpuConstantType type,
UniformParameterPtr Program::resolveAutoParameterInt(GpuProgramParameters::AutoConstantType autoType, GpuConstantType type,
uint32 data, size_t size)
{
UniformParameterPtr param;
Expand All @@ -227,7 +227,7 @@ UniformParameterPtr Program::resolveAutoParameterInt(GpuProgramParameters::AutoC
}

//-----------------------------------------------------------------------------
UniformParameterPtr Program::resolveParameter(GpuConstantType type,
UniformParameterPtr Program::resolveParameter(GpuConstantType type,
int index, uint16 variability,
const String& suggestedName,
size_t size)
Expand Down Expand Up @@ -255,11 +255,11 @@ UniformParameterPtr Program::resolveParameter(GpuConstantType type,
// Check if parameter already exists.
param = getParameterByType(type, index);
if (param.get() != NULL)
{
return param;
{
return param;
}
}

// Create new parameter.
param = ParameterFactory::createUniform(type, index, variability, suggestedName, size);
addParameter(param);
Expand Down Expand Up @@ -305,14 +305,10 @@ UniformParameterPtr Program::getParameterByType(GpuConstantType type, int index)
//-----------------------------------------------------------------------------
UniformParameterPtr Program::getParameterByAutoType(GpuProgramParameters::AutoConstantType autoType)
{
UniformParameterIterator it;

for (it = mParameters.begin(); it != mParameters.end(); ++it)
for (const auto& p : mParameters)
{
if ((*it)->isAutoConstantParameter() && (*it)->getAutoConstantType() == autoType)
{
return *it;
}
if (p->isAutoConstantParameter() && p->getAutoConstantType() == autoType)
return p;
}

return UniformParameterPtr();
Expand Down
Loading

0 comments on commit 64bc666

Please sign in to comment.