String and primitive parameters/return values - Feedback request

Started by spasi, March 13, 2010, 00:45:44

Previous topic - Next topic

spasi

Support for String arguments and return values has been added to LWJGL:

- Existing methods have been overloaded, your current code will run unmodified.
- Return values are Strings, input values are CharSequences, so you can also use String, StringBuilder or any other implementation.
- Support for CharSequence[] arguments is also included.
- The implementation uses ThreadLocal buffers internally, so it's multi-context ready.

Some examples:

glShaderSource(int shader, ByteBuffer string); // Original
glShaderSource(int shader, CharSequence string); // New - single source
glShaderSource(int shader, CharSequence[] strings); // New - multiple sources

void glGetShaderInfoLog(int shader, IntBuffer length, ByteBuffer infoLog); // Original
String glGetShaderInfoLog(int shader, int maxLength); // New

----------------------

EDIT: I have extended this API feature to primitive types. Functions with Buffer arguments that often read or write a single value in those Buffers have been overloaded to accept or return that single primitive value. Examples:

int texID = glGenTextures();
glDeleteTextures(texID);

int maxTexUnits = glGetInteger(GL_MAX_TEXTURE_UNITS);
float aniso = glGetFloat(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT);

if ( glGetShader(shaderID, GL_COMPILE_STATUS) == GL11.GL_FALSE ) throw new RuntimeException();

----------------------

EDIT2: Added a javadoc comment to all the new methods that says which GL call is being overloaded.

----------------------

I would very much appreciate it if you could download a nightly build and try it out in your projects. Let me know if something doesn't work or if I have missed any functions that could be overloaded.

princec

Fancy adding conveniences for glGetInteger etc. too?

Cas :)

spasi

It's what I'm doing the past two days. ;)

spasi

Support for primitive parameters and return values has been added, I've updated the first post with examples.

Rene

Wow, that's all looking great. I'll check the nightly when I have a moment
When I am king, they shall not have bread and shelter only, but also teachings out of books, for a full belly is little worth where the mind is starved - Mark Twain

Rene

Quote from: Rene on March 15, 2010, 13:49:01
Wow, that's all looking great. I'll check the nightly when I have a moment

Right, I just checked some of the new functions, and it all works like a charm. This cleans up my code quite a bit! Thanks!
When I am king, they shall not have bread and shelter only, but also teachings out of books, for a full belly is little worth where the mind is starved - Mark Twain

Fool Running

Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

ryanm

Lovely stuff. Any chance of this rolling across to the OpenAL side too?

spasi

I've added some AL functions, should be available on the next nightly. They are only 6 though, 4 Gen/Delete ones and the two alSource(Un)QueueBuffers. The rest of the API already has alternate function versions for single values, unless I missed something.

ryanm


delt0r

Great change. Hope this doesn't complicated the auto JNI stuff for you devs however. We don't want to give you too much work and put you all off the project.
If you want a plot read a book and leave Hollywood out of it.

EvilOne

This is damn great.

Would be nice to have some additional stuff for getActiveAttrib/Uniform to get rid of those pesky IntBuffers... glGetActiveAttribType and glGetActiveAttribSize maybe?

Cheers,
E1.
If you got a shiny new hammer, every problem looks like a nail!

spasi

Quote from: EvilOne on March 23, 2010, 07:59:27Would be nice to have some additional stuff for getActiveAttrib/Uniform to get rid of those pesky IntBuffers... glGetActiveAttribType and glGetActiveAttribSize maybe?

Done, added glGetActiveUniformSize, glGetActiveUniformType, glGetActiveAttribSize, glGetActiveAttribType. Could you please test it when the next build is up? I'm not sure how it's going to behave with a 0 maxlength passed to the native call. Btw, for uniforms a better choice would be glGetActiveUniforms(int program, int uniformIndex, int pname) in GL31 and ARB_uniform_buffer_object.

I've also added a javadoc comment to all the new methods, so that it's easy to tell which GL method it overloads. It can be quite messy without it in some cases.

elFarto

Hi

Thanks for the new methods, they clean up the code nicely. Any chance of getting glGetActiveUniformBlock added aswell?

Thanks & Regards
elFarto

spasi

Thanks, glGetActiveUniformBlock was ok in ARB_uniform_buffer_object but missed it in GL31. Gonna add it when I commit the APPLE extensions.