2

Datasource:

float[] v = { ... };

Working example:

FloatBuffer buf = BufferUtils.createFloatBuffer(v.length);
buf.put(v);
buf.flip(); // or buf.rewind()

The buffer can now be uploaded to opengl and works fine:

...
glBufferData(..., buf, ...);
...

Why do the following examples of the buffer creation not also work?

Not working 1:

FloatBuffer buf = FloatBuffer.wrap(v);

Not working 2:

FloatBuffer buf = FloatBuffer.allocate(v.length);
buf.put(v);
buf.flip(); // or buf.rewind()

Edit:

After browsing the API code, I found out:

In case of the working example memAddress(buf) returns a valid address, but in the other cases it returns just 0.

Additional infos:

why am i getting a FloatBuffer is not direct error?

1
  • This might also be platform dependent. I have used FloatBuffer.wrap() on Android without any problems. Commented Jun 23, 2015 at 3:03

1 Answer 1

1

BufferUtils returns a direct buffer whereas the others might not.

You can check the directness of the wrap and allocate methods using isDirect() method. Wrappers are non direct.

Sign up to request clarification or add additional context in comments.

2 Comments

You are right. Take a look to my edit in the question above.
nice, been a long time since I dabbled in there

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.