Пример #1
0
void Shader::load(StreamReader* reader)
{
	DebugLog::print("Parsing shader...");

	reader->retain();
	while (!reader->endOfStream())
	{
		ByteArray* line = reader->readLineToBytes();

		if (line)
		{
			line->trim();

			if (line->equals("[EFFECT]"))
			{
				processEffectInfo(reader);
			}
			else if (line->equals("[VERTEXSHADER]"))
			{
				m_strVertexShader = ByteArray::create(false);
				processShader(reader, "[/VERTEXSHADER]", m_strVertexShader);
			}
			else if (line->equals("[FRAGMENTSHADER]"))
			{
				m_strFragmentShader = ByteArray::create(false);
				processShader(reader, "[/FRAGMENTSHADER]", m_strFragmentShader);
			}
		}		
	}

	DebugLog::print("Compiling shader...");
	build();
	reader->release();

	DebugLog::print("Done!");
}
Пример #2
0
void ShaderNode::loadShader()
{
	GLint			Result;

	clearShader();

	if( ( mProgramId = glCreateProgram() ) == 0 )
	{
		return;
	}

	OPENGL_PLUGIN_DEBUG;

	loadShader( mPinShaderVertex, mShaderVertId, GL_VERTEX_SHADER );

	OPENGL_PLUGIN_DEBUG;

#if defined( GL_TESS_CONTROL_SHADER )
	loadShader( mPinShaderTessCtrl, mShaderTessCtrlId, GL_TESS_CONTROL_SHADER );

	OPENGL_PLUGIN_DEBUG;
#endif

#if defined( GL_TESS_EVALUATION_SHADER )
	loadShader( mPinShaderTessEval, mShaderTessEvalId, GL_TESS_EVALUATION_SHADER );

	OPENGL_PLUGIN_DEBUG;
#endif

	loadShader( mPinShaderGeometry, mShaderGeomId, GL_GEOMETRY_SHADER );

	OPENGL_PLUGIN_DEBUG;

	loadShader( mPinShaderFragment, mShaderFragId, GL_FRAGMENT_SHADER );

	OPENGL_PLUGIN_DEBUG;

	//-------------------------------------------------------------------------

	glLinkProgram( mProgramId );

	OPENGL_PLUGIN_DEBUG;

	glGetProgramiv( mProgramId, GL_LINK_STATUS, &Result );

	if( Result != GL_TRUE )
	{
		if( !QOpenGLContext::currentContext()->format().testOption( QSurfaceFormat::DebugContext ) )
		{
			glGetShaderiv( mProgramId, GL_INFO_LOG_LENGTH, &Result );

			QVector<GLchar>	Log( Result + 1 );

			glGetShaderInfoLog( mProgramId, Result, &Result, Log.data() );

			qWarning() << QString( Log.data() );
		}

		return;
	}

	mProgramLinked = true;

	//-------------------------------------------------------------------------

	OPENGL_PLUGIN_DEBUG;

	processShader( mProgramId );

	OPENGL_PLUGIN_DEBUG;
}
Пример #3
0
void ResourcePool::Config()
{
	for (vector<Branch>::iterator branch = resourceBranch.childBranches.begin(); branch != resourceBranch.childBranches.end(); ++branch)
	{
		if (branch->branchName == "MeshContainer")
		{
			for (vector<Attribute>::iterator attri = branch->attributes.begin(); attri != branch->attributes.end(); ++attri)
			{
				Attribute tempAttri = *attri;
				string attriName = tempAttri.name;
				string attriValue = tempAttri.value;

				if (attriName == "Directory")
				{
					processMesh(attriValue);
				}
			}
		}

		else if (branch->branchName == "TextureContainer")
		{
			for (vector<Attribute>::iterator attri = branch->attributes.begin(); attri != branch->attributes.end(); ++attri)
			{
				Attribute tempAttri = *attri;
				string attriName = tempAttri.name;
				string attriValue = tempAttri.value;

				if (attriName == "Directory")
				{
					processTexture(attriValue);
				}
			}
		}

		else if (branch->branchName == "ColorContainer")
		{
			for (vector<Attribute>::iterator attri = branch->attributes.begin(); attri != branch->attributes.end(); ++attri)
			{
				Attribute tempAttri = *attri;
				string attriName = tempAttri.name;
				string attriValue = tempAttri.value;
				if (attriName == "Directory")
				{
					processColor(attriValue);
				}
			}
		}

		else if (branch->branchName == "ShaderContainer")
		{
			for (vector<Attribute>::iterator attri = branch->attributes.begin(); attri != branch->attributes.end(); ++attri)
			{
				Attribute tempAttri = *attri;
				string attriName = tempAttri.name;
				string attriValue = tempAttri.value;
				if (attriName == "Directory")
				{
					processShader(attriValue);
				}
			}
		}

		else if (branch->branchName == "SoundContainer")
		{
			for (vector<Attribute>::iterator attri = branch->attributes.begin(); attri != branch->attributes.end(); ++attri)
			{
				Attribute tempAttri = *attri;
				string attriName = tempAttri.name;
				string attriValue = tempAttri.value;
				if (attriName == "Directory")
				{
					soundPool->processSound(attriValue);
				}
			}
		}
	}
}