Exemplo n.º 1
0
	void DrawTriangles(std::vector<float>& pos, std::vector<float>& texCoords, std::vector<float>& normals)
	{
		GetAttributeLocations();
		if(!texCoords.empty() && texCoords.size() / 2 == pos.size() / 3)
		{
			EnableVertexAttrib(g_TexCoordLocation, 2, GL_FLOAT, GL_FALSE, 0, texCoords.data());
			g_CurrentProgram->SetUniform("useTexture", true);
		}
		else
		{
			g_CurrentProgram->SetUniform("useTexture", false);
		}

		if(!normals.empty() && normals.size() / 3 == pos.size() / 3)
		{
			EnableVertexAttrib(g_NormalLocation, 3, GL_FLOAT, GL_FALSE, 0, normals.data());
		}

		if(!pos.empty())
		{
			EnableVertexAttrib(g_VertexLocation, 3, GL_FLOAT, GL_FALSE, 0, pos.data());
		}

		g_CurrentProgram->UseProgram();

		glDrawArrays(GL_TRIANGLES, 0, pos.size() / 3);

		DisableVertexAttrib(g_VertexLocation);
		DisableVertexAttrib(g_NormalLocation);
		DisableVertexAttrib(g_TexCoordLocation);
		DisableVertexAttrib(g_ColorLocation);

		ResetAttributeLocations();
	}
Exemplo n.º 2
0
	void DrawLines()
	{
		GetAttributeLocations();
		g_CurrentProgram->SetUniform("color", g_CurrentColor);

		if(!g_DrawVertices->empty())
		{
			EnableVertexAttrib(g_VertexLocation, 3, GL_FLOAT, GL_FALSE, 0, g_DrawVertices->data());
			g_CurrentProgram->SetUniform("useTexture", false);
		}
		else
			return;

		if(!g_DrawColor->empty())
		{
			EnableVertexAttrib(g_ColorLocation, 4, GL_FLOAT, GL_FALSE, 0, g_DrawColor->data());
			g_CurrentProgram->SetUniform("useVertColor", true);
		}
		else
			g_CurrentProgram->SetUniform("useVertColor", false);

		g_CurrentProgram->UseProgram();
		glDrawArrays(GL_LINES, 0, g_DrawVertices->size() / 3);

		DisableVertexAttrib(g_VertexLocation);
		DisableVertexAttrib(g_ColorLocation);

		ResetAttributeLocations();
	}
Exemplo n.º 3
0
	void Cuboid::Draw(GLProgram& glProgram)
	{
		glProgram.SetModelViewProjection();
		glProgram.UseProgram();

		glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_);

		static const size_t STRIDE = sizeof(TangentSpaceVertex);

		const int vl = glProgram.GetAttributeLocation("vertex");
		const int nl = glProgram.GetAttributeLocation("normal");
		const int tl = glProgram.GetAttributeLocation("texCoord");

		const int tanl  = glProgram.GetAttributeLocation("tangent");
		const int btanl = glProgram.GetAttributeLocation("bitangent");

		EnableVertexAttrib(vl, 3, GL_FLOAT, GL_FALSE, STRIDE, 0);
		EnableVertexAttrib(nl, 3, GL_FLOAT, GL_FALSE, STRIDE, reinterpret_cast<const GLvoid* >(offsetof(TangentSpaceVertex, nx_)));
		EnableVertexAttrib(tl, 2, GL_FLOAT, GL_FALSE, STRIDE, reinterpret_cast<const GLvoid* >(offsetof(TangentSpaceVertex, u_)));

		EnableVertexAttrib(tanl,  3, GL_FLOAT, GL_FALSE, STRIDE, reinterpret_cast<const GLvoid* >(offsetof(TangentSpaceVertex, tstx_)));
		EnableVertexAttrib(btanl, 3, GL_FLOAT, GL_FALSE, STRIDE, reinterpret_cast<const GLvoid* >(offsetof(TangentSpaceVertex, tsbx_)));

		glDrawElements(GL_TRIANGLES, NUM_INDICES, GL_UNSIGNED_INT, 0);

		DisableVertexAttrib(vl);
		DisableVertexAttrib(nl);
		DisableVertexAttrib(tl);
		DisableVertexAttrib(tanl);
		DisableVertexAttrib(btanl);

		glBindBuffer(GL_ARRAY_BUFFER, 0);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
	}
Exemplo n.º 4
0
void ModelNode::renderGeometry() {
	// Enable all needed texture units
	for (uint32 t = 0; t < _textures.size(); t++) {
		TextureMan.activeTexture(t);
		glEnable(GL_TEXTURE_2D);

		TextureMan.set(_textures[t]);
	}

	// Render the node's faces

	const VertexDecl &vertexDecl = _vertexBuffer.getVertexDecl();

	for (uint32 i = 0; i < vertexDecl.size(); i++)
		EnableVertexAttrib(vertexDecl[i]);

	glDrawElements(GL_TRIANGLES, _indexBuffer.getCount(), _indexBuffer.getType(), _indexBuffer.getData());

	for (uint32 i = 0; i < vertexDecl.size(); i++)
		DisableVertexAttrib(vertexDecl[i]);

	// Disable the texture units again
	for (uint32 i = 0; i < _textures.size(); i++) {
		TextureMan.activeTexture(i);
		glDisable(GL_TEXTURE_2D);
	}
}
void opengl_array_state::BindPointersEnd()
{
	for (auto &it : vertex_attrib_units) {
		if (!it.second.used_for_draw) {
			DisableVertexAttrib(it.first);
		}
	}
}
void opengl_array_state::ResetVertexAttribs()
{
	for (auto &it : vertex_attrib_units) {
		DisableVertexAttrib(it.first);
	}

	vertex_attrib_units.clear();
}
Exemplo n.º 7
0
void opengl_array_state::DisabledVertexAttribUnused()
{
	SCP_map<GLuint,opengl_vertex_attrib_unit>::iterator it;

	for ( it = vertex_attrib_units.begin(); it != vertex_attrib_units.end(); ++it ) {
		if ( !it->second.used ) {
			DisableVertexAttrib(it->first);
		}
	}
}
void opengl_array_state::ResetVertexAttribs()
{
	SCP_map<GLuint, opengl_vertex_attrib_unit>::iterator it;

	for ( it = vertex_attrib_units.begin(); it != vertex_attrib_units.end(); ++it ) {
		DisableVertexAttrib(it->first);
	}

	vertex_attrib_units.clear();
}
Exemplo n.º 9
0
void opengl_array_state::BindPointersEnd()
{
	// any client states not used, disable them
	if ( !vertex_array_used_for_draw ) DisableClientVertex();
	if ( !color_array_used_for_draw ) DisableClientColor();
	if ( !normal_array_used_for_draw ) DisableClientNormal();

	for (unsigned int i = 0; i < num_client_texture_units; i++) {
		if ( !client_texture_units[i].used_for_draw ) {
			SetActiveClientUnit(i);
			DisableClientTexture();
		}
	}

	SCP_map<GLuint, opengl_vertex_attrib_unit>::iterator it;

	for (it = vertex_attrib_units.begin(); it != vertex_attrib_units.end(); ++it) {
		if ( !it->second.used_for_draw ) DisableVertexAttrib(it->first);
	}
}