Herramientas de usuario

Herramientas del sitio


wiki2:ogl

¡Esta es una revisión vieja del documento!


OpenGL & GLSL

Render

glDrawArrays & glDrawElements

glDrawArrays is basically “draw this contiguous range of vertices, using the data I gave you earlier”.

  • Good:
    • You don't need to build an index buffer
  • Bad:
    • If you organise your data into GL_TRIANGLES, you will have duplicate vertex data for adjacent triangles. This is obviously wasteful.
    • If you use GL_TRIANGLE_STRIP and GL_TRIANGLE_FAN to try and avoid duplicating data: it isn't terribly effective and you'd have to make a rendering call for each strip and fan. OpenGL calls are expensive and should be avoided where possible.

With glDrawElements, you pass in buffer containing the indices of the vertices you want to draw.

  • Good
    • No duplicate vertex data - you just index the same data for different triangles
    • You can just use GL_TRIANGLES and rely on the vertex cache to avoid processing the same data twice - no need to re-organise your geometry data or split rendering over multiple calls
  • Bad
    • Memory overhead of index buffer

Shaders en general

Vertex Shader

Cambiar el tamaño de los puntos dibujados

gl_PointSize = 10.0;

Fragment Shader

Asignar un color fijo en el Vertex Shader

gl_FragColor = vec4(1,0,0,1);
wiki2/ogl.1448137782.txt.gz · Última modificación: 2020/05/09 09:25 (editor externo)