Understanding a small openGL abstraction with LWJGL

The LWJGL API is not a direct call to openGL, everywhere I look that there is a small layer of abstraction, I think that is why it is called light weight.

Most of the abstraction is similar, for example, the code in this example is common throughout the source

public static void glBufferSubData(int target, long offset, FloatBuffer data) { ContextCapabilities caps = GLContext.getCapabilities(); long function_pointer = caps.glBufferSubData; BufferChecks.checkFunctionAddress(function_pointer); BufferChecks.checkDirect(data); nglBufferSubData(target, offset, (data.remaining() << 2), MemoryUtil.getAddress(data), function_pointer); } 

As you can see, the LWJGL user will call this function, and then this function will call the actual GL function. I assume that the "n" in nglBufferSubData means native.

So my question is: what does this code mean? I have an idea what this function does. It sends data to an openGL buffer object. I just don’t understand what is happening in the code. Can anyone break this for me?

+4
source share
1 answer

Some OpenGL features are available through extensions. Different platforms support different extensions or even OpenGL specification features.

ContextCapabilities class knows which features are supported.

long function_pointer = caps.glBufferSubData; gets a pointer to the native OpenGL glBufferSubData method.

BufferChecks.checkFunctionAddress(function_pointer); checks to see if this pointer is specified if the null function is not supported, and an exception is thrown.

BufferChecks.checkDirect(data); ensures that the buffer is direct (and, implicitly, not equal to zero).

nglBufferSubData(target, offset, (data.remaining() << 2), MemoryUtil.getAddress(data), function_pointer); Now we have the correct data and the correct pointer to glBufferSubData , and here we call it with the specified target, offset and size in bytes.

+4
source

All Articles