Cube using single GL_TRIANGLE_STRIP

后端 未结 4 828
滥情空心
滥情空心 2021-02-07 04:03

Is it possible to draw a whole cube using just a single GL_TRIANGLE_STRIP?

Obviously it\'s just the cube combinatorics I\'m concerned about here, it might a

4条回答
  •  情歌与酒
    2021-02-07 04:51

    May be useful to some, here's a geometry shader that will take in a point and output a triangle strip of a unit cube

    #version 410
    
    layout(points) in;
    layout(triangle_strip, max_vertices = 12) out;
    
    uniform mat4 mvp;
    
    void main() {
        vec4 center = gl_in[0].gl_Position;
    
        vec4 dx = mvp[0];
        vec4 dy = mvp[1];
        vec4 dz = mvp[2];
    
        vec4 p1 = center;
        vec4 p2 = center + dx;
        vec4 p3 = center + dy;
        vec4 p4 = p2 + dy;
        vec4 p5 = p1 + dz;
        vec4 p6 = p2 + dz;
        vec4 p7 = p3 + dz;
        vec4 p8 = p4 + dz;
    
        gl_Position = p7;
        EmitVertex();
    
        gl_Position = p8;
        EmitVertex();
    
        gl_Position = p5;
        EmitVertex();
    
        gl_Position = p6;
        EmitVertex();
    
        gl_Position = p2;
        EmitVertex();
    
        gl_Position = p8;
        EmitVertex();
    
        gl_Position = p4;
        EmitVertex();
    
        gl_Position = p7;
        EmitVertex();
    
        gl_Position = p3;
        EmitVertex();
    
        gl_Position = p5;
        EmitVertex();
    
        gl_Position = p1;
        EmitVertex();
    
        gl_Position = p2;
        EmitVertex();
    
        gl_Position = p3;
        EmitVertex();
    
        gl_Position = p4;
        EmitVertex();
    
    }
    

提交回复
热议问题