Results 1 to 2 of 2

Thread: Geometry shader + glDrawInstacedArrray ()

  1. #1
    Newbie Newbie
    Join Date
    Mar 2016
    Posts
    2

    Geometry shader + glDrawInstacedArrray ()

    Hi, I have already used both geometry shaders and instanced rendering in some applications, but I was wondering if I could mix them

    - Basically, I would like to create a generic line rendering system, where I simply push vertices (vec3 position, vec4 color) to a buffer, and draw several lines in a single draw call (if 0, 1, 2, ..., n are the vertices index, I would like to draw lines between (0, 1), (2, 3), ...., but not (1, 2), (3, 4) ...)

    - I think I can do it with a 'line VAO', which would hold two vertices : ((0, 0, 0), (0, 0, 1)) , draw instancely and apply a different transformation matrix in each instance.
    The VAO method would lead to many calculation cpu-side, to process the transformation matrix for each line: distance between the two points (line model scaling), angle between the standart model and the line (rotation), translate the model to the line origin

    I would like to skip those calculation with a geometry shader, as coordinates are already 'world-relative' CPU-side

    I hope it made sense and English was correct, maybe I'm searching the wrong way, so feel free to give me alternative solution. Thank you for your reading

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,105
    Quote Originally Posted by toss-dev View Post
    - Basically, I would like to create a generic line rendering system, where I simply push vertices (vec3 position, vec4 color) to a buffer, and draw several lines in a single draw call (if 0, 1, 2, ..., n are the vertices index, I would like to draw lines between (0, 1), (2, 3), ...., but not (1, 2), (3, 4) ...)
    That's what you get from glDrawArrays(GL_LINES). No need for a geometry shader or instancing.

    If you use a geometry shader, each invocation will get two vertices, i.e. 0 and 1, 2 and 3, 4 and 5, and so on.

    Instancing lets you use a single element from an attribute array for all vertices of an instance, so it can reduce the size of the attribute arrays. But if you're using a geometry shader, you could just use GL_POINTS where each "point" contains all of the information required for a line segment, and have the geometry shader convert each point to to a line segment.

    In any case, there's no reason why the two can't be mixed.

Similar Threads

  1. shader storage buffer objects within geometry shader
    By minidrive in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 07-14-2014, 08:43 AM
  2. Replies: 5
    Last Post: 06-23-2013, 01:13 AM
  3. Replies: 4
    Last Post: 11-16-2012, 04:20 PM
  4. Geometry Shader
    By Cgor_Cyrosly in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 05-21-2007, 05:09 AM
  5. Geometry shader with VBO
    By ropel in forum OpenGL: GLSL
    Replies: 4
    Last Post: 03-21-2007, 02:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean