java - Why can we directly allocate bytes in ByteBuffer but not floating Point in FloatBuffer -


in java using opengl (es) can directly allocate bytebuffer

bytebuffer bf ; bf.allocatedirect(); 

but can not in case of floatbuffer not aviliable , why ?

i wondering if because of :

byte accessible in hardware level (as opengl works above hardware unlike delvik ) , registers in hardware (hardware of gpu ) in bytes , floating points numbers should stored in 4 byte register may not available cannot allocate directly , rather should tell buffer allocate memory block of given size , after put data in blocks , treat again floatbuffer.

opengl es written in c. in c floats, integers etc not fixed size java. float point number in java 32 bits. lets examine how java uses opengl es. when send vertices graphics pipeline using java call c functions dirty work you. called ndk , find more info here : https://developer.android.com/tools/sdk/ndk/index.html. c translated assembly code each float can have different byte size on each phone depending on cpu architecture. use nio buffers ( more here : https://docs.oracle.com/javase/7/docs/api/java/nio/buffer.html ) assure float array sizes based on phone's cpu architecture(native order) , not on jvm fixed primitive sizes. lastly, imagine have vertices array of java floats (32bit fixed size). cpu floats 64 bit. if call opengl es function java program end crashing. hope helped.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -