Login  Register

Re: JOCL texture generation

Posted by Wade Walker on Mar 17, 2014; 12:27am
URL: https://forum.jogamp.org/JOCL-texture-generation-tp4031853p4031930.html

I still don't get the exception, but it just silently doesn't work. I upgraded my drivers to the latest also, and still no luck. I also tried writing a different test that just checks to see if OpenCL can read a texture that OpenGL creates, and that seems to work, bizarrely:

int[] id = new int[1];
gl.glGenTextures(id.length, id, 0);
gl.glActiveTexture(GL2.GL_TEXTURE0);
gl.glBindTexture  (GL2.GL_TEXTURE_2D, id[0]);

ByteBuffer bufferGL = Buffers.newDirectByteBuffer(new byte [] {
    (byte)0,  (byte)5,  (byte)10, (byte)0xff,
    (byte)15, (byte)20, (byte)25, (byte)0xff,
    (byte)30, (byte)35, (byte)40, (byte)0xff,
    (byte)45, (byte)50, (byte)55, (byte)0xff});
bufferGL.rewind();
gl.glTexImage2D(GL2.GL_TEXTURE_2D, 0, GL2.GL_RGBA, 2, 2, 0, GL2.GL_RGBA, GL2.GL_UNSIGNED_BYTE, bufferGL);
gl.glBindTexture(GL2.GL_TEXTURE_2D, 0);
gl.glFinish();

ByteBuffer bufferCL = Buffers.newDirectByteBuffer(2*2*4);
CLGLTexture2d<ByteBuffer> clTexture = context.createFromGLTexture2d(bufferCL, GL2.GL_TEXTURE_2D, id[0], 0, CLBuffer.Mem.READ_ONLY);

// assertEquals(bufferGL.capacity(), clTexture.getCLCapacity());
// assertEquals(bufferGL.capacity(), clTexture.getCLSize());

 CLCommandQueue queue = device.createCommandQueue();

queue.putAcquireGLObject(clTexture)
    .putReadImage(clTexture, true)
    .putReleaseGLObject(clTexture);

while(bufferCL.hasRemaining()) {
    byte bGL = bufferGL.get();
    byte bCL = bufferCL.get();
    assertEquals(bGL, bCL);
}

The test isn't perfect, though -- notice the commented asserts will fail, because the OpenCL call to determine the size of the CL image returns 0 for some reason.

I tried a bunch of other stuff too, like making sure the GL texture was "complete", but haven't hit on the right thing yet. I'll keep trying more stuff to try to figure this out. It may be time to write a C test to make sure that this even works on Nvidia cards at all.