void opengl_render_primitives(primitive_type prim_type, vertex_layout* layout, int n_verts, int buffer_handle, size_t vert_offset, size_t byte_offset)
{
	GR_DEBUG_SCOPE("Render primitives");

	Assertion(buffer_handle >= 0, "A valid buffer handle is required! Use the immediate buffer if data is not in GPU buffer yet.");

	opengl_bind_vertex_layout(*layout, opengl_buffer_get_id(GL_ARRAY_BUFFER, buffer_handle), 0, byte_offset);

	glDrawArrays(opengl_primitive_type(prim_type), (GLint)vert_offset, n_verts);
}
Exemplo n.º 2
0
static void opengl_init_arrays(indexed_vertex_source *vert_src, vertex_buffer *bufferp)
{
	GLubyte *ptr = NULL;

	if ( vert_src->Vbuffer_handle >= 0 ) {
		opengl_bind_buffer_object(vert_src->Vbuffer_handle);
	} else {
		ptr = (GLubyte*)vert_src->Vertex_list;
	}
	
	opengl_bind_vertex_layout(bufferp->layout, 0, ptr);
}
void gr_opengl_render_decals(decal_material* material_info,
							 primitive_type prim_type,
							 vertex_layout* layout,
							 int num_elements,
							 const indexed_vertex_source& binding) {
	opengl_tnl_set_material_decal(material_info);

	opengl_bind_vertex_layout(*layout,
							  opengl_buffer_get_id(GL_ARRAY_BUFFER, binding.Vbuffer_handle),
							  opengl_buffer_get_id(GL_ELEMENT_ARRAY_BUFFER, binding.Ibuffer_handle));

	glDrawElements(opengl_primitive_type(prim_type), num_elements, GL_UNSIGNED_INT, nullptr);
}
Exemplo n.º 4
0
void opengl_render_model_program(model_material* material_info, indexed_vertex_source *vert_source, vertex_buffer* bufferp, buffer_data *datap)
{
	GL_state.Texture.SetShaderMode(GL_TRUE);

	opengl_tnl_set_model_material(material_info);

	GLubyte *ibuffer = reinterpret_cast<GLubyte*>(vert_source->Index_offset);

	GLenum element_type = (datap->flags & VB_FLAG_LARGE_INDEX) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT;

	Assert(vert_source);
	Assertion(vert_source->Vbuffer_handle >= 0, "The vertex data must be located in a GPU buffer!");
	Assertion(vert_source->Ibuffer_handle >= 0, "The index values must be located in a GPU buffer!");

	// basic setup of all data
	opengl_bind_vertex_layout(bufferp->layout,
							  opengl_buffer_get_id(GL_ARRAY_BUFFER, vert_source->Vbuffer_handle),
							  opengl_buffer_get_id(GL_ELEMENT_ARRAY_BUFFER, vert_source->Ibuffer_handle));

	// If GL_ARB_gpu_shader5 is supprted then the instancing is handled by the geometry shader
	if ( !GLAD_GL_ARB_gpu_shader5 && Rendering_to_shadow_map ) {
		glDrawElementsInstancedBaseVertex(GL_TRIANGLES,
										  (GLsizei) datap->n_verts,
										  element_type,
										  ibuffer + datap->index_offset,
										  4,
										  (GLint) (vert_source->Base_vertex_offset + bufferp->vertex_num_offset));
	} else {
		if (Cmdline_drawelements) {
			glDrawElementsBaseVertex(GL_TRIANGLES,
									 (GLsizei) datap->n_verts,
									 element_type,
									 ibuffer + datap->index_offset,
									 (GLint) (vert_source->Base_vertex_offset + bufferp->vertex_num_offset));
		} else {
			glDrawRangeElementsBaseVertex(GL_TRIANGLES,
										  datap->i_first,
										  datap->i_last,
										  (GLsizei) datap->n_verts,
										  element_type,
										  ibuffer + datap->index_offset,
										  (GLint) (vert_source->Base_vertex_offset + bufferp->vertex_num_offset));
		}
	}


	GL_state.Texture.SetShaderMode(GL_FALSE);
}
void gr_opengl_render_rocket_primitives(interface_material* material_info, primitive_type prim_type,
                                        vertex_layout* layout, int n_indices, int vertex_buffer, int index_buffer)
{
	GR_DEBUG_SCOPE("Render rocket ui primitives");

	gr_set_2d_matrix();

	opengl_tnl_set_rocketui_material(material_info);

	opengl_bind_vertex_layout(*layout, opengl_buffer_get_id(GL_ARRAY_BUFFER, vertex_buffer),
	                          opengl_buffer_get_id(GL_ELEMENT_ARRAY_BUFFER, index_buffer));

	glDrawElements(opengl_primitive_type(prim_type), n_indices, GL_UNSIGNED_INT, nullptr);

	gr_end_2d_matrix();
}