//============================================================ // <T>转换脚本。</T> // // @param pOutputScript 输出脚本 // @param pInputScript 输入脚本 // @return 处理结果 //============================================================ TResult FPoRenderShaderTransformer::Convert(MString* pOutputScript, MString* pInputScript){ Hlsl2Glsl_Initialize(); ShHandle parser = Hlsl2Glsl_ConstructCompiler(EShLangVertex); TInt parseOk = Hlsl2Glsl_Parse(parser, pInputScript->MemoryC(), ETargetGLSL_120, ETranslateOpIntermediate); TCharC* pInfo = Hlsl2Glsl_GetInfoLog(parser); if(parseOk){ TInt translateOk = Hlsl2Glsl_Translate(parser, "main", ETargetGLSL_120, ETranslateOpIntermediate); TCharC* infoLog = Hlsl2Glsl_GetInfoLog( parser ); if(translateOk){ TCharC* pGlslScript = Hlsl2Glsl_GetShader(parser); pOutputScript->Assign(pGlslScript); } } Hlsl2Glsl_DestructCompiler(parser); Hlsl2Glsl_Shutdown(); return ESuccess; }
int main (int argc, const char** argv) { if (argc < 2) { printf ("USAGE: hlsl2glsltest testfolder\n"); return 1; } bool hasOpenGL = InitializeOpenGL (); if (!hasOpenGL) printf("NOTE: will not check GLSL with actual driver (no GL/GLSL)\n"); clock_t time0 = clock(); Hlsl2Glsl_Initialize (); std::string baseFolder = argv[1]; size_t tests = 0; size_t errors = 0; for (int type = 0; type < NUM_RUN_TYPES; ++type) { printf ("TESTING %s...\n", kTypeName[type]); const ETargetVersion version1 = kTargets1[type]; const ETargetVersion version2 = kTargets2[type]; const ETargetVersion version3 = kTargets3[type]; std::string testFolder = baseFolder + "/" + kTypeName[type]; StringVector inputFiles = GetFiles (testFolder, "-in.txt"); size_t n = inputFiles.size(); tests += n; for (size_t i = 0; i < n; ++i) { std::string inname = inputFiles[i]; //if (inname != "_zzz-in.txt") // continue; const bool preprocessorTest = (inname.find("pp-") == 0); bool ok = true; printf ("test %s\n", inname.c_str()); if (type == BOTH) { ok = TestCombinedFile(testFolder + "/" + inname, version1, hasOpenGL); if (ok && version2 != ETargetVersionCount) ok = TestCombinedFile(testFolder + "/" + inname, version2, hasOpenGL); } else { ok = TestFile(TestRun(type), testFolder + "/" + inname, version1, 0, hasOpenGL); if (!preprocessorTest) { if (ok && version2 != ETargetVersionCount) ok = TestFile(TestRun(type), testFolder + "/" + inname, version2, ETranslateOpEmitGLSL120ArrayInitWorkaround, hasOpenGL); if (ok && version3 != ETargetVersionCount) ok = TestFile(TestRun(type), testFolder + "/" + inname, version3, 0, hasOpenGL); } } if (!ok) ++errors; } } clock_t time1 = clock(); float t = float(time1-time0) / float(CLOCKS_PER_SEC); if (errors != 0) printf ("%i tests, %i FAILED, %.2fs\n", (int)tests, (int)errors, t); else printf ("%i tests succeeded, %.2fs\n", (int)tests, t); Hlsl2Glsl_Shutdown(); CleanupOpenGL(); return errors ? 1 : 0; }