wxString GLVertexDecompilerThread::BuildCode() { wxString p = wxEmptyString; for(u32 i=0; i<m_parr.params.GetCount(); ++i) { p += m_parr.params[i].Format(); } wxString fp = wxEmptyString; for(int i=m_funcs.GetCount() - 1; i>=0; --i) { fp += wxString::Format("void %s();\n", m_funcs[i].name.mb_str()); } wxString f = wxEmptyString; f += wxString::Format("void %s()\n{\n\tgl_Position = vec4(0.0f, 0.0f, 0.0f, 1.0f);\n%s}\n", m_funcs[0].name.mb_str(), BuildFuncBody(m_funcs[0]).mb_str()); for(uint i=1; i<m_funcs.GetCount(); ++i) { f += wxString::Format("\nvoid %s()\n{\n%s}\n", m_funcs[i].name.mb_str(), BuildFuncBody(m_funcs[i]).mb_str()); } static const wxString& prot = "#version 330\n" "\n" "%s\n" "%s\n" "%s"; return wxString::Format(prot, p.mb_str(), fp.mb_str(), f.mb_str()); }
std::string GLVertexDecompilerThread::BuildCode() { std::string p; for(u32 i=0; i<m_parr.params.size(); ++i) { p += m_parr.params[i].Format(); } std::string fp; for(int i=m_funcs.size() - 1; i>0; --i) { fp += fmt::Format("void %s();\n", m_funcs[i].name.c_str()); } std::string f; f += fmt::Format("void %s()\n{\n\tgl_Position = vec4(0.0f, 0.0f, 0.0f, 1.0f);\n\t%s();\n\tgl_Position = gl_Position * scaleOffsetMat;\n}\n", m_funcs[0].name.c_str(), m_funcs[1].name.c_str()); for(uint i=1; i<m_funcs.size(); ++i) { f += fmt::Format("\nvoid %s()\n{\n%s}\n", m_funcs[i].name.c_str(), BuildFuncBody(m_funcs[i]).c_str()); } static const std::string& prot = "#version 330\n" "\n" "uniform mat4 scaleOffsetMat = mat4(1.0);\n" "%s\n" "%s\n" "%s"; return fmt::Format(prot, p.c_str(), fp.c_str(), f.c_str()); }
std::string GLVertexDecompilerThread::BuildCode() { struct reg_info { std::string name; bool need_declare; std::string src_reg; std::string src_reg_mask; bool need_cast; }; static const reg_info reg_table[] = { { "gl_Position", false, "dst_reg0", "", false }, { "diff_color", true, "dst_reg1", "", false }, { "spec_color", true, "dst_reg2", "", false }, { "front_diff_color", true, "dst_reg3", "", false }, { "front_spec_color", true, "dst_reg4", "", false }, { "fogc", true, "dst_reg5", ".x", true }, { "gl_ClipDistance[0]", false, "dst_reg5", ".y", false }, { "gl_ClipDistance[1]", false, "dst_reg5", ".z", false }, { "gl_ClipDistance[2]", false, "dst_reg5", ".w", false }, { "gl_PointSize", false, "dst_reg6", ".x", false }, { "gl_ClipDistance[3]", false, "dst_reg6", ".y", false }, { "gl_ClipDistance[4]", false, "dst_reg6", ".z", false }, { "gl_ClipDistance[5]", false, "dst_reg6", ".w", false }, { "tc0", true, "dst_reg7", "", false }, { "tc1", true, "dst_reg8", "", false }, { "tc2", true, "dst_reg9", "", false }, { "tc3", true, "dst_reg10", "", false }, { "tc4", true, "dst_reg11", "", false }, { "tc5", true, "dst_reg12", "", false }, { "tc6", true, "dst_reg13", "", false }, { "tc7", true, "dst_reg14", "", false }, { "tc8", true, "dst_reg15", "", false }, { "tc9", true, "dst_reg6", "", false } }; std::string f; for (auto &i : reg_table) { if (m_parr.HasParam(PARAM_NONE, "vec4", i.src_reg)) { if (i.need_declare) { m_parr.AddParam(PARAM_OUT, "vec4", i.name); } if (i.need_cast) { f += "\t" + i.name + " = vec4(" + i.src_reg + i.src_reg_mask + ");\n"; } else { f += "\t" + i.name + " = " + i.src_reg + i.src_reg_mask + ";\n"; } } } std::string p; for (u32 i = 0; i<m_parr.params.size(); ++i) { p += m_parr.params[i].Format(); } std::string fp; for (int i = m_funcs.size() - 1; i>0; --i) { fp += fmt::Format("void %s();\n", m_funcs[i].name.c_str()); } f = fmt::Format("void %s()\n{\n\t%s();\n%s\tgl_Position = gl_Position * scaleOffsetMat;\n}\n", m_funcs[0].name.c_str(), m_funcs[1].name.c_str(), f.c_str()); std::string main_body; for (uint i = 0, lvl = 1; i < m_instr_count; i++) { lvl -= m_instructions[i].close_scopes; if (lvl < 1) lvl = 1; //assert(lvl >= 1); for (uint j = 0; j < m_instructions[i].put_close_scopes; ++j) { --lvl; if (lvl < 1) lvl = 1; main_body.append(lvl, '\t') += "}\n"; } for (uint j = 0; j < m_instructions[i].do_count; ++j) { main_body.append(lvl, '\t') += "do\n"; main_body.append(lvl, '\t') += "{\n"; lvl++; } for (uint j = 0; j < m_instructions[i].body.size(); ++j) { main_body.append(lvl, '\t') += m_instructions[i].body[j] + "\n"; } lvl += m_instructions[i].open_scopes; } f += fmt::Format("\nvoid %s()\n{\n%s}\n", m_funcs[1].name.c_str(), main_body.c_str()); for(uint i=2; i<m_funcs.size(); ++i) { f += fmt::Format("\nvoid %s()\n{\n%s}\n", m_funcs[i].name.c_str(), BuildFuncBody(m_funcs[i]).c_str()); } static const std::string& prot = "#version 330\n" "\n" "uniform mat4 scaleOffsetMat = mat4(1.0);\n" "%s\n" "%s\n" "%s"; return fmt::Format(prot, p.c_str(), fp.c_str(), f.c_str()); }