Why are native methods unsafe?

Started by doppelgunner, February 18, 2017, 13:55:34

Previous topic - Next topic

doppelgunner

In the attached picture, why call glCompileShader(int shader) method instead of nglCompileShader(int shader). And in the documentation why calling the latter is unsafe. I just want to understand why?

spasi

This was a side-effect of the new thread-local implementation of OpenGL and OpenGL ES calls in LWJGL 3.1.1. The code generator has been taught the new scheme and it now produces cleaner code. This is what the code looks like in the latest 3.1.2 snapshot. (I just noticed the SDK link is missing, will fix)

In general, LWJGL produces normal and "unsafe" methods when there's something special that LWJGL does to make calling the native function easier/safer/etc. For example, normal LWJGL methods accept nio buffers, while the corresponding unsafe methods accept raw pointer values. In glCompileShader's case, there's nothing special to be done, so there shouldn't be an unsafe version.