• Breaking News

    Duplicating a VAO I'm currently working on a level editor, which will support editing meshes. I've been trying to duplicate a VAO and its VBOs, so I can then modify it, however, I'm stuck trying to duplicate the VAO's index buffer. I can copy the other VBOs just fine. The first VBO is the first attribute (and the index buffer is created before any buffers for the attributes are, and so that is why I'm subtracting one from the first VBO). int vao = Loader.getInstance().createVAO(); int firstVBO = 0; int[] vbos = new int[meshComponent.model.getMesh().getDimensions()]; int count = meshComponent.model.getMesh().getVertexCount(); { GL15.glBindBuffer(GL31.GL_COPY_READ_BUFFER, meshComponent.model.getMesh().getFirstVBO() - 1); int size = GL15.glGetBufferParameteri(GL31.GL_COPY_READ_BUFFER, GL15.GL_BUFFER_SIZE); int vbo = Loader.getInstance().createEmptyIndexBuffer(size / 4); GL15.glBindBuffer(GL31.GL_COPY_WRITE_BUFFER, vbo); GL31.glCopyBufferSubData(GL31.GL_COPY_READ_BUFFER, GL31.GL_COPY_WRITE_BUFFER, 0, 0, size); } for (int i = 0; i < vbos.length; i++) { int mul = 3; // the dimensions of the VBO if (i == 1) mul = 2; // texture coordinates int vbo = Loader.getInstance().createEmptyVBO(meshComponent.model.getMesh().getVertexCount() * mul); if (i == 0) firstVBO = vbo; GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo); GL20.glVertexAttribPointer(i, mul, GL11.GL_FLOAT, false, mul * 4, 0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL15.glBindBuffer(GL31.GL_COPY_READ_BUFFER, meshComponent.model.getMesh().getFirstVBO() + i); GL15.glBindBuffer(GL31.GL_COPY_WRITE_BUFFER, vbo); GL31.glCopyBufferSubData(GL31.GL_COPY_READ_BUFFER, GL31.GL_COPY_WRITE_BUFFER, 0, 0, meshComponent.model.getMesh().getVertexCount() * mul); } GL15.glBindBuffer(GL31.GL_COPY_READ_BUFFER, 0); GL15.glBindBuffer(GL31.GL_COPY_WRITE_BUFFER, 0); Loader.getInstance().unbindVAO(); When I try to clone a cube, only the top and bottom faces are rendered (even with backface culling disabled). Here is a picture of the bug. If I divide size by 4 (as 4 bytes is an int) in the glCopyBufferSubData call, then only 3 triangles are copied (one is missing on the top face as well as all of the triangles on the side - picture here). Furthermore, using glGetBufferSubData on the index buffer (of both the copied and original VAOs) fails silently, however, it works on the attributes. Thank you in advance for any help. https://ift.tt/eA8V8J

    I'm currently working on a level editor, which will support editing meshes. I've been trying to duplicate a VAO and its VBOs, so I can then modify it, however, I'm stuck trying to duplicate the VAO's index buffer. I can copy the other VBOs just fine. The first VBO is the first attribute (and the index buffer is created before any buffers for the attributes are, and so that is why I'm subtracting one from the first VBO). int vao = Loader.getInstance().createVAO(); int firstVBO = 0; int[] vbos = new int[meshComponent.model.getMesh().getDimensions()]; int count = meshComponent.model.getMesh().getVertexCount(); { GL15.glBindBuffer(GL31.GL_COPY_READ_BUFFER, meshComponent.model.getMesh().getFirstVBO() - 1); int size = GL15.glGetBufferParameteri(GL31.GL_COPY_READ_BUFFER, GL15.GL_BUFFER_SIZE); int vbo = Loader.getInstance().createEmptyIndexBuffer(size / 4); GL15.glBindBuffer(GL31.GL_COPY_WRITE_BUFFER, vbo); GL31.glCopyBufferSubData(GL31.GL_COPY_READ_BUFFER, GL31.GL_COPY_WRITE_BUFFER, 0, 0, size); } for (int i = 0; i < vbos.length; i++) { int mul = 3; // the dimensions of the VBO if (i == 1) mul = 2; // texture coordinates int vbo = Loader.getInstance().createEmptyVBO(meshComponent.model.getMesh().getVertexCount() * mul); if (i == 0) firstVBO = vbo; GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo); GL20.glVertexAttribPointer(i, mul, GL11.GL_FLOAT, false, mul * 4, 0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL15.glBindBuffer(GL31.GL_COPY_READ_BUFFER, meshComponent.model.getMesh().getFirstVBO() + i); GL15.glBindBuffer(GL31.GL_COPY_WRITE_BUFFER, vbo); GL31.glCopyBufferSubData(GL31.GL_COPY_READ_BUFFER, GL31.GL_COPY_WRITE_BUFFER, 0, 0, meshComponent.model.getMesh().getVertexCount() * mul); } GL15.glBindBuffer(GL31.GL_COPY_READ_BUFFER, 0); GL15.glBindBuffer(GL31.GL_COPY_WRITE_BUFFER, 0); Loader.getInstance().unbindVAO(); When I try to clone a cube, only the top and bottom faces are rendered (even with backface culling disabled). Here is a picture of the bug. If I divide size by 4 (as 4 bytes is an int) in the glCopyBufferSubData call, then only 3 triangles are copied (one is missing on the top face as well as all of the triangles on the side - picture here). Furthermore, using glGetBufferSubData on the index buffer (of both the copied and original VAOs) fails silently, however, it works on the attributes. Thank you in advance for any help.

    from GameDev.net http://bit.ly/2ON5Jbm

    ليست هناك تعليقات

    Post Top Ad

    ad728

    Post Bottom Ad

    ad728