[SOLVED] Vertex buffer not uploading to GPU when expected

What circumstances would cause a vertex buffer to not upload to the gpu when its mesh gets rendered?

I’m trying to bind an opencl buffer to a mesh’s color buffer, and that requires the color buffer be uploaded to the gpu first. No matter how long I wait, the color buffer never gets uploaded, so when I attempt to bind, an error occurs. I perform the exact same operation at the same time on the mesh’s position buffer, and that binds with no issues.

This is how I set up the vertex buffers in the mesh:

int cap = getCapacity(); // get number of verts
FloatBuffer pb = BufferUtils.createVector3Buffer(cap);
FloatBuffer cb = BufferUtils.createFloatBuffer(cap * 4);
MeshUtils.initializeVertexBuffer(this, Type.Position, VertexBuffer.Usage.Stream, VertexBuffer.Format.Float, pb, 3);
MeshUtils.initializeVertexBuffer(this, Type.Color, VertexBuffer.Usage.Stream, VertexBuffer.Format.Float, cb, 4);
updateCounts();
updateBound();
public static VertexBuffer initializeVertexBuffer(Mesh mesh, Type type, Usage usage, Format format, Buffer data, int components) {
    VertexBuffer buf = mesh.getBuffer(type);
    if (buf != null) {
        buf.updateData(data);
    } else {
        buf = new VertexBuffer(type);
        buf.setupData(usage, components, format, data);
        mesh.setBuffer(buf);
    }
    return buf;
}

About two frames after initializing the vertex buffers, I initialize opencl bindings:

clPosBuffer = context.bindVertexBuffer(getBuffer(Type.Position), MemoryAccess.READ_WRITE);
// vvv program fails here vvv
clColorBuffer = context.bindVertexBuffer(getBuffer(Type.Color), MemoryAccess.READ_WRITE);

The program throws this exception:

SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.IllegalArgumentException: vertex buffer was not yet uploaded to the GPU or is CPU only
	at com.jme3.opencl.lwjgl.LwjglContext.bindVertexBuffer(LwjglContext.java:156)
	at codex.vfx.particles.gpu.GpuParticleMesh.initOpenCL(GpuParticleMesh.java:131)
	at codex.vfx.particles.gpu.GpuParticleGeometry.updateLogicalState(GpuParticleGeometry.java:37)
	at com.jme3.scene.Node.updateLogicalState(Node.java:239)
	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:265)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:160)
	at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:225)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:242)
	at java.base/java.lang.Thread.run(Thread.java:833)

I have tried waiting longer between initializing vertex buffers and initializing opencl bindings, but that had no impact. I have also tried using the texture coordinate vertex buffer instead of the color vertex buffer, but that had no impact either.

Never mind, got it fixed. The color vertex buffer did not get uploaded because the inColor attribute was not used for anything besides a varying in both the vertex and fragment shaders.

I will leave this post here in case someone else has trouble with this issue.

5 Likes