Vertex Functions: Difference between revisions

From ENIGMA
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(19 intermediate revisions by 2 users not shown)
Line 1: Line 1:
This article is an overview of vertex related functions, they can be used to specify custom vertex formats that can allow multitexturing. In modern graphics programming primitives and models are rendered from vertex buffers in [[OpenGL]] and [[DirectX|Direct3D]], what this means is that the data for vertices and texture coordinates are packed together inside a buffer and sent to your graphics card and rendered by the GPU. Modern graphics cards are designed to do one thing very well, and that is to draw lots and lots of triangles. By constantly sending vertex and texture coordinate data and normals to the GPU you interfere with the graphics pipeline, and this can cause slow downs in games. So it is best to use vertex buffers and buffer primitives only one time and let them sit on the GPU without interference. OpenGL 1 graphics system does not utilize this behavior as older graphics cards may not support this, however [[OpenGL|OpenGL 3]] and [[DirectX|Direct3D 9]] and later graphics systems do utilize this for models. These functions give you more control over your vertex buffer by letting you specify custom formats and do multitexturing so that you only send what you absolutely need to send to the GPU.
[[Image:Primitivetypes.png|thumb|300px|Vertex ordering for various primitive types with clockwise orientation.]]
This article is an overview of vertex buffers and their related functions. The vertex functions are lower level than the model functions and allow you more control over how the vertex attributes, such as color, texture coordinates, and normals, are specified. This means they can be used to achieve proper 3D multitexturing too.


In modern graphics programming, graphics primitives are rendered from vertex buffers in [[OpenGL]] and [[DirectX|Direct3D]] where the data for vertices and texture coordinates are packed together inside a buffer and sent to your graphics card before being rendered by the GPU. This works best when data is static, and is rarely updated, because synchronizing the data between CPU and GPU can create a bottleneck.
The following functions can be used to create, declare primitives for, render, and delete a vertex buffer.
* [[vertex_create_buffer]]
* [[vertex_create_buffer]]
* [[vertex_create_buffer_ext]]
* [[vertex_create_buffer_ext]]
Line 6: Line 10:


* [[vertex_begin]]
* [[vertex_begin]]
* [[vertex_colour]]
* [[vertex_end]]
* [[vertex_normal]]
* [[vertex_freeze]]
* [[vertex_clear]]
* [[vertex_get_buffer_size]]
* [[vertex_get_number]]
* [[vertex_submit]]
 
These functions add vertex position, diffuse, UV, and normal data.
* [[vertex_position]]
* [[vertex_position]]
* [[vertex_position_3d]]
* [[vertex_position_3d]]
* [[vertex_rgba]]
* [[vertex_normal]]
* [[vertex_color]]
* [[vertex_argb]]
* [[vertex_texcoord]]
* [[vertex_texcoord]]
These functions let you add the vertex data in a custom way yourself.
* [[vertex_data]]
* [[vertex_float1]]
* [[vertex_float1]]
* [[vertex_float2]]
* [[vertex_float2]]
Line 17: Line 32:
* [[vertex_float4]]
* [[vertex_float4]]
* [[vertex_ubyte4]]
* [[vertex_ubyte4]]
* [[vertex_end]]
* [[vertex_freeze]]
* [[vertex_submit]]
* [[vertex_delete]]


The vertex format functions let you specify exactly what format your vertices are in, and for instance how many texture coordinates each vertex in the primitive contains, effectively allowing you to multitexture. The vertex formats were mainly inspired by Direct3D usage declarations, but are necessary to let the native backends (e.g. OpenGL or Direct3D) know how the vertex data is laid out. They are also important for functions like [[vertex_data]] to correctly pack the data together for the GPU with the correct data types. As long as you specify the data in the same order as the vertex format, you will have no problems using the default shader or your own custom shaders, the vertex data will be correctly mapped to shader inputs.
* [[vertex_format_begin]]
* [[vertex_format_begin]]
* [[vertex_format_add_colour]]
* [[vertex_format_add_color]]
* [[vertex_format_add_position]]
* [[vertex_format_add_position]]
* [[vertex_format_add_position_3d]]
* [[vertex_format_add_position_3d]]
Line 30: Line 42:
* [[vertex_format_add_custom]]
* [[vertex_format_add_custom]]
* [[vertex_format_end]]
* [[vertex_format_end]]
* [[vertex_format_delete]]
== See Also ==
* [[Vertex constants]]

Latest revision as of 00:20, 18 June 2018

Vertex ordering for various primitive types with clockwise orientation.

This article is an overview of vertex buffers and their related functions. The vertex functions are lower level than the model functions and allow you more control over how the vertex attributes, such as color, texture coordinates, and normals, are specified. This means they can be used to achieve proper 3D multitexturing too.

In modern graphics programming, graphics primitives are rendered from vertex buffers in OpenGL and Direct3D where the data for vertices and texture coordinates are packed together inside a buffer and sent to your graphics card before being rendered by the GPU. This works best when data is static, and is rarely updated, because synchronizing the data between CPU and GPU can create a bottleneck.

The following functions can be used to create, declare primitives for, render, and delete a vertex buffer.

These functions add vertex position, diffuse, UV, and normal data.

These functions let you add the vertex data in a custom way yourself.

The vertex format functions let you specify exactly what format your vertices are in, and for instance how many texture coordinates each vertex in the primitive contains, effectively allowing you to multitexture. The vertex formats were mainly inspired by Direct3D usage declarations, but are necessary to let the native backends (e.g. OpenGL or Direct3D) know how the vertex data is laid out. They are also important for functions like vertex_data to correctly pack the data together for the GPU with the correct data types. As long as you specify the data in the same order as the vertex format, you will have no problems using the default shader or your own custom shaders, the vertex data will be correctly mapped to shader inputs.

See Also