|
|
@ -6,99 +6,55 @@ |
|
|
|
#include <d3d9.h> |
|
|
|
#include <d3d9.h> |
|
|
|
#include <d3dx9core.h> |
|
|
|
#include <d3dx9core.h> |
|
|
|
|
|
|
|
|
|
|
|
void ICreateHeader(const char* const varName, const char* const fileName, FILE* fp, LPD3DXBUFFER shader) |
|
|
|
void ICreateHeader(const plString& varName, const plFileName& fileName, FILE* fp, LPD3DXBUFFER shader) |
|
|
|
{ |
|
|
|
{ |
|
|
|
fprintf(fp, "\n\n\n"); |
|
|
|
fputs("\n\n\n", fp); |
|
|
|
|
|
|
|
|
|
|
|
int byteLen = shader->GetBufferSize(); |
|
|
|
int byteLen = shader->GetBufferSize(); |
|
|
|
int quadLen = byteLen >> 2; |
|
|
|
int quadLen = byteLen >> 2; |
|
|
|
|
|
|
|
|
|
|
|
unsigned char* codes = (unsigned char*)shader->GetBufferPointer(); |
|
|
|
unsigned char* codes = (unsigned char*)shader->GetBufferPointer(); |
|
|
|
|
|
|
|
|
|
|
|
fprintf(fp, "static const uint32_t %sbyteLen = %d;\n\n", varName, byteLen); |
|
|
|
plPrintf(fp, "static const uint32_t {}byteLen = {};\n\n", varName, byteLen); |
|
|
|
fprintf(fp, "static const uint8_t %sCodes[] = {\n", varName); |
|
|
|
plPrintf(fp, "static const uint8_t {}Codes[] = {\n", varName); |
|
|
|
|
|
|
|
|
|
|
|
int i; |
|
|
|
int i; |
|
|
|
for( i = 0; i < quadLen-1; i++ ) |
|
|
|
for( i = 0; i < quadLen-1; i++ ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
fprintf(fp, "\t0x%x,", *codes++); |
|
|
|
plPrintf(fp, "\t0x{x},", *codes++); |
|
|
|
fprintf(fp, "\t0x%x,", *codes++); |
|
|
|
plPrintf(fp, "\t0x{x},", *codes++); |
|
|
|
fprintf(fp, "\t0x%x,", *codes++); |
|
|
|
plPrintf(fp, "\t0x{x},", *codes++); |
|
|
|
fprintf(fp, "\t0x%x,\n", *codes++); |
|
|
|
plPrintf(fp, "\t0x{x},\n", *codes++); |
|
|
|
} |
|
|
|
} |
|
|
|
fprintf(fp, "\t0x%x,", *codes++); |
|
|
|
plPrintf(fp, "\t0x{x},", *codes++); |
|
|
|
fprintf(fp, "\t0x%x,", *codes++); |
|
|
|
plPrintf(fp, "\t0x{x},", *codes++); |
|
|
|
fprintf(fp, "\t0x%x,", *codes++); |
|
|
|
plPrintf(fp, "\t0x{x},", *codes++); |
|
|
|
fprintf(fp, "\t0x%x\n", *codes++); |
|
|
|
plPrintf(fp, "\t0x{x}\n", *codes++); |
|
|
|
fprintf(fp, "\t};"); |
|
|
|
fputs("\t};", fp); |
|
|
|
fprintf(fp, "\n\n"); |
|
|
|
fputs("\n\n", fp); |
|
|
|
|
|
|
|
|
|
|
|
fprintf(fp, "static const plShaderDecl %sDecl(\"%s\", %s, %sbyteLen, %sCodes);\n\n", varName, fileName, varName, varName, varName); |
|
|
|
plPrintf(fp, "static const plShaderDecl {}Decl(\"{}\", {}, {}byteLen, {}Codes);\n\n", |
|
|
|
fprintf(fp, "static const plShaderRegister %sRegister(&%sDecl);\n\n", varName, varName); |
|
|
|
varName, fileName, varName, varName, varName); |
|
|
|
|
|
|
|
plPrintf(fp, "static const plShaderRegister {}Register(&{}Decl);\n\n", varName, varName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) |
|
|
|
int main(int argc, char* argv[]) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if( argc < 2 ) |
|
|
|
if( argc < 2 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
printf("%s <file0> <file1> ...\n", argv[0]); |
|
|
|
plPrintf("{} <file0> <file1> ...\n", argv[0]); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
const char* const * nameList = 0L; |
|
|
|
|
|
|
|
|
|
|
|
const char* const * nameList = nullptr; |
|
|
|
int numNames = 0; |
|
|
|
int numNames = 0; |
|
|
|
if( !_stricmp(argv[1], "all") ) |
|
|
|
if (stricmp(argv[1], "all") == 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Cut and paste enum and add kNumEnumNames to end
|
|
|
|
|
|
|
|
// so you don't have to count.
|
|
|
|
|
|
|
|
enum { |
|
|
|
|
|
|
|
vs_WaveFixedFin6, |
|
|
|
|
|
|
|
ps_WaveFixed, |
|
|
|
|
|
|
|
vs_CompCosines, |
|
|
|
|
|
|
|
ps_CompCosines, |
|
|
|
|
|
|
|
vs_ShoreLeave6, |
|
|
|
|
|
|
|
ps_ShoreLeave6, |
|
|
|
|
|
|
|
vs_WaveRip, |
|
|
|
|
|
|
|
ps_WaveRip, |
|
|
|
|
|
|
|
vs_WaveDec1Lay, |
|
|
|
|
|
|
|
vs_WaveDec2Lay11, |
|
|
|
|
|
|
|
vs_WaveDec2Lay12, |
|
|
|
|
|
|
|
vs_WaveDecEnv, |
|
|
|
|
|
|
|
ps_CbaseAbase, |
|
|
|
|
|
|
|
ps_CalphaAbase, |
|
|
|
|
|
|
|
ps_CalphaAMult, |
|
|
|
|
|
|
|
ps_CalphaAadd, |
|
|
|
|
|
|
|
ps_CaddAbase, |
|
|
|
|
|
|
|
ps_CaddAMult, |
|
|
|
|
|
|
|
ps_CaddAAdd, |
|
|
|
|
|
|
|
ps_CmultAbase, |
|
|
|
|
|
|
|
ps_CmultAMult, |
|
|
|
|
|
|
|
ps_CmultAAdd, |
|
|
|
|
|
|
|
ps_WaveDecEnv, |
|
|
|
|
|
|
|
vs_WaveGraph2, |
|
|
|
|
|
|
|
ps_WaveGraph, |
|
|
|
|
|
|
|
vs_WaveGridFin, |
|
|
|
|
|
|
|
ps_WaveGrid, |
|
|
|
|
|
|
|
vs_BiasNormals, |
|
|
|
|
|
|
|
ps_BiasNormals, |
|
|
|
|
|
|
|
vs_ShoreLeave7, |
|
|
|
|
|
|
|
vs_WaveRip7, |
|
|
|
|
|
|
|
ps_MoreCosines, |
|
|
|
|
|
|
|
vs_WaveDec1Lay_7, |
|
|
|
|
|
|
|
vs_WaveDec2Lay11_7, |
|
|
|
|
|
|
|
vs_WaveDec2Lay12_7, |
|
|
|
|
|
|
|
vs_WaveDecEnv_7, |
|
|
|
|
|
|
|
vs_WaveFixedFin7, |
|
|
|
|
|
|
|
vs_GrassShader, |
|
|
|
|
|
|
|
ps_GrassShader, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
kNumEnumNames |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Just copy in the enum and use Replace on
|
|
|
|
// Just copy in the enum and use Replace on
|
|
|
|
// vs_ => "vs_
|
|
|
|
// vs_ => "vs_
|
|
|
|
// ps_ => "ps_
|
|
|
|
// ps_ => "ps_
|
|
|
|
// , => ",
|
|
|
|
// , => ",
|
|
|
|
const char* kEnumNames[kNumEnumNames] = { |
|
|
|
const char* kEnumNames[] = { |
|
|
|
"vs_WaveFixedFin6", |
|
|
|
"vs_WaveFixedFin6", |
|
|
|
"ps_WaveFixed", |
|
|
|
"ps_WaveFixed", |
|
|
|
"vs_CompCosines", |
|
|
|
"vs_CompCosines", |
|
|
@ -141,62 +97,54 @@ int main(int argc, char* argv[]) |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
nameList = kEnumNames; |
|
|
|
nameList = kEnumNames; |
|
|
|
numNames = kNumEnumNames; |
|
|
|
numNames = arrsize(kEnumNames); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
nameList = argv+1; |
|
|
|
nameList = argv+1; |
|
|
|
numNames = argc-1; |
|
|
|
numNames = argc-1; |
|
|
|
} |
|
|
|
} |
|
|
|
int i; |
|
|
|
|
|
|
|
for( i = 0; i < numNames; i++ ) |
|
|
|
for (int i = 0; i < numNames; i++ ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
const char* name = nameList[i]; |
|
|
|
const char* name = nameList[i]; |
|
|
|
|
|
|
|
plString varName = plFileName(name).StripFileExt().AsString(); |
|
|
|
|
|
|
|
|
|
|
|
char varName[512]; |
|
|
|
plFileName inFile = plFormat("{}.inl", varName); |
|
|
|
strcpy(varName, name); |
|
|
|
plFileName outFile = plFormat("{}.h", varName); |
|
|
|
char* p = strrchr(varName, '.'); |
|
|
|
|
|
|
|
if( p ) |
|
|
|
|
|
|
|
*p = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char inFile[512]; |
|
|
|
|
|
|
|
sprintf(inFile, "%s.inl", varName); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char outFile[512]; |
|
|
|
|
|
|
|
sprintf(outFile, "%s.h", varName); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("Processing %s into %s\n", name, outFile); |
|
|
|
plPrintf("Processing {} into {}\n", name, outFile); |
|
|
|
FILE* fp = fopen(outFile, "w"); |
|
|
|
FILE* fp = fopen(outFile.AsString().c_str(), "w"); |
|
|
|
if( !fp ) |
|
|
|
if (!fp) |
|
|
|
{ |
|
|
|
{ |
|
|
|
printf("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"); |
|
|
|
fputs("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", stdout); |
|
|
|
printf("Error opening file %s for output\n"); |
|
|
|
plPrintf("Error opening file %s for output\n", outFile); |
|
|
|
printf("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"); |
|
|
|
fputs("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", stdout); |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
LPD3DXBUFFER compiledShader = 0L; |
|
|
|
LPD3DXBUFFER compiledShader = nullptr; |
|
|
|
LPD3DXBUFFER compilationErrors = 0L; |
|
|
|
LPD3DXBUFFER compilationErrors = nullptr; |
|
|
|
DWORD flags = 0; |
|
|
|
DWORD flags = 0; |
|
|
|
LPD3DXINCLUDE include = 0L; |
|
|
|
LPD3DXINCLUDE include = nullptr; |
|
|
|
|
|
|
|
|
|
|
|
HRESULT hr = D3DXAssembleShaderFromFile( |
|
|
|
HRESULT hr = D3DXAssembleShaderFromFile( |
|
|
|
inFile, |
|
|
|
inFile.AsString().c_str(), |
|
|
|
0L, |
|
|
|
nullptr, |
|
|
|
include, |
|
|
|
include, |
|
|
|
flags, |
|
|
|
flags, |
|
|
|
&compiledShader, |
|
|
|
&compiledShader, |
|
|
|
&compilationErrors); |
|
|
|
&compilationErrors); |
|
|
|
|
|
|
|
|
|
|
|
if( FAILED(hr) ) |
|
|
|
if (FAILED(hr)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
printf("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"); |
|
|
|
fputs("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", stdout); |
|
|
|
printf(compilationErrors ? (char*)compilationErrors->GetBufferPointer() : "File not found"); |
|
|
|
fputs(compilationErrors ? (const char*)compilationErrors->GetBufferPointer() |
|
|
|
|
|
|
|
: "File not found", stdout); |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
sprintf(inFile, "sha/%s.inl", varName); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ICreateHeader(varName, inFile, fp, compiledShader); |
|
|
|
ICreateHeader(varName, plFormat("sha/{}.inl", varName), fp, compiledShader); |
|
|
|
|
|
|
|
|
|
|
|
fclose(fp); |
|
|
|
fclose(fp); |
|
|
|
|
|
|
|
|
|
|
|