src/renderer.cpp
void Renderer::renderMeshWithMaterial(const Matrix44 model, Mesh* mesh, GTR::Material* material, Camera* camera)
{
	//in case there is nothing to do
	if (!mesh || !mesh->getNumVertices() || !material )
		return;

	//define locals to simplify coding
	Shader* shader = NULL;
	Texture* texture = NULL;

	texture = material->color_texture;
	//texture = material->emissive_texture;
	//texture = material->metallic_roughness_texture;
	//texture = material->normal_texture;
	//texture = material->occlusion_texture;

	//select the blending
	if (material->alpha_mode == GTR::AlphaMode::BLEND)
	{
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	}
	else
		glDisable(GL_BLEND);

	//select if render both sides of the triangles
	if(material->two_sided)
		glDisable(GL_CULL_FACE);
	else
		glEnable(GL_CULL_FACE);

	//chose a shader
	if (texture)
		shader = Shader::Get("texture");
	else
		shader = Shader::Get("flat");

	//no shader? then nothing to render
	if (!shader)
		return;
	shader->enable();

	//upload uniforms
	shader->setUniform("u_viewprojection", camera->viewprojection_matrix);
	shader->setUniform("u_camera_position", camera->eye);
	shader->setUniform("u_model", model );

	shader->setUniform("u_color", material->color);
	if(texture)
		shader->setUniform("u_texture", texture, 0);

	//this is used to say which is the alpha threshold to what we should not paint a pixel on the screen (to cut polygons according to texture alpha)
	shader->setUniform("u_alpha_cutoff", material->alpha_mode == GTR::AlphaMode::MASK ? material->alpha_cutoff : 0);

	//do the draw call that renders the mesh into the screen
	mesh->render(GL_TRIANGLES);

	//disable shader
	shader->disable();

	//set the render state as it was before to avoid problems with future renders
	glDisable(GL_BLEND);
}
//renders a mesh given its transform and material

renders a mesh given its transform and material
renders a mesh given its transform and material
void Renderer::renderMeshWithMaterial(const Matrix44 model, Mesh* mesh, GTR::Material* material, Camera* camera)
{
	if (!mesh || !mesh->getNumVertices() || !material )
		return;
	Shader* shader = NULL;
	Texture* texture = NULL;
	texture = material->color_texture;
	if (material->alpha_mode == GTR::AlphaMode::BLEND)
	{
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	}
	else
		glDisable(GL_BLEND);
	if(material->two_sided)
		glDisable(GL_CULL_FACE);
	else
		glEnable(GL_CULL_FACE);
	if (texture)
		shader = Shader::Get("texture");
	else
		shader = Shader::Get("flat");
	if (!shader)
		return;
	shader->enable();
	shader->setUniform("u_viewprojection", camera->viewprojection_matrix);
	shader->setUniform("u_camera_position", camera->eye);
	shader->setUniform("u_model", model );
	shader->setUniform("u_color", material->color);
	if(texture)
		shader->setUniform("u_texture", texture, 0);
	shader->setUniform("u_alpha_cutoff", material->alpha_mode == GTR::AlphaMode::MASK ? material->alpha_cutoff : 0);
	mesh->render(GL_TRIANGLES);
	shader->disable();
	glDisable(GL_BLEND);
}
void Renderer :: renderMeshWithMaterial ( const Matrix44 model , Mesh * mesh , GTR :: Material * material , Camera * camera ) { if ( ! mesh || ! mesh -> getNumVertices ( ) || ! material ) return ; Shader * shader = NULL ; Texture * texture = NULL ; texture = material -> color_texture ; if ( material -> alpha_mode == GTR :: AlphaMode :: BLEND ) { glEnable ( GL_BLEND ) ; glBlendFunc ( GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA ) ; } else glDisable ( GL_BLEND ) ; if ( material -> two_sided ) glDisable ( GL_CULL_FACE ) ; else glEnable ( GL_CULL_FACE ) ; if ( texture ) shader = Shader :: Get ( " " ) ; else shader = Shader :: Get ( " " ) ; if ( ! shader ) return ; shader -> enable ( ) ; shader -> setUniform ( " " , camera -> viewprojection_matrix ) ; shader -> setUniform ( " " , camera -> eye ) ; shader -> setUniform ( " " , model ) ; shader -> setUniform ( " " , material -> color ) ; if ( texture ) shader -> setUniform ( " " , texture , 0 ) ; shader -> setUniform ( " " , material -> alpha_mode == GTR :: AlphaMode :: MASK ? material -> alpha_cutoff : 0 ) ; mesh -> render ( GL_TRIANGLES ) ; shader -> disable ( ) ; glDisable ( GL_BLEND ) ; }
renders a mesh given its transform and material
renders a mesh given its transform and material
//in case there is nothing to do
 //define locals to simplify coding
 //texture = material->emissive_texture;
 //texture = material->metallic_roughness_texture;
 //texture = material->normal_texture;
 //texture = material->occlusion_texture;
 //select the blending
 //select if render both sides of the triangles
 //chose a shader
 //no shader? then nothing to render
 //upload uniforms
 //this is used to say which is the alpha threshold to what we should not paint a pixel on the screen (to cut polygons according to texture alpha)
 //do the draw call that renders the mesh into the screen
 //disable shader
 //set the render state as it was before to avoid problems with future renders
