bool ParseText::loadShader(std:: string &filename)
{
fullFileName = rootDir +filename;
LOG_INFO( "ParseText","begin to open file" );
zip_file * file = zip_fopen( apkArchive, fullFileName .c_str(), 0);
if(file == NULL)
{
return false ;
}
LOG_INFO( "ParseText","end open file" );
//char data[];
int size = file->bytes_left ;
char *data = (char *)malloc( sizeof(char )*size);
int state;
state = zip_fread(file, ( void *)data, size);
LOG_INFO( "ParseText","begin to read file: %d, %d" , state, size);
if(state == 0)
{
return false ;
}
data[size]= '\0';
if(!load(data, size))
{
return false ;
}
return true ;
}
[[FX]]
// Samplers
sampler2D albedoMap;
// Contexts
context OVERLAY
{
BlendMode = Blend;
}
[[VS_OVERLAY]]
varying vec2 texCoords;
[[FS_OVERLAY]]
uniform vec4 olayColor;
bool ParseText::load( const char *data, int size)
{
//Parse sections
const char *pData = data;
const char *eof = data +size;
while (pData <eof)
{
if (pData < eof-1 && *pData == '['&&*(pData+1)== '[' )
{
pData += 2;
//Parse section name
const char *sectionNameStart = pData;
while (pData <eof && *pData != ']' && *pData != '\n' &&*pData !='\r' )++pData;
const char *sectionNameEnd = pData++;
//Check for correct closing of name
if (pData >= eof || *pData++!=']' ) return false;
//Parse content
const char *sectionContentStart = pData;
while ((pData < eof && *pData != '[')||(pData < eof-1&&*(pData+1)!='[' ))++pData;
const char *sectionContentEnd = pData;
if (sectionNameEnd - sectionNameStart == 2 &&
*sectionNameStart == 'F' &&*(sectionNameStart+1)=='X' )
{
//FX section
if (fxCode != 0x0) return false ;
fxCode = new char[sectionContentEnd - sectionContentStart+1];
memcpy ( (void *)fxCode , sectionContentStart, sectionContentEnd - sectionContentStart );
fxCode [sectionContentEnd - sectionContentStart] = '\0' ;
} else
{
}
} else
++pData;
}<pre name="code" class="plain">
albedoMap
;
context
OVERLAY
{
BlendMode
=
Blend
;
}
.....