示例#1
0
文件: renderer.cpp 项目: BennyQBD/GDX
std::vector<UniformData> Renderer::CreateShaderUniforms(const std::string& shaderText, unsigned int shaderProgram)
{
	static const std::string UNIFORM_KEY = "uniform";
    
	std::vector<UniformStruct> structs = FindUniformStructs(shaderText);

	std::vector<UniformData> result;

    size_t uniformLocation = shaderText.find(UNIFORM_KEY);
    while(uniformLocation != std::string::npos)
    {
        bool isCommented = false;
        size_t lastLineEnd = shaderText.rfind(";", uniformLocation);
        
        if(lastLineEnd != std::string::npos)
        {
            std::string potentialCommentSection = shaderText.substr(lastLineEnd,uniformLocation - lastLineEnd);
            isCommented = potentialCommentSection.find("//") != std::string::npos;
        }
        
        if(!isCommented)
        {
            size_t begin = uniformLocation + UNIFORM_KEY.length();
            size_t end = shaderText.find(";", begin);
            
            std::string uniformLine = shaderText.substr(begin + 1, end-begin - 1);
            
            begin = uniformLine.find(" ");
            std::string uniformName = uniformLine.substr(begin + 1);
            std::string uniformType = uniformLine.substr(0, begin);
            
            AddUniform(uniformName, uniformType, shaderProgram, structs, result);
        }
        uniformLocation = shaderText.find(UNIFORM_KEY, uniformLocation + UNIFORM_KEY.length());
    }

	return result;
}
示例#2
0
void ShaderData::AddShaderUniforms(const string& _shaderText) {
	static const string UNIFORM_KEY = "uniform";

	vector<UniformData> structs = FindUniformStructs(_shaderText);

	size_t uniformLocation = _shaderText.find(UNIFORM_KEY);
	while (uniformLocation != string::npos) {
		bool isCommented = false;
		size_t lastLineEnd = _shaderText.rfind("\n", uniformLocation);

		if (lastLineEnd != string::npos) {
			string potentialCommentSection = _shaderText.substr(lastLineEnd, uniformLocation - lastLineEnd);
			isCommented = potentialCommentSection.find("//") != string::npos;
		}

		if (!isCommented) {
			size_t begin = uniformLocation + UNIFORM_KEY.length();
			size_t end = _shaderText.find(";", begin);

			string uniformLine = _shaderText.substr(begin + 1, end - begin - 1);

			begin = uniformLine.find(" ");
			string uniformName = uniformLine.substr(begin + 1);
			string uniformType = uniformLine.substr(0, begin);

			size_t subscriptLocation = uniformName.find("[");
			if (subscriptLocation != string::npos) {
				uniformName = uniformName.substr(0, subscriptLocation);
			}

			uniformNames.push_back(uniformName);
			uniformTypes.push_back(uniformType);
			AddUniform(uniformName, uniformType, structs);
		}
		uniformLocation = _shaderText.find(UNIFORM_KEY, uniformLocation + UNIFORM_KEY.length());
	}
}