org.lwjgl.opengl.ARBVertexArrayObject Java Examples

The following examples show how to use org.lwjgl.opengl.ARBVertexArrayObject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LWJGL20DrawContext.java    From settlers-remake with MIT License 6 votes vote down vote up
@Override
GeometryHandle allocateVBO(EGeometryFormatType type, String name) {
	GeometryHandle geometry =  super.allocateVBO(type, name);
	if (glcaps.GL_ARB_vertex_array_object && type.isSingleBuffer()) {
		geometry.setInternalFormatId(ARBVertexArrayObject.glGenVertexArrays());
		bindFormat(geometry.getInternalFormatId());

		specifyFormat(type);
	}

	if(type.isSingleBuffer())  {
		setObjectLabel(GL11.GL_VERTEX_ARRAY, geometry.getInternalFormatId(), name + "-vao");
	}

	return geometry;
}
 
Example #2
Source File: LWJGL20DrawContext.java    From settlers-remake with MIT License 5 votes vote down vote up
@Override
public void drawTrianglesWithTextureColored(TextureHandle textureid, GeometryHandle shapeHandle, GeometryHandle colorHandle, int offset, int lines, int width, int stride, float x, float y) {
	bindTexture(textureid);

	if(backgroundVAO == -1) {
		if(glcaps.GL_ARB_vertex_array_object) {
			backgroundVAO = ARBVertexArrayObject.glGenVertexArrays();
			bindFormat(backgroundVAO);
		}
		GL20.glEnableVertexAttribArray(0);
		GL20.glEnableVertexAttribArray(1);
		GL20.glEnableVertexAttribArray(2);

		bindGeometry(shapeHandle);
		GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 5 * 4, 0);
		GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, 5 * 4, 3 * 4);

		bindGeometry(colorHandle);
		GL20.glVertexAttribPointer(2, 1, GL11.GL_FLOAT, false, 0, 0);

		setObjectLabel(GL11.GL_VERTEX_ARRAY, backgroundVAO, "background-vao");
		setObjectLabel(KHRDebug.GL_BUFFER, shapeHandle.getInternalId(), "background-shape");
		setObjectLabel(KHRDebug.GL_BUFFER, colorHandle.getInternalId(), "background-color");
	}
	int starti = offset < 0 ? (int)Math.ceil(-offset/(float)stride) : 0;

	useProgram(prog_background);

	GL20.glUniform2f(prog_background.ufs[TRANS], x, y);

	bindFormat(backgroundVAO);
	for (int i = starti; i != lines; i++) {
		GL11.glDrawArrays(GL11.GL_TRIANGLES, (offset + stride * i) * 3, width * 3);
	}
}
 
Example #3
Source File: LwjglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
        }
    }
}
 
Example #4
Source File: LwjglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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();
    }
 
Example #5
Source File: LWJGL20DrawContext.java    From settlers-remake with MIT License 4 votes vote down vote up
protected void bindFormat(int format) {
	if(format != lastFormat) {
		ARBVertexArrayObject.glBindVertexArray(format);
		lastFormat = format;
	}
}
 
Example #6
Source File: ArraysHelper.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public int glGenVertexArrays() {
	return ARBVertexArrayObject.glGenVertexArrays();
}
 
Example #7
Source File: ArraysHelper.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void glBindVertexArray(int array) {
	ARBVertexArrayObject.glBindVertexArray(array);
}