2015-04-23 45 views
-1

我將此samplesite)移植到jogl但我注意到圖像中有些東西不完美,地面上的某些人造物和形狀不完全平整,您可以看(不關於顏色護理,是不同的),也地板犯規好看:我無法得到一個簡單的索引數組呈現正確

enter image description here

enter image description here

因此,我試圖呈現只有首先發言(如果你想嘗試,很容易的,從100 - > 0開始SQRT_BUILDING_COUNT)在那裏我已經有了第一個問題,它應該是基於兩個三角形的正方形,但我只看到其中的一個。

enter image description here

My vertex structure

public float[] position = new float[3]; 
public byte[] color = new byte[4]; 
public float[] attrib0 = new float[4]; 
public float[] attrib1 = new float[4]; 
public float[] attrib2 = new float[4]; 
public float[] attrib3 = new float[4]; 
public float[] attrib4 = new float[4]; 
public float[] attrib5 = new float[4]; 
public float[] attrib6 = new float[4]; 

attrib0-6未使用的那一刻

My VS inputs

// Input attributes 
layout(location=0) in vec4 iPos; 
layout(location=1) in vec4 iColor; 
layout(location=2) in PerMeshUniforms* bindlessPerMeshUniformsPtr; 
layout(location=3) in vec4 iAttrib3; 
layout(location=4) in vec4 iAttrib4; 
layout(location=5) in vec4 iAttrib5; 
layout(location=6) in vec4 iAttrib6; 
layout(location=7) in vec4 iAttrib7; 

我聲明IPOS爲VEC3,所以我想它將在VS中填充爲vec4(iPos,1)

I transfer data to gpu

gl4.glNamedBufferData(vertexBuffer[0], Vertex.size() * vertices.size(), 
      GLBuffers.newDirectFloatBuffer(verticesArray), GL4.GL_STATIC_DRAW); 
    gl4.glNamedBufferData(indexBuffer[0], GLBuffers.SIZEOF_SHORT * indices.size(), 
      GLBuffers.newDirectShortBuffer(indicesArray), GL4.GL_STATIC_DRAW); 

然後我才呈現I call

 gl4.glEnableVertexArrayAttrib(0, 0); 
     gl4.glEnableVertexArrayAttrib(0, 1); 

然後渲染,original code is

// Set up attribute 0 for the position (3 floats) 
    glVertexArrayVertexAttribOffsetEXT(0, m_vertexBuffer, 0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), Vertex::PositionOffset); 

    // Set up attribute 1 for the color (4 unsigned bytes) 
    glVertexArrayVertexAttribOffsetEXT(0, m_vertexBuffer, 1, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex), Vertex::ColorOffset); 

I substituted it with

 // Set up attribute 0 for the position (3 floats) 
     gl4.glVertexArrayVertexBuffer(0, 0, vertexBuffer[0], Vertex.positionOffset, 
       Vertex.size()); 
     gl4.glVertexArrayAttribFormat(0, 0, 3, GL4.GL_FLOAT, false, Vertex.size()); 

     // Set up attribute 1 for the color (4 unsigned bytes) 
     gl4.glVertexArrayVertexBuffer(0, 1, vertexBuffer[0], Vertex.colorOffset, 
       Vertex.size()); 
     gl4.glVertexArrayAttribFormat(0, 1, 4, GL4.GL_UNSIGNED_BYTE, true, Vertex.size()); 

And then I finish the render

 // Reset state 
     gl4.glDisableVertexArrayAttrib(0, 0); 
     gl4.glDisableVertexArrayAttrib(0, 1); 

我承認我從來沒有使用過DSA,我總是用GL3與正常VBO,VAO和IBO,綁定和解除綁定..

剔除處於關閉狀態。

然後出現什麼問題?

回答

0

解決了,問題是我沒有執行正確DSA

glEnableVertexAttribArray(vao, 0); 
glEnableVertexAttribArray(vao, 1); 

// Setup the formats 
glVertexArrayAttribFormat(vao, 0, 3, GL_FLOAT, GL_FALSE, 0); 
glVertexArrayAttribFormat(vao, 1, 2, GL_FLOAT, GL_FALSE, 0); 

// Setup the buffer sources 
glVertexArrayVertexBuffer(vao, 0, buffers[0], 0, 0); // Note the 2nd argument here is a 'binding index', not the attribute index 
glVertexArrayVertexBuffer(vao, 1, buffers[1], 0, 0); 

// Link them up 
glVertexArrayAttribBinding(vao, 0, 0); // Associate attrib 0 (first 0) with binding 0 (second 0). 
glVertexArrayAttribBinding(vao, 1, 1); 

glVertexArrayElementBuffer如果你有索引的渲染