예제 #1
0
파일: renderer.cpp 프로젝트: BennyQBD/GDX
unsigned int Renderer::CreateFragmentShader(const std::string& shaderText)
{
	std::string version = GetSpecifiedVersion(shaderText);
    
    size_t vertexShaderKeyLocation = shaderText.find("void VSmain()");
    size_t fragmentShaderKeyLocation = shaderText.find("void FSmain()");

    std::string fragmentShaderText = std::string(shaderText);
    String_FindAndReplace(fragmentShaderText, "void FSmain()", "void main()");
        
    if(vertexShaderKeyLocation != std::string::npos)
            EraseShaderFunction(fragmentShaderText, "void VSmain()");
        
    String_ReplaceAll(fragmentShaderText, "attribute", "", "\n");
        
    if(version.compare("330") == 0)
	{
        String_ReplaceAll(fragmentShaderText, "varying", "in");
		String_FindAndReplace(fragmentShaderText, "gl_FragColor", "OUT_Fragment_Color");

		std::string newFragout = "out vec4 OUT_Fragment_Color;\n";
		size_t start = fragmentShaderText.find("\n");
		fragmentShaderText.replace(start + 1,0,newFragout);
	}

    return CreateShader(fragmentShaderText, GL_FRAGMENT_SHADER);
}
예제 #2
0
파일: Downloader.c 프로젝트: tindzk/podfm
static sdef(String, Sanitize, String name) {
	String out = String_Clone(name);

	String_ReplaceAll(&out, $("?"),  $(" "));
	String_ReplaceAll(&out, $(":"),  $(" "));
	String_ReplaceAll(&out, $("/"),  $("-"));
	String_ReplaceAll(&out, $("  "), $(" "));

	String_Copy(&out, String_Trim(out));

	if (String_EndsWith(out, $("."))) {
		out.len--;
	}

	return out;
}
예제 #3
0
파일: renderer.cpp 프로젝트: BennyQBD/GDX
unsigned int Renderer::CreateVertexShader(const std::string& shaderText)
{
    std::string version = GetSpecifiedVersion(shaderText);
    
    size_t vertexShaderKeyLocation = shaderText.find("void VSmain()");
    size_t fragmentShaderKeyLocation = shaderText.find("void FSmain()");
    
    std::string vertexShaderText = std::string(shaderText);
    String_FindAndReplace(vertexShaderText, "void VSmain()", "void main()");
        
    if(fragmentShaderKeyLocation != std::string::npos)
        EraseShaderFunction(vertexShaderText, "void FSmain()");
        
    if(version.compare("330") == 0)
    {
        String_ReplaceAll(vertexShaderText, "attribute", "layout(location = %d) in", "", 0, true);
        String_ReplaceAll(vertexShaderText, "varying", "out");
    }

    return CreateShader(vertexShaderText, GL_VERTEX_SHADER);
	//std::string vertexShaderText = "#version 330\n\n";
	//std::string token = "";
	//std::string lastToken = "";
	//size_t tokenLocation = String_NextToken(shaderText, 0, &token);

	//bool appendNext = false;
	//int attributeCounter = 0;
	//std::string nextAppendEnding = "";
	//std::string nextAppendBefore = "";
	//std::string appendBefore = "";

	//while(tokenLocation != 0)
	//{
	//	if(appendNext)
	//	{
	//		appendNext = false;
	//		vertexShaderText += (nextAppendBefore + token + nextAppendEnding);
	//		continue;
	//	}

	//	if(token.compare("cbuffer") == 0)
	//		appendBefore = "uniform ";
	//	if(token.compare("}") == 0)
	//	{
	//		nextAppendBefore = "";
	//		appendBefore = "";
	//	}

	//	if(lastToken.compare("struct") == 0 && token.compare("VS_IN") == 0)
	//	{
	//		appendBefore = "layout (location = 0) in ";
	//		nextAppendBefore = "VS_IN_";
	//	}

	//	if(lastToken.compare("struct") == 0 && token.compare("PS_IN") == 0)
	//	{
	//		appendBefore = "out ";
	//		nextAppendBefore = "";
	//	}

	//	if(token.compare("Texture2D") == 0)
	//	{
	//		appendNext = true;
	//		vertexShaderText += "uniform sampler2D ";
	//		nextAppendEnding = ";\n";
	//	}

	//	if(token.compare("matrix") == 0)
	//	{
	//		appendNext = true;
	//		vertexShaderText += (appendBefore + "mat4 ");
	//		nextAppendEnding = ";\n";
	//	}

	//	if(token.compare("float4") == 0)
	//	{
	//		appendNext = true;
	//		vertexShaderText += (appendBefore + "vec4 ");
	//		nextAppendEnding = ";\n";
	//	}

	//	if(token.compare("float2") == 0)
	//	{
	//		appendNext = true;
	//		vertexShaderText += (appendBefore + "vec2 ");
	//		nextAppendEnding = ";\n";
	//	}

	//	//vertexShaderText += token;
	//	//vertexShaderText += " ";

	//	//if(token.compare(";") == 0)
	//	//	vertexShaderText += "\n";
	//	//if(lastToken.compare("}") == 0)
	//	//	vertexShaderText += "\n";

	//	lastToken = token;
	//	tokenLocation = String_NextToken(shaderText, tokenLocation, &token);
	//	std::cout << token << std::endl;
	//}

	//std::cout << vertexShaderText << std::endl;

	//return 0;
}