LWJGL Forum

Please login or register.

Login with username, password and session length

Author Topic: Why are native methods unsafe?  (Read 150 times)

doppelgunner

  • Newbie
  • *
  • Offline Offline
  • Posts: 1
Why are native methods unsafe?
« on: February 18, 2017, 13:55:34 »

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?
Logged

spasi

  • Administrator
  • Nerdus Imperius
  • *****
  • Offline Offline
  • Posts: 1746
Re: Why are native methods unsafe?
« Reply #1 on: February 18, 2017, 16:29:00 »

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.
Logged