diff --git a/src/GLES2/GLSLCombiner_gles2.cpp b/src/GLES2/GLSLCombiner_gles2.cpp index 0363ff3a..08970ac0 100644 --- a/src/GLES2/GLSLCombiner_gles2.cpp +++ b/src/GLES2/GLSLCombiner_gles2.cpp @@ -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()) { diff --git a/src/OGL3X/GLSLCombiner_ogl3x.cpp b/src/OGL3X/GLSLCombiner_ogl3x.cpp index f4bee1df..316e9451 100644 --- a/src/OGL3X/GLSLCombiner_ogl3x.cpp +++ b/src/OGL3X/GLSLCombiner_ogl3x.cpp @@ -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(); diff --git a/src/ShaderUtils.cpp b/src/ShaderUtils.cpp index 5698ec9c..ba9b381a 100644 --- a/src/ShaderUtils.cpp +++ b/src/ShaderUtils.cpp @@ -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; } diff --git a/src/ShaderUtils.h b/src/ShaderUtils.h index d1ac762f..0f92394d 100644 --- a/src/ShaderUtils.h +++ b/src/ShaderUtils.h @@ -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