コード例 #1
0
ファイル: snd_shader.cpp プロジェクト: Deepfreeze32/taken
/*
===============
idSoundShader::Parse

  this is called by the declManager
===============
*/
bool idSoundShader::Parse( const char *text, const int textLength, bool allowBinaryVersion ) {
	idLexer	src;

	src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
	src.SetFlags( DECL_LEXER_FLAGS );
	src.SkipUntilString( "{" );

	if ( !ParseShader( src ) ) {
		MakeDefault();
		return false;
	}
	return true;
}
コード例 #2
0
ファイル: snd_shader.cpp プロジェクト: tankorsmash/quadcow
/*
===============
idSoundShader::Parse

  this is called by the declManager
===============
*/
bool idSoundShader::Parse( const char *text, const int textLength ) {
	idLexer	src;

	src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
	src.SetFlags( DECL_LEXER_FLAGS );
	src.SkipUntilString( "{" );

	// deeper functions can set this, which will cause MakeDefault() to be called at the end
	errorDuringParse = false;

	if ( !ParseShader( src ) || errorDuringParse ) {
		MakeDefault();
		return false;
	}
	return true;
}
コード例 #3
0
ファイル: test.cpp プロジェクト: eulex/libglslpp
bool _test_shader_(char *shader, const _test_type_list_& list) {
	GLuint program = ParseShader(shader);
	if (program) {

		glUseProgram(program);

		glBegin(GL_QUADS);

		glVertex2s(-1, -1);

		glVertex2s(1, -1);

		glVertex2s(1, 1);

		glVertex2s(-1, 1);

		glEnd();

		checkGLErrors();

		glFlush();

		for (unsigned x = 0; x < list.size(); ++x) {
			float test[4], e[4], a[4];
			glReadPixels(x, 0, 1, 1, GL_RGBA, GL_FLOAT, test);
			glReadPixels(x, 1, 1, 1, GL_RGBA, GL_FLOAT, e);
			glReadPixels(x, 2, 1, 1, GL_RGBA, GL_FLOAT, a);
			if (test[0] != 1.0f) {
				std::cout << "OpenGL GLSL subtest #" << x << " failed" << std::endl;
				if (test[0] == 2.0f) { // expected/actual available
					std::cout << "expected " << e[0] << " " << e[1] << " " << e[2] << " " << e[3]
					          << ", actual " << a[0] << " " << a[1] << " " << a[2] << " " << a[3]
					          << ", diff " << a[0]-e[0] << " " << a[1]-e[1] << " " << a[2]-e[2] << " " << a[3]-e[3]
					          << std::endl;
				}
				return false;
			}
		}
		return true;
	}
	return false;
}
コード例 #4
0
/*!***************************************************************************
 @Function			Parse
 @Output			pReturnError	error string
 @Return			bool			true for success parsing file
 @Description		Parses a loaded PFX file.
*****************************************************************************/
bool CPVRTPFXParser::Parse(CPVRTString * const pReturnError)
{
	int nEndLine = 0;
	int nHeaderCounter = 0, nTexturesCounter = 0;
	unsigned int i,j,k;
	m_nNumVertShaders	= 0;
	m_nNumFragShaders	= 0;
	m_nNumEffects		= 0;

	// Loop through the file
	for(unsigned int nLine=0; nLine < m_psContext->nNumLines; nLine++)
	{
		// Skip blank lines
		if(!*m_psContext->ppszEffectFile[nLine])
			continue;

		if(strcmp("[HEADER]", m_psContext->ppszEffectFile[nLine]) == 0)
		{
			if(nHeaderCounter>0)
			{
				sprintf(errorMsg, "[HEADER] redefined on line %d\n", m_psContext->pnFileLineNumber[nLine]);
				*pReturnError = errorMsg;
				return false;
			}
			if(GetEndTag("HEADER", nLine, &nEndLine))
			{
				if(ParseHeader(nLine, nEndLine, pReturnError))
					nHeaderCounter++;
				else
					return false;
			}
			else
			{
				sprintf(errorMsg, "Missing [/HEADER] tag after [HEADER] on line %d\n", m_psContext->pnFileLineNumber[nLine]);
				*pReturnError = errorMsg;
				return false;
			}
			nLine = nEndLine;
		}
		else if(strcmp("[TEXTURES]", m_psContext->ppszEffectFile[nLine]) == 0)
		{
			if(nTexturesCounter>0)
			{
				sprintf(errorMsg, "[TEXTURES] redefined on line %d\n", m_psContext->pnFileLineNumber[nLine]);
				*pReturnError = errorMsg;
				return false;
			}
			if(GetEndTag("TEXTURES", nLine, &nEndLine))
			{
				if(ParseTextures(nLine, nEndLine, pReturnError))
					nTexturesCounter++;
				else
					return false;
			}
			else
			{
				sprintf(errorMsg, "Missing [/TEXTURES] tag after [TEXTURES] on line %d\n", m_psContext->pnFileLineNumber[nLine]);
				*pReturnError = errorMsg;
				return false;
			}
			nLine = nEndLine;
		}
		else if(strcmp("[VERTEXSHADER]", m_psContext->ppszEffectFile[nLine]) == 0)
		{
			if(GetEndTag("VERTEXSHADER", nLine, &nEndLine))
			{
				if(m_nNumVertShaders >= m_nMaxVertShaders)
				{
					sprintf(errorMsg, "%d vertex shaders read, can't store any more, on line %d\n", m_nNumVertShaders, m_psContext->pnFileLineNumber[nLine]);
					*pReturnError = errorMsg;
					return false;
				}
				if(ParseShader(nLine, nEndLine, pReturnError, m_psVertexShader[m_nNumVertShaders], "VERTEXSHADER"))
					m_nNumVertShaders++;
				else
				{
					FREE(m_psVertexShader[m_nNumVertShaders].pszName);
					FREE(m_psVertexShader[m_nNumVertShaders].pszGLSLfile);
					FREE(m_psVertexShader[m_nNumVertShaders].pszGLSLcode);
					FREE(m_psVertexShader[m_nNumVertShaders].pszGLSLBinaryFile);
					return false;
				}
			}
			else
			{
				sprintf(errorMsg, "Missing [/VERTEXSHADER] tag after [VERTEXSHADER] on line %d\n", m_psContext->pnFileLineNumber[nLine]);
				*pReturnError = errorMsg;
				return false;
			}
			nLine = nEndLine;
		}
		else if(strcmp("[FRAGMENTSHADER]", m_psContext->ppszEffectFile[nLine]) == 0)
		{
			if(GetEndTag("FRAGMENTSHADER", nLine, &nEndLine))
			{
				if(m_nNumFragShaders >= m_nMaxFragShaders)
				{
					sprintf(errorMsg, "%d fragment shaders read, can't store any more, on line %d\n", m_nNumFragShaders, m_psContext->pnFileLineNumber[nLine]);
					*pReturnError = errorMsg;
					return false;
				}
				if(ParseShader(nLine, nEndLine, pReturnError, m_psFragmentShader[m_nNumFragShaders], "FRAGMENTSHADER"))
					m_nNumFragShaders++;
				else
				{
					FREE(m_psFragmentShader[m_nNumFragShaders].pszName);
					FREE(m_psFragmentShader[m_nNumFragShaders].pszGLSLfile);
					FREE(m_psFragmentShader[m_nNumFragShaders].pszGLSLcode);
					FREE(m_psFragmentShader[m_nNumFragShaders].pszGLSLBinaryFile);
					return false;
				}
			}
			else
			{
				sprintf(errorMsg, "Missing [/FRAGMENTSHADER] tag after [FRAGMENTSHADER] on line %d\n", m_psContext->pnFileLineNumber[nLine]);
				*pReturnError = errorMsg;
				return false;
			}
			nLine = nEndLine;
		}
		else if(strcmp("[EFFECT]", m_psContext->ppszEffectFile[nLine]) == 0)
		{
			if(GetEndTag("EFFECT", nLine, &nEndLine))
			{
				if(m_nNumEffects >= m_nMaxEffects)
				{
					sprintf(errorMsg, "%d effects read, can't store any more, on line %d\n", m_nNumEffects, m_psContext->pnFileLineNumber[nLine]);
					*pReturnError = errorMsg;
					return false;
				}
				if(ParseEffect(m_psEffect[m_nNumEffects], nLine, nEndLine, pReturnError))
					m_nNumEffects++;
				else
				{
					for(i=0; i < m_psEffect[m_nNumEffects].nNumUniforms; ++i)
					{
						FREE(m_psEffect[m_nNumEffects].psUniform[i].pszName);
						FREE(m_psEffect[m_nNumEffects].psUniform[i].pszValue);
					}
					delete [] m_psEffect[m_nNumEffects].psUniform;

					for(i=0; i < m_psEffect[m_nNumEffects].nNumAttributes; ++i)
					{
						FREE(m_psEffect[m_nNumEffects].psAttribute[i].pszName);
						FREE(m_psEffect[m_nNumEffects].psAttribute[i].pszValue);
					}
					delete [] m_psEffect[m_nNumEffects].psAttribute;

					for(i=0; i < m_psEffect[m_nNumEffects].nNumTextures; ++i)
					{
						FREE(m_psEffect[m_nNumEffects].psTextures[i].pszName);
					}
					delete [] m_psEffect[m_nNumEffects].psTextures;

					FREE(m_psEffect[m_nNumEffects].pszFragmentShaderName);
					FREE(m_psEffect[m_nNumEffects].pszVertexShaderName);

					FREE(m_psEffect[m_nNumEffects].pszAnnotation);
					FREE(m_psEffect[m_nNumEffects].pszName);

					return false;
				}
			}
			else
			{
				sprintf(errorMsg, "Missing [/EFFECT] tag after [EFFECT] on line %d\n", m_psContext->pnFileLineNumber[nLine]);
				*pReturnError = errorMsg;
				return false;
			}
			nLine = nEndLine;
		}
		else
		{
			sprintf(errorMsg, "'%s' unexpected on line %d\n", m_psContext->ppszEffectFile[nLine], m_psContext->pnFileLineNumber[nLine]);
			*pReturnError = errorMsg;
			return false;
		}
	}

	if(m_nNumEffects < 1)
	{
		sprintf(errorMsg, "No [EFFECT] found. PFX file must have at least one defined.\n");
		*pReturnError = errorMsg;
		return false;
	}

	if(m_nNumFragShaders < 1)
	{
		sprintf(errorMsg, "No [FRAGMENTSHADER] found. PFX file must have at least one defined.\n");
		*pReturnError = errorMsg;
		return false;
	}

	if(m_nNumVertShaders < 1)
	{
		sprintf(errorMsg, "No [VERTEXSHADER] found. PFX file must have at least one defined.\n");
		*pReturnError = errorMsg;
		return false;
	}

	for(i = 0; i < m_nNumEffects; ++i)
	{
		for(j = 0; j < m_psEffect[i].nNumTextures; ++j)
		{
			for(k = 0; k < m_nNumTextures; ++k)
			{
				if(strcmp(m_psEffect[i].psTextures[j].pszName, m_psTexture[k].pszName) == 0)
					break;
			}
			
			if(!m_nNumTextures || k == m_nNumTextures)
			{
				sprintf(errorMsg, "Error: TEXTURE '%s' is not defined in [TEXTURES].\n", m_psEffect[i].psTextures[j].pszName);
				*pReturnError = errorMsg;
				return false;
			}
		}
	}

	return true;
}