1

我将此示例从g-truc移植到 jogl ,它可以正常工作,一切都很好。

但现在我试图准确理解streamofglDrawTransformFeedbackStream指的是什么。

基本上vec4 position输入被转换为

        String[] strings = {"gl_Position", "Block.color"};
        gl4.glTransformFeedbackVaryings(transformProgramName, 2, strings, GL_INTERLEAVED_ATTRIBS);

如下:

void main()
{   
    gl_Position = mvp * position;
    outBlock.color = vec4(clamp(vec2(position), 0.0, 1.0), 0.0, 1.0);
}

转换流.vert ,转换流.geom

然后我简单地渲染转换后的对象glDrawTransformFeedbackStream

反馈流.vert反馈流.frag

现在,根据他们说的文档:

指定从中检索原始计数的变换反馈流的索引。

酷,所以如果我把我的绑定feedbackArrayBufferName0 这里

    gl4.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, feedbackName[0]);
    gl4.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, feedbackArrayBufferName[0]);
    gl4.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);

我想应该是这样的。

几何着色器也(仅)输出颜色以索引 0。位置呢?是否假定它们已经在流 0 上?如何?从glTransformFeedbackVaryings?

因此,我尝试将对该流的所有引用切换为 1 以检查它们是否都一致,然后它们是否引用了相同的索引。

所以我修改了

    gl4.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 1, feedbackArrayBufferName[0]);

    gl4.glDrawTransformFeedbackStream(GL_TRIANGLES, feedbackName[0], 1);

以及几何着色器内部

out Block
{
    layout(stream = 1) vec4 color;
} outBlock;

但如果我跑步,我会得到:

Program link failed: 1
    Link info
---------
error: Transform feedback can't capture varyings belonging to different vertex streams in a single buffer.

OpenGL Error(GL_INVALID_OPERATION): initProgram
GlDebugOutput.messageSent(): GLDebugEvent[ id 0x502
    type Error
    severity High: dangerous undefined behavior
    source GL API
    msg GL_INVALID_OPERATION error generated. <program> object is not successfully linked, or is not a program object.
    when 1455183474230
    source 4.5 (Core profile, arb, debug, compat[ES2, ES3, ES31, ES32], FBO, hardware) - 4.5.0 NVIDIA 361.43 - hash 0x225c78a9]
GlDebugOutput.messageSent(): GLDebugEvent[ id 0x502
    type Error
    severity High: dangerous undefined behavior
    source GL API
    msg GL_INVALID_OPERATION error generated. <program> has not been linked, or is not a program object.
    when 1455183474232
    source 4.5 (Core profile, arb, debug, compat[ES2, ES3, ES31, ES32], FBO, hardware) - 4.5.0 NVIDIA 361.43 - hash 0x225c78a9]

想知道发生了什么,我在这里找到了这个

Output variables in the Geometry Shader can be declared to go to a particular stream. This is controlled via an in-shader specification, but there are certain limitations that affect advanced component interleaving.

No two outputs that go to different streams can be captured by the same buffer. Attempting to do so will result in a linker error. So using multiple streams with interleaved writing requires using advanced interleaving to route attributes to different buffers. 

这是发生在我身上的事吗?position索引 0 和颜色索引 1?

我只是想知道我的假设是否正确。如果是,我想通过更改流索引来证明这一点。因此,我还想知道如何position在更改后将 on stream 1 与颜色一起设置。我应该以这种方式修改几何着色器的输出layout(triangle_strip, max_vertices = 3, xfb_buffer = 1) out;吗?

因为它抱怨

Shader status invalid: 0(11) : error C7548: 'layout(xfb_buffer)' requires "#extension GL_ARB_enhanced_layouts : enable" before use

然后我添加它,我得到

error: Transform feedback can't capture varyings belonging to different vertex streams in a single buffer.

但是现在他们应该都在流 1 上,我错过了什么?

此外,流的定义是什么?

4

0 回答 0