コード例 #1
0
void CBspMapResourceProvider::LoadShaders(CPakFile& pakFile)
{
	CPakFile::FileNameList shaderFileNames = pakFile.GetFileNamesMatching(".shader");
	for(CPakFile::FileNameList::const_iterator fileNameIterator(shaderFileNames.begin());
		fileNameIterator != shaderFileNames.end(); fileNameIterator++)
	{
		const std::string& shaderFileName(*fileNameIterator);

		uint8* fileData(NULL);
		uint32 fileSize(0);
		if(!pakFile.ReadFile(shaderFileName.c_str(), &fileData, &fileSize))
		{
			continue;
		}

		std::string shaderString(fileData, fileData + fileSize);

		delete fileData;

		QuakeShaderList shaders = CQuakeShaderParser::ParseShaders(shaderString.c_str());
		for(QuakeShaderList::const_iterator shaderIterator(shaders.begin());
			shaderIterator != shaders.end(); shaderIterator++)
		{
			m_shaders[shaderIterator->name] = *shaderIterator;
		}
	}
}
コード例 #2
0
ファイル: Shader.cpp プロジェクト: cginternals/globjects
bool Shader::checkCompileStatus() const
{
    GLboolean status = static_cast<GLboolean>(get(GL_COMPILE_STATUS));

    if (status == GL_FALSE)
    {
        critical()
            << "Compiler error:" << std::endl
            << shaderString() << std::endl
            << infoLog();

        return false;
    }

    return true;
}
コード例 #3
0
ファイル: cm_utils.cpp プロジェクト: colormotor/colormotor
std::string shaderString( const std::string& path )
{
	std::string out="";
	FILE * f = fopen( path.c_str(), "r" );
	
	if( !f )
	{
		printf("Could not load %s\n", path.c_str());
		return out;
	}
	
	int size = getFileSize(f);
	
	char * fstr = new char[size+1];
	fread(fstr,1,size,f);
	fstr[size] = '\0';
	
	std::string str = fstr;
	delete [] fstr;
	fclose(f);
	
	// search for includes
	int  cur = 0;
	int ind = 0;
	
	while(true)
	{
		ind = str.find("#include",cur);
		if( ind == -1)
			break;
			
		// be sure line isnt commented... hack just checking for one /
		// TODO should have comment blocks too... search for  searchComment function...
		int newline = str.rfind('\n',ind); 
		int comm = str.rfind('/',ind);
		if( comm > newline )
		{
			continue;
		}
		
		// add stuff in the middle
		if( ind > cur )
			out+=str.substr(cur,ind-cur-1);
		
		int b1 = str.find('\"',ind);
		if( b1 == -1)
		{
			printf("Shader preprocessor error: expected \" after #include 'n");
			return "";
		}
		
		int b2 = str.find('\"',b1+1);
		if( b2 == -1)
		{
			printf("Shader preprocessor error: expected \" \n");
			return "";
		}
		
		cur = str.find('\n',b2);
		if( cur == -1 )
		{
			printf("Shader preprocessor error expected new line \n");
			return "";
		}
		
		std::string incPath = str.substr(b1+1,b2-b1-1);//,)
		
		std::string included = shaderString(incPath.c_str()) ;
		out+=included;
		
	}

	// append remaining stuff
	
	if( cur < (int)str.size() )
	{
		std::string sub =  str.substr(cur,str.size()-cur);
		
		out += sub;//str.substr(cur,str.size()-cur-1);
		//debugPrint("%s\n",out.c_str());
	}

	return out;
}