简体   繁体   English

EmitVertex 给出“错误 C1067:类型构造函数中的数据太少”

[英]EmitVertex gives "error C1067: too little data in type constructor"

I am using geometry shaders to generate cubes from GL_POINTS我正在使用几何着色器从 GL_POINTS 生成立方体

#version 150 core

layout(points) in;
layout(triangle_strip, max_vertices = 18) out;

in vec3 g_col[];

out vec3 f_col;

uniform mat4 transform;

void main()
{
    f_col = g_col[0];

    float s = gl_in[0].gl_PointSize * 0.5;

    vec4 c = gl_in[0].gl_Position;

    // Bottom

    gl_Position = transform * (c + vec4 (-s, -s, -s, 0));
    EmitVertex();

    gl_Position = transform * (c + vec4 (+s, -s, -s, 0));
    EmitVertex();

    gl_Position = transform * (c + vec4 (-s, +s, -s, 0));
    EmitVertex();

    gl_Position = transform * (c + vec4 (+s, +s, -s, 0));
    EmitVertex();

    // Far

    gl_Position = transform * (c + vec4 (-s, +s, +s, 0));
    EmitVertex();

    gl_Position = transform * (c + vec4 (+s, +s, +s, 0));
    EmitVertex();

    // Top

    gl_Position = transform * (c + vec4 (-s, -s, +s, 0));
    EmitVertex();

    gl_Position = transform * (c + vec4 (+s, -s, +s, 0));
    EmitVertex();

    // Near

    gl_Position = transform * (c + vec4 (-s, -s, -s, 0));
    EmitVertex();

    gl_Position = transform * (c + vec4 (+s, -s, -s, 0));
    EmitVertex();

    EndPrimitive();

    // Left

    gl_Position = transform * (c + vec4 (-s, -s, -s));
    EmitVertex ();

    gl_Position = transform * (c + vec4 (-s, +s, -s));
    EmitVertex ();

    gl_Position = transform * (c + vec4 (-s, -s, +s));
    EmitVertex ();

    gl_Position = transform * (c + vec4 (-s, +s, +s));
    EmitVertex ();

    EndPrimitive ();
}

If I delete the code after the first EndPrimitive (before the // Left comment), this correctly draws a strip around a cube, leaving the sides uncapped.如果我删除第一个EndPrimitive之后的代码(在// Left注释之前),这将正确地在立方体周围绘制一条条带,而使两侧没有封盖。

If I try to draw a new triangle strip to cap the side, I get this error for each of the four subsequent EmitVertex calls:如果我尝试绘制一个新的三角形条带来EmitVertex边,对于随后的四个EmitVertex调用中的每一个,我都会收到此错误:

error C1067: too little data in type constructor

According to this documentation根据这个文件

The GS defines what kind of primitive these vertex outputs represent. GS 定义了这些顶点输出代表什么类型的图元。 The GS can also end a primitive and start a new one , by calling the EndPrimitive() function. GS 还可以通过调用 EndPrimitive() 函数来结束一个原语并开始一个新的原语。 This does not emit a vertex.这不会发出顶点。

In order to write two independent triangles from a GS, you must write three separate vertices with EmitVertex() for the first three vertices, then call EndPrimitive() to end the strip and start a new one .为了从一个 GS 写出两个独立的三角形,你必须用 EmitVertex() 为前三个顶点写三个独立的顶点,然后调用 EndPrimitive() 结束条带并开始一个新的条带 Then you write three more vertices with EmitVertex().然后你用 EmitVertex() 再写三个顶点。

What am I doing wrong?我究竟做错了什么?

In the working part:在工作部分:

 gl_Position = transform * (c + vec4 (+s, -s, -s, 0));

In the non-working part:在非工作部分:

 gl_Position = transform * (c + vec4 (-s, -s, -s));

A vec4 constructor needs four components, just as the error message tells you.正如错误消息告诉您的那样, vec4构造函数需要四个组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM