Daniel W. Dulitz x108 writes:
 > JNI performs endian conversion, if necessary, automatically. 
 > If you have a native method that wants a byte[], and it gloms together
 > four contiguous elements and treats them as an integer according to
 > the processor's hardware endianness, then your native interface is
 > irreparably screwed up

Indeed. Not OpenGL, mind you, it is a mature API that has
done an excellent job as not forcing you to do fancy tap
dancing. I can't say the same thing about JNI though.

OpenGL Red Book, p65-78, "Vertex Arrays"
glColorPointer( GLint size, GLenum type, GLsizei stride,
                const GLvoid* pointer );
used as
   glColorPointer( 4, GL_UNSIGNED_BYTE, 0, data );

In Java, using byte[4] is simply way too expensive. The
Color objects store as r,g,b,a separately, and return
values are packed in 32bit. I use the 32bpp GL_C4UB format,
which is
     int as  byte[4] as {byte R,G,B,A}

To save JNI overhead, I put together an int[] in Java as a 
packed array of GL_C4UB colors for the above OpenGL function, 
hand it over to native code en block - and have JNI changing
the endianess on the fly? First a redundant swap by JNI,
then me swapping it back, and you do have a screwed up 
situation.

>From Jack Middleton @ SUN, OpenGL ARB/interleaved array
>  over JNI, stripped for this discussion:
>     intVal =  r;
>     intVal = intVal << 8;
>     intVal = intVal | g;
>     intVal = intVal << 8;
>     intVal = intVal | b;
>     intVal = intVal << 8;
>     intVal = intVal | a;

Which breaks for the same reason, incidentally.

 > >java.lang.Integer.byteBitsToInt( byte[] ).
 > No, there is no such thing.

It wouldn't help anyway. What would be needed instead is a 
way to get a 32bit array across JNI without JNI changing 
the byte order.

 > Search the archives for the last batch of postings on 
 > endianness, or email me privately and I'll resend some
 > earlier mails.

I'd very much appreciate that. I'll check www.blackdown.org
for archives anyway, but it would sure save me some time.
However, I somehow suspect that this is a problem inherent
to JNI. 


                                                 b.






----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to