mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-04 10:03:36 +00:00
Code refactor: use std::string instead of plain char buffer in compileCombiner.
This commit is contained in:
parent
b7369e905e
commit
9d8ef24777
|
@ -145,7 +145,7 @@ void DestroyShaderCombiner() {
|
|||
|
||||
ShaderCombiner::ShaderCombiner(Combiner & _color, Combiner & _alpha, const gDPCombine & _combine) : m_combine(_combine)
|
||||
{
|
||||
char strCombiner[2048];
|
||||
std::string strCombiner;
|
||||
m_nInputs = compileCombiner(_color, _alpha, strCombiner);
|
||||
|
||||
if (usesTexture()) {
|
||||
|
|
|
@ -282,7 +282,7 @@ ShaderCombiner::ShaderCombiner() : m_bNeedUpdate(true)
|
|||
|
||||
ShaderCombiner::ShaderCombiner(Combiner & _color, Combiner & _alpha, const gDPCombine & _combine) : m_combine(_combine), m_bNeedUpdate(true)
|
||||
{
|
||||
char strCombiner[2048];
|
||||
std::string strCombiner;
|
||||
m_nInputs = compileCombiner(_color, _alpha, strCombiner);
|
||||
|
||||
const bool bUseLod = usesLOD();
|
||||
|
|
|
@ -185,7 +185,7 @@ void _correctSecondStageParams(CombinerStage & _stage) {
|
|||
}
|
||||
|
||||
static
|
||||
int _compileCombiner(const CombinerStage & _stage, const char** _Input, char * _strCombiner) {
|
||||
int _compileCombiner(const CombinerStage & _stage, const char** _Input, std::string & _strShader) {
|
||||
char buf[128];
|
||||
bool bBracketOpen = false;
|
||||
int nRes = 0;
|
||||
|
@ -193,7 +193,7 @@ int _compileCombiner(const CombinerStage & _stage, const char** _Input, char * _
|
|||
switch (_stage.op[i].op) {
|
||||
case LOAD:
|
||||
sprintf(buf, "(%s ", _Input[_stage.op[i].param1]);
|
||||
strcat(_strCombiner, buf);
|
||||
_strShader += buf;
|
||||
bBracketOpen = true;
|
||||
nRes |= 1 << _stage.op[i].param1;
|
||||
break;
|
||||
|
@ -204,7 +204,7 @@ int _compileCombiner(const CombinerStage & _stage, const char** _Input, char * _
|
|||
}
|
||||
else
|
||||
sprintf(buf, "- %s", _Input[_stage.op[i].param1]);
|
||||
strcat(_strCombiner, buf);
|
||||
_strShader += buf;
|
||||
nRes |= 1 << _stage.op[i].param1;
|
||||
break;
|
||||
case ADD:
|
||||
|
@ -214,7 +214,7 @@ int _compileCombiner(const CombinerStage & _stage, const char** _Input, char * _
|
|||
}
|
||||
else
|
||||
sprintf(buf, "+ %s", _Input[_stage.op[i].param1]);
|
||||
strcat(_strCombiner, buf);
|
||||
_strShader += buf;
|
||||
nRes |= 1 << _stage.op[i].param1;
|
||||
break;
|
||||
case MUL:
|
||||
|
@ -224,12 +224,12 @@ int _compileCombiner(const CombinerStage & _stage, const char** _Input, char * _
|
|||
}
|
||||
else
|
||||
sprintf(buf, "*%s", _Input[_stage.op[i].param1]);
|
||||
strcat(_strCombiner, buf);
|
||||
_strShader += buf;
|
||||
nRes |= 1 << _stage.op[i].param1;
|
||||
break;
|
||||
case INTER:
|
||||
sprintf(buf, "mix(%s, %s, %s)", _Input[_stage.op[0].param2], _Input[_stage.op[0].param1], _Input[_stage.op[0].param3]);
|
||||
strcat(_strCombiner, buf);
|
||||
_strShader += buf;
|
||||
nRes |= 1 << _stage.op[i].param1;
|
||||
nRes |= 1 << _stage.op[i].param2;
|
||||
nRes |= 1 << _stage.op[i].param3;
|
||||
|
@ -240,21 +240,21 @@ int _compileCombiner(const CombinerStage & _stage, const char** _Input, char * _
|
|||
}
|
||||
}
|
||||
if (bBracketOpen)
|
||||
strcat(_strCombiner, ")");
|
||||
strcat(_strCombiner, "; \n");
|
||||
_strShader.append(")");
|
||||
_strShader.append("; \n");
|
||||
return nRes;
|
||||
}
|
||||
|
||||
int compileCombiner(Combiner & _color, Combiner & _alpha, char * _strShader)
|
||||
int compileCombiner(Combiner & _color, Combiner & _alpha, std::string & _strShader)
|
||||
{
|
||||
if (gDP.otherMode.cycleType == G_CYC_1CYCLE) {
|
||||
_correctFirstStageParams(_alpha.stage[0]);
|
||||
_correctFirstStageParams(_color.stage[0]);
|
||||
}
|
||||
strcpy(_strShader, " alpha1 = ");
|
||||
_strShader.append(" alpha1 = ");
|
||||
int nInputs = _compileCombiner(_alpha.stage[0], AlphaInput, _strShader);
|
||||
|
||||
strcat(_strShader,
|
||||
_strShader.append(
|
||||
" if (uEnableAlphaTest != 0) { \n"
|
||||
" lowp float alphaTestValue = (uAlphaCompareMode == 3) ? snoise() : uAlphaTestValue; \n"
|
||||
" lowp float alphaValue = alpha1; \n"
|
||||
|
@ -269,24 +269,24 @@ int compileCombiner(Combiner & _color, Combiner & _alpha, char * _strShader)
|
|||
" } \n"
|
||||
);
|
||||
|
||||
strcat(_strShader, " color1 = ");
|
||||
_strShader.append(" color1 = ");
|
||||
nInputs |= _compileCombiner(_color.stage[0], ColorInput, _strShader);
|
||||
strcat(_strShader, fragment_shader_blender);
|
||||
_strShader.append(fragment_shader_blender);
|
||||
|
||||
strcat(_strShader, " combined_color = vec4(color1, alpha1); \n");
|
||||
_strShader.append(" combined_color = vec4(color1, alpha1); \n");
|
||||
if (_alpha.numStages == 2) {
|
||||
strcat(_strShader, " alpha2 = ");
|
||||
_strShader.append(" alpha2 = ");
|
||||
_correctSecondStageParams(_alpha.stage[1]);
|
||||
nInputs |= _compileCombiner(_alpha.stage[1], AlphaInput, _strShader);
|
||||
}
|
||||
else
|
||||
strcat(_strShader, " alpha2 = alpha1; \n");
|
||||
_strShader.append(" alpha2 = alpha1; \n");
|
||||
if (_color.numStages == 2) {
|
||||
strcat(_strShader, " color2 = ");
|
||||
_strShader.append(" color2 = ");
|
||||
_correctSecondStageParams(_color.stage[1]);
|
||||
nInputs |= _compileCombiner(_color.stage[1], ColorInput, _strShader);
|
||||
}
|
||||
else
|
||||
strcat(_strShader, " color2 = color1; \n");
|
||||
_strShader.append(" color2 = color1; \n");
|
||||
return nInputs;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,6 @@ GLuint createShaderProgram(const char * _strVertex, const char * _strFragment);
|
|||
bool checkShaderCompileStatus(GLuint obj);
|
||||
bool checkProgramLinkStatus(GLuint obj);
|
||||
void logErrorShader(GLenum _shaderType, const std::string & _strShader);
|
||||
int compileCombiner(Combiner & _color, Combiner & _alpha, char * _strShader);
|
||||
int compileCombiner(Combiner & _color, Combiner & _alpha, std::string & _strShader);
|
||||
|
||||
#endif // SHADER_UTILS_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user