103 lines
2.0 KiB
C++
103 lines
2.0 KiB
C++
//
|
|
// Test compiler for CgFX files
|
|
//
|
|
// only using for test,
|
|
//
|
|
// author : Florian Delizy Copyright Virtools (2004)
|
|
//
|
|
//
|
|
|
|
|
|
#define USE_CGFX_121
|
|
|
|
#include <iostream>
|
|
#include <cstdio>
|
|
#include <windows.h>
|
|
|
|
#include <CgFX/ICgFXEffect.h>
|
|
|
|
|
|
using namespace std;
|
|
|
|
int main (int argc,char ** argv, char **arge)
|
|
{
|
|
|
|
ICgFXEffect * compile = NULL;
|
|
const char * errors = NULL;
|
|
|
|
#ifdef USE_CGFX_121
|
|
char * options = NULL;
|
|
#endif
|
|
|
|
HRESULT h;
|
|
|
|
if (argc < 2)
|
|
{
|
|
cerr << "Usage " << argv[0] << "<file.fx> options" << endl;
|
|
cerr << " Where : " << endl;
|
|
cerr << " <file.fx> is the shader file to compile " << endl;
|
|
cerr << " options : are the cgc options" << endl;
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
|
|
#ifdef USE_CGFX_121
|
|
if (argc > 2) // options had been passed
|
|
{
|
|
for (int i = 2; i < argc; i++)
|
|
{
|
|
if (options)
|
|
{
|
|
options = (char *) realloc (options, strlen(options) + strlen(argv[i]) + 2); // space and '\0'
|
|
options = strcat(options, " ");
|
|
options = strcat(options, argv[i]);
|
|
} else {
|
|
options = strdup(argv[i]);
|
|
}
|
|
}
|
|
|
|
}
|
|
#endif
|
|
|
|
cout << "Invoquing compiler with filename : " << argv[1];
|
|
|
|
#ifdef USE_CGFX_121
|
|
if (options) cout << " options :" << options;
|
|
#endif
|
|
|
|
cout << endl;
|
|
|
|
|
|
#ifdef USE_CGFX_121
|
|
h = CgFXCreateEffectFromFileA(argv[1], (const char **) &options, &compile, &errors);
|
|
|
|
if (options)
|
|
{
|
|
free (options);
|
|
options = NULL;
|
|
}
|
|
#else
|
|
h = CgFXCreateEffectFromFileA(argv[1], 0, &compile, &errors);
|
|
#endif
|
|
|
|
if (errors)
|
|
{
|
|
cerr << "Compiler returned errors : " << endl << errors << endl;
|
|
if (SUCCEEDED(h)) return EXIT_SUCCESS;
|
|
else return EXIT_FAILURE;
|
|
}
|
|
|
|
cout << "Effect pointer value is : " << (int) compile << endl;
|
|
|
|
if (FAILED(h))
|
|
{
|
|
const char * errors = NULL;
|
|
CgFXGetErrors(&errors);
|
|
errors = errors ? errors : "No error returned";
|
|
cerr << "Effect creation failed, CgFXGetErrors returned : " << errors << endl;
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
if (compile) delete (compile);
|
|
return EXIT_SUCCESS;
|
|
} |