public void render() { if(HAS_VAO) glBindVertexArray(vao); else if(IS_MAC) APPLEVertexArrayObject.glBindVertexArrayAPPLE(vao); else ARBVertexArrayObject.glBindVertexArray(vao); for(RenderCommand r : renderCommands) r.render(); if(HAS_VAO) glBindVertexArray(0); else if(IS_MAC) APPLEVertexArrayObject.glBindVertexArrayAPPLE(0); else ARBVertexArrayObject.glBindVertexArray(0); }
@Test public void testNoVertexAttribPointerInOtherVAOViaExtension() { window = glfwCreateWindow(800, 600, "", 0L, 0L); glfwMakeContextCurrent(window); createCapabilities(); ARBVertexShader.glEnableVertexAttribArrayARB(0); int vao = ARBVertexArrayObject.glGenVertexArrays(); ARBVertexArrayObject.glBindVertexArray(vao); glDrawArrays(GL_POINTS, 0, 1); // <--- MUST NOT THROW ARBVertexArrayObject.glDeleteVertexArrays(new int[] { vao }); }
public void updateVertexArray(Mesh mesh) { int id = mesh.getId(); if (id == -1) { IntBuffer temp = intBuf1; ARBVertexArrayObject.glGenVertexArrays(temp); id = temp.get(0); mesh.setId(id); } if (context.boundVertexArray != id) { ARBVertexArrayObject.glBindVertexArray(id); context.boundVertexArray = id; } VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData); if (interleavedData != null && interleavedData.isUpdateNeeded()) { updateBufferData(interleavedData); } IntMap<VertexBuffer> buffers = mesh.getBuffers(); for (Entry<VertexBuffer> entry : buffers) { VertexBuffer vb = entry.getValue(); if (vb.getBufferType() == Type.InterleavedData || vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers || vb.getBufferType() == Type.Index) { continue; } if (vb.getStride() == 0) { // not interleaved setVertexAttrib(vb); } else { // interleaved setVertexAttrib(vb, interleavedData); } } }
private void renderMeshVertexArray(Mesh mesh, int lod, int count) { if (mesh.getId() == -1){ updateVertexArray(mesh); }else{ // TODO: Check if it was updated } if (context.boundVertexArray != mesh.getId()) { ARBVertexArrayObject.glBindVertexArray(mesh.getId()); context.boundVertexArray = mesh.getId(); } // IntMap<VertexBuffer> buffers = mesh.getBuffers(); VertexBuffer indices = null; if (mesh.getNumLodLevels() > 0) { indices = mesh.getLodLevel(lod); } else { indices = mesh.getBuffer(Type.Index); } if (indices != null) { drawTriangleList(indices, mesh, count); } else { drawTriangleArray(mesh.getMode(), count, mesh.getVertexCount()); } clearVertexAttribs(); clearTextureUnits(); }
public static void glBindVertexArray(int vao) { if(GL_VERSION >= 30) { GL30.glBindVertexArray(vao); } else if(IS_MAC) { APPLEVertexArrayObject.glBindVertexArrayAPPLE(vao); } else if(GLContext.getCapabilities().GL_ARB_vertex_array_object) { ARBVertexArrayObject.glBindVertexArray(vao); } else { throw new UnsupportedOperationException("VAOs not supported on this system."); } }
public static int glGenVertexArrays() { if(GL_VERSION >= 30) { return GL30.glGenVertexArrays(); } else if(IS_MAC) { return APPLEVertexArrayObject.glGenVertexArraysAPPLE(); } else if(GLContext.getCapabilities().GL_ARB_vertex_array_object) { return ARBVertexArrayObject.glGenVertexArrays(); } else { throw new UnsupportedOperationException("VAOs not supported on this system."); } }
public CubeRenderer() { buffer = BufferUtils.createFloatBuffer((int)((Math.pow(2, MAX_DEPTH + 1) - 1) * 4 * 6 * 3)); dataVBO = glGenBuffers(); glBindBuffer(GL_ARRAY_BUFFER, dataVBO); glBufferData(GL_ARRAY_BUFFER, buffer.capacity() * 4, GL_STREAM_DRAW); cubeVAO = HAS_VAO ? glGenVertexArrays() : (IS_MAC ? APPLEVertexArrayObject.glGenVertexArraysAPPLE() : ARBVertexArrayObject.glGenVertexArrays()); if(HAS_VAO) glBindVertexArray(cubeVAO); else if(IS_MAC) APPLEVertexArrayObject.glBindVertexArrayAPPLE(cubeVAO); else ARBVertexArrayObject.glBindVertexArray(cubeVAO); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, false, 6 * 4, 0); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 3, GL_FLOAT, false, 6 * 4, 3 * 4); if(HAS_VAO) glBindVertexArray(0); else if(IS_MAC) APPLEVertexArrayObject.glBindVertexArrayAPPLE(0); else ARBVertexArrayObject.glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); }
public void render(MatrixStack matrixStack) { matrixStack.getTop().translate(0, -20, Math.min(-40 * getDepth() - 40 * change * timePassed / SPLIT_TIME, -40)); buffer.clear(); float angle = (float)Math.toRadians((getDepth() + change * timePassed / SPLIT_TIME) * 45f / MAX_DEPTH); render(matrixStack, angle, 0, buffer); buffer.flip(); glBindBuffer(GL_ARRAY_BUFFER, dataVBO); glBufferSubData(GL_ARRAY_BUFFER, 0, buffer); glBindBuffer(GL_ARRAY_BUFFER, 0); if(HAS_VAO) glBindVertexArray(cubeVAO); else if(IS_MAC) APPLEVertexArrayObject.glBindVertexArrayAPPLE(cubeVAO); else ARBVertexArrayObject.glBindVertexArray(cubeVAO); glDrawArrays(GL_TRIANGLES, 0, buffer.limit() / 6); if(HAS_VAO) glBindVertexArray(0); else if(IS_MAC) APPLEVertexArrayObject.glBindVertexArrayAPPLE(0); else ARBVertexArrayObject.glBindVertexArray(0); }
public Mesh(ByteBuffer data, ArrayList<Attribute> attributes, ArrayList<RenderCommand> renderCommands, ByteBuffer indices) { if(indices == null) for(RenderCommand r : renderCommands) if(r.isIndexedCmd) throw new IllegalArgumentException("One of the render commands requires indices when none is supplied."); this.renderCommands = renderCommands; int vbo1 = glGenBuffers(); glBindBuffer(GL_ARRAY_BUFFER, vbo1); glBufferData(GL_ARRAY_BUFFER, data, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); int vbo2 = -1; if(indices != null) { vbo2 = glGenBuffers(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo2); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } vao = HAS_VAO ? glGenVertexArrays() : (IS_MAC ? APPLEVertexArrayObject.glGenVertexArraysAPPLE() : ARBVertexArrayObject.glGenVertexArrays()); if(HAS_VAO) glBindVertexArray(vao); else if(IS_MAC) APPLEVertexArrayObject.glBindVertexArrayAPPLE(vao); else ARBVertexArrayObject.glBindVertexArray(vao); glBindBuffer(GL_ARRAY_BUFFER, vbo1); for(Attribute attrib : attributes) { glEnableVertexAttribArray(attrib.index); glVertexAttribPointer(attrib.index, attrib.size, attrib.type.dataType, attrib.type.normalized, 0, attrib.offset); } if(vbo2 > -1) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo2); if(HAS_VAO) glBindVertexArray(0); else if(IS_MAC) APPLEVertexArrayObject.glBindVertexArrayAPPLE(0); else ARBVertexArrayObject.glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); }
@Override public int glGenVertexArrays() { return ARBVertexArrayObject.glGenVertexArrays(); }
@Override public void glBindVertexArray(int array) { ARBVertexArrayObject.glBindVertexArray(array); }