Use MemoryStack api for OpenGL and document it for SimpleDrawElements#24
Use MemoryStack api for OpenGL and document it for SimpleDrawElements#24Bawbby wants to merge 2 commits intoLWJGL:mainfrom Bawbby:master
Conversation
| import static org.lwjgl.opengl.GL15.*; | ||
| import static org.lwjgl.system.MemoryUtil.*; | ||
|
|
||
| import java.nio.FloatBuffer; |
There was a problem hiding this comment.
Why change the import order?
There was a problem hiding this comment.
My mistake, I moved the imports by accident I'll fix that.
| keyCallback.free(); | ||
| wsCallback.free(); | ||
| if (debugProc != null) | ||
| if ( debugProc != null ) |
There was a problem hiding this comment.
The code uses both with spaces and no spaces between parens, I just changed formatting to make it consistent. I can revert it if needed.
| @Override | ||
| public void invoke(long window, int w, int h) { | ||
| if (w > 0 && h > 0) { | ||
| if ( w > 0 && h > 0 ) { |
| GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); | ||
| glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2); | ||
| try (MemoryStack frame = MemoryStack.stackPush()) { | ||
| try ( MemoryStack frame = MemoryStack.stackPush() ) { |
| // Load the data into buffers and send it off to OpenGL using the MemoryStack api | ||
| // instead of BufferUtils | ||
| // Note: Don't forget to flip any buffers before passing them into gl functions that need them | ||
| try ( MemoryStack stack = MemoryStack.stackPush() ) { |
There was a problem hiding this comment.
I think using the MemoryStack for buffer data upload is stretching it a bit. In this example, since it is only 3 vertices it's okay, but it might give the wrong idea to people. The problem is that MemoryStack is not meant for potentially large buffer data, which one usually has when uploading models/vertices. A better alternative for this is manual Buffer memory management with memAlloc/memFree.
There was a problem hiding this comment.
I had forgotten to state why I used the MemoryStack vs other methods. I'll add a note about using different methods for allocating buffers and the reasons why.
2057745 to
bbab002
Compare
0342101 to
c20d13e
Compare
b402ed6 to
475b266
Compare
3a903d2 to
a95a3f2
Compare
1e52759 to
66ae1d5
Compare
9cf33fa to
aeb3174
Compare
No description provided.