Java Code Examples for org.lwjgl.system.MemoryUtil#memFree()
The following examples show how to use
org.lwjgl.system.MemoryUtil#memFree() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Hud.java From lwjglbook with Apache License 2.0 | 5 votes |
public void cleanup() { nvgDelete(vg); if (posx != null) { MemoryUtil.memFree(posx); } if (posy != null) { MemoryUtil.memFree(posy); } }
Example 2
Source File: InstancedMesh.java From lwjglbook with Apache License 2.0 | 5 votes |
@Override public void cleanUp() { super.cleanUp(); if (this.modelViewBuffer != null) { MemoryUtil.memFree(this.modelViewBuffer); this.modelViewBuffer = null; } if (this.modelLightViewBuffer != null) { MemoryUtil.memFree(this.modelLightViewBuffer); this.modelLightViewBuffer = null; } }
Example 3
Source File: InstancedMesh.java From lwjglbook with Apache License 2.0 | 5 votes |
@Override public void cleanUp() { super.cleanUp(); if (this.instanceDataBuffer != null) { MemoryUtil.memFree(this.instanceDataBuffer); this.instanceDataBuffer = null; } }
Example 4
Source File: InstancedMesh.java From lwjglbook with Apache License 2.0 | 5 votes |
@Override public void cleanUp() { super.cleanUp(); if (this.instanceDataBuffer != null) { MemoryUtil.memFree(this.instanceDataBuffer); this.instanceDataBuffer = null; } }
Example 5
Source File: Hud.java From lwjglbook with Apache License 2.0 | 5 votes |
public void cleanup() { nvgDelete(vg); if (posx != null) { MemoryUtil.memFree(posx); } if (posy != null) { MemoryUtil.memFree(posy); } }
Example 6
Source File: InstancedMesh.java From lwjglbook with Apache License 2.0 | 5 votes |
@Override public void cleanUp() { super.cleanUp(); if (this.instanceDataBuffer != null) { MemoryUtil.memFree(this.instanceDataBuffer); this.instanceDataBuffer = null; } }
Example 7
Source File: Hud.java From lwjglbook with Apache License 2.0 | 5 votes |
public void cleanup() { nvgDelete(vg); if (posx != null) { MemoryUtil.memFree(posx); } if (posy != null) { MemoryUtil.memFree(posy); } }
Example 8
Source File: Hud.java From lwjglbook with Apache License 2.0 | 5 votes |
public void cleanup() { nvgDelete(vg); if (posx != null) { MemoryUtil.memFree(posx); } if (posy != null) { MemoryUtil.memFree(posy); } }
Example 9
Source File: Hud.java From lwjglbook with Apache License 2.0 | 5 votes |
public void cleanup() { nvgDelete(vg); if (posx != null) { MemoryUtil.memFree(posx); } if (posy != null) { MemoryUtil.memFree(posy); } }
Example 10
Source File: InstancedMesh.java From lwjglbook with Apache License 2.0 | 5 votes |
@Override public void cleanUp() { super.cleanUp(); if (this.instanceDataBuffer != null) { MemoryUtil.memFree(this.instanceDataBuffer); this.instanceDataBuffer = null; } }
Example 11
Source File: Mesh.java From lwjglbook with Apache License 2.0 | 4 votes |
public Mesh(float[] positions, float[] textCoords, float[] normals, int[] indices, int[] jointIndices, float[] weights) { FloatBuffer posBuffer = null; FloatBuffer textCoordsBuffer = null; FloatBuffer vecNormalsBuffer = null; FloatBuffer weightsBuffer = null; IntBuffer jointIndicesBuffer = null; IntBuffer indicesBuffer = null; try { vertexCount = indices.length; vboIdList = new ArrayList<>(); vaoId = glGenVertexArrays(); glBindVertexArray(vaoId); // Position VBO int vboId = glGenBuffers(); vboIdList.add(vboId); posBuffer = MemoryUtil.memAllocFloat(positions.length); posBuffer.put(positions).flip(); glBindBuffer(GL_ARRAY_BUFFER, vboId); glBufferData(GL_ARRAY_BUFFER, posBuffer, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0); // Texture coordinates VBO vboId = glGenBuffers(); vboIdList.add(vboId); textCoordsBuffer = MemoryUtil.memAllocFloat(textCoords.length); textCoordsBuffer.put(textCoords).flip(); glBindBuffer(GL_ARRAY_BUFFER, vboId); glBufferData(GL_ARRAY_BUFFER, textCoordsBuffer, GL_STATIC_DRAW); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0); // Vertex normals VBO vboId = glGenBuffers(); vboIdList.add(vboId); vecNormalsBuffer = MemoryUtil.memAllocFloat(normals.length); if (vecNormalsBuffer.capacity() > 0) { vecNormalsBuffer.put(normals).flip(); } else { // Create empty structure vecNormalsBuffer = MemoryUtil.memAllocFloat(positions.length); } glBindBuffer(GL_ARRAY_BUFFER, vboId); glBufferData(GL_ARRAY_BUFFER, vecNormalsBuffer, GL_STATIC_DRAW); glEnableVertexAttribArray(2); glVertexAttribPointer(2, 3, GL_FLOAT, false, 0, 0); // Weights vboId = glGenBuffers(); vboIdList.add(vboId); weightsBuffer = MemoryUtil.memAllocFloat(weights.length); weightsBuffer.put(weights).flip(); glBindBuffer(GL_ARRAY_BUFFER, vboId); glBufferData(GL_ARRAY_BUFFER, weightsBuffer, GL_STATIC_DRAW); glEnableVertexAttribArray(3); glVertexAttribPointer(3, 4, GL_FLOAT, false, 0, 0); // Joint indices vboId = glGenBuffers(); vboIdList.add(vboId); jointIndicesBuffer = MemoryUtil.memAllocInt(jointIndices.length); jointIndicesBuffer.put(jointIndices).flip(); glBindBuffer(GL_ARRAY_BUFFER, vboId); glBufferData(GL_ARRAY_BUFFER, jointIndicesBuffer, GL_STATIC_DRAW); glEnableVertexAttribArray(4); glVertexAttribPointer(4, 4, GL_FLOAT, false, 0, 0); // Index VBO vboId = glGenBuffers(); vboIdList.add(vboId); indicesBuffer = MemoryUtil.memAllocInt(indices.length); indicesBuffer.put(indices).flip(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboId); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); } finally { if (posBuffer != null) { MemoryUtil.memFree(posBuffer); } if (textCoordsBuffer != null) { MemoryUtil.memFree(textCoordsBuffer); } if (vecNormalsBuffer != null) { MemoryUtil.memFree(vecNormalsBuffer); } if (weightsBuffer != null) { MemoryUtil.memFree(weightsBuffer); } if (jointIndicesBuffer != null) { MemoryUtil.memFree(jointIndicesBuffer); } if (indicesBuffer != null) { MemoryUtil.memFree(indicesBuffer); } } }
Example 12
Source File: SoundBuffer.java From lwjglbook with Apache License 2.0 | 4 votes |
public void cleanup() { alDeleteBuffers(this.bufferId); if (pcm != null) { MemoryUtil.memFree(pcm); } }
Example 13
Source File: Mesh.java From lwjglbook with Apache License 2.0 | 4 votes |
public Mesh(float[] positions, float[] textCoords, float[] normals, int[] indices) { FloatBuffer posBuffer = null; FloatBuffer textCoordsBuffer = null; FloatBuffer vecNormalsBuffer = null; IntBuffer indicesBuffer = null; try { vertexCount = indices.length; vboIdList = new ArrayList<>(); vaoId = glGenVertexArrays(); glBindVertexArray(vaoId); // Position VBO int vboId = glGenBuffers(); vboIdList.add(vboId); posBuffer = MemoryUtil.memAllocFloat(positions.length); posBuffer.put(positions).flip(); glBindBuffer(GL_ARRAY_BUFFER, vboId); glBufferData(GL_ARRAY_BUFFER, posBuffer, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0); // Texture coordinates VBO vboId = glGenBuffers(); vboIdList.add(vboId); textCoordsBuffer = MemoryUtil.memAllocFloat(textCoords.length); textCoordsBuffer.put(textCoords).flip(); glBindBuffer(GL_ARRAY_BUFFER, vboId); glBufferData(GL_ARRAY_BUFFER, textCoordsBuffer, GL_STATIC_DRAW); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0); // Vertex normals VBO vboId = glGenBuffers(); vboIdList.add(vboId); vecNormalsBuffer = MemoryUtil.memAllocFloat(normals.length); vecNormalsBuffer.put(normals).flip(); glBindBuffer(GL_ARRAY_BUFFER, vboId); glBufferData(GL_ARRAY_BUFFER, vecNormalsBuffer, GL_STATIC_DRAW); glEnableVertexAttribArray(2); glVertexAttribPointer(2, 3, GL_FLOAT, false, 0, 0); // Index VBO vboId = glGenBuffers(); vboIdList.add(vboId); indicesBuffer = MemoryUtil.memAllocInt(indices.length); indicesBuffer.put(indices).flip(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboId); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); } finally { if (posBuffer != null) { MemoryUtil.memFree(posBuffer); } if (textCoordsBuffer != null) { MemoryUtil.memFree(textCoordsBuffer); } if (vecNormalsBuffer != null) { MemoryUtil.memFree(vecNormalsBuffer); } if (indicesBuffer != null) { MemoryUtil.memFree(indicesBuffer); } } }
Example 14
Source File: Mesh.java From lwjglbook with Apache License 2.0 | 4 votes |
public Mesh(float[] positions, float[] textCoords, float[] normals, int[] indices) { FloatBuffer posBuffer = null; FloatBuffer textCoordsBuffer = null; FloatBuffer vecNormalsBuffer = null; IntBuffer indicesBuffer = null; try { vertexCount = indices.length; vboIdList = new ArrayList<>(); vaoId = glGenVertexArrays(); glBindVertexArray(vaoId); // Position VBO int vboId = glGenBuffers(); vboIdList.add(vboId); posBuffer = MemoryUtil.memAllocFloat(positions.length); posBuffer.put(positions).flip(); glBindBuffer(GL_ARRAY_BUFFER, vboId); glBufferData(GL_ARRAY_BUFFER, posBuffer, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0); // Texture coordinates VBO vboId = glGenBuffers(); vboIdList.add(vboId); textCoordsBuffer = MemoryUtil.memAllocFloat(textCoords.length); textCoordsBuffer.put(textCoords).flip(); glBindBuffer(GL_ARRAY_BUFFER, vboId); glBufferData(GL_ARRAY_BUFFER, textCoordsBuffer, GL_STATIC_DRAW); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0); // Vertex normals VBO vboId = glGenBuffers(); vboIdList.add(vboId); vecNormalsBuffer = MemoryUtil.memAllocFloat(normals.length); if (vecNormalsBuffer.capacity() > 0) { vecNormalsBuffer.put(normals).flip(); } else { // Create empty structure vecNormalsBuffer = MemoryUtil.memAllocFloat(positions.length); } glBindBuffer(GL_ARRAY_BUFFER, vboId); glBufferData(GL_ARRAY_BUFFER, vecNormalsBuffer, GL_STATIC_DRAW); glEnableVertexAttribArray(2); glVertexAttribPointer(2, 3, GL_FLOAT, false, 0, 0); // Index VBO vboId = glGenBuffers(); vboIdList.add(vboId); indicesBuffer = MemoryUtil.memAllocInt(indices.length); indicesBuffer.put(indices).flip(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboId); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); } finally { if (posBuffer != null) { MemoryUtil.memFree(posBuffer); } if (textCoordsBuffer != null) { MemoryUtil.memFree(textCoordsBuffer); } if (vecNormalsBuffer != null) { MemoryUtil.memFree(vecNormalsBuffer); } if (indicesBuffer != null) { MemoryUtil.memFree(indicesBuffer); } } }
Example 15
Source File: Mesh.java From lwjglbook with Apache License 2.0 | 4 votes |
public Mesh(float[] positions, float[] textCoords, float[] normals, int[] indices) { FloatBuffer posBuffer = null; FloatBuffer textCoordsBuffer = null; FloatBuffer vecNormalsBuffer = null; IntBuffer indicesBuffer = null; try { vertexCount = indices.length; vboIdList = new ArrayList<>(); vaoId = glGenVertexArrays(); glBindVertexArray(vaoId); // Position VBO int vboId = glGenBuffers(); vboIdList.add(vboId); posBuffer = MemoryUtil.memAllocFloat(positions.length); posBuffer.put(positions).flip(); glBindBuffer(GL_ARRAY_BUFFER, vboId); glBufferData(GL_ARRAY_BUFFER, posBuffer, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0); // Texture coordinates VBO vboId = glGenBuffers(); vboIdList.add(vboId); textCoordsBuffer = MemoryUtil.memAllocFloat(textCoords.length); textCoordsBuffer.put(textCoords).flip(); glBindBuffer(GL_ARRAY_BUFFER, vboId); glBufferData(GL_ARRAY_BUFFER, textCoordsBuffer, GL_STATIC_DRAW); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0); // Vertex normals VBO vboId = glGenBuffers(); vboIdList.add(vboId); vecNormalsBuffer = MemoryUtil.memAllocFloat(normals.length); if (vecNormalsBuffer.capacity() > 0) { vecNormalsBuffer.put(normals).flip(); } else { // Create empty structure vecNormalsBuffer = MemoryUtil.memAllocFloat(positions.length); } glBindBuffer(GL_ARRAY_BUFFER, vboId); glBufferData(GL_ARRAY_BUFFER, vecNormalsBuffer, GL_STATIC_DRAW); glEnableVertexAttribArray(2); glVertexAttribPointer(2, 3, GL_FLOAT, false, 0, 0); // Index VBO vboId = glGenBuffers(); vboIdList.add(vboId); indicesBuffer = MemoryUtil.memAllocInt(indices.length); indicesBuffer.put(indices).flip(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboId); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); } finally { if (posBuffer != null) { MemoryUtil.memFree(posBuffer); } if (textCoordsBuffer != null) { MemoryUtil.memFree(textCoordsBuffer); } if (vecNormalsBuffer != null) { MemoryUtil.memFree(vecNormalsBuffer); } if (indicesBuffer != null) { MemoryUtil.memFree(indicesBuffer); } } }
Example 16
Source File: SoundBuffer.java From lwjglbook with Apache License 2.0 | 4 votes |
public void cleanup() { alDeleteBuffers(this.bufferId); if (pcm != null) { MemoryUtil.memFree(pcm); } }
Example 17
Source File: SoundBuffer.java From lwjglbook with Apache License 2.0 | 4 votes |
public void cleanup() { alDeleteBuffers(this.bufferId); if (pcm != null) { MemoryUtil.memFree(pcm); } }
Example 18
Source File: SoundBuffer.java From lwjglbook with Apache License 2.0 | 4 votes |
public void cleanup() { alDeleteBuffers(this.bufferId); if (pcm != null) { MemoryUtil.memFree(pcm); } }
Example 19
Source File: Mesh.java From lwjglbook with Apache License 2.0 | 4 votes |
public Mesh(float[] positions, float[] textCoords, float[] normals, int[] indices) { FloatBuffer posBuffer = null; FloatBuffer textCoordsBuffer = null; FloatBuffer vecNormalsBuffer = null; IntBuffer indicesBuffer = null; try { colour = Mesh.DEFAULT_COLOUR; vertexCount = indices.length; vboIdList = new ArrayList<>(); vaoId = glGenVertexArrays(); glBindVertexArray(vaoId); // Position VBO int vboId = glGenBuffers(); vboIdList.add(vboId); posBuffer = MemoryUtil.memAllocFloat(positions.length); posBuffer.put(positions).flip(); glBindBuffer(GL_ARRAY_BUFFER, vboId); glBufferData(GL_ARRAY_BUFFER, posBuffer, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0); // Texture coordinates VBO vboId = glGenBuffers(); vboIdList.add(vboId); textCoordsBuffer = MemoryUtil.memAllocFloat(textCoords.length); textCoordsBuffer.put(textCoords).flip(); glBindBuffer(GL_ARRAY_BUFFER, vboId); glBufferData(GL_ARRAY_BUFFER, textCoordsBuffer, GL_STATIC_DRAW); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0); // Vertex normals VBO vboId = glGenBuffers(); vboIdList.add(vboId); vecNormalsBuffer = MemoryUtil.memAllocFloat(normals.length); vecNormalsBuffer.put(normals).flip(); glBindBuffer(GL_ARRAY_BUFFER, vboId); glBufferData(GL_ARRAY_BUFFER, vecNormalsBuffer, GL_STATIC_DRAW); glEnableVertexAttribArray(2); glVertexAttribPointer(2, 3, GL_FLOAT, false, 0, 0); // Index VBO vboId = glGenBuffers(); vboIdList.add(vboId); indicesBuffer = MemoryUtil.memAllocInt(indices.length); indicesBuffer.put(indices).flip(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboId); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); } finally { if (posBuffer != null) { MemoryUtil.memFree(posBuffer); } if (textCoordsBuffer != null) { MemoryUtil.memFree(textCoordsBuffer); } if (vecNormalsBuffer != null) { MemoryUtil.memFree(vecNormalsBuffer); } if (indicesBuffer != null) { MemoryUtil.memFree(indicesBuffer); } } }
Example 20
Source File: Renderer.java From lwjglbook with Apache License 2.0 | 4 votes |
public void init() throws Exception { shaderProgram = new ShaderProgram(); shaderProgram.createVertexShader(Utils.loadResource("/vertex.vs")); shaderProgram.createFragmentShader(Utils.loadResource("/fragment.fs")); shaderProgram.link(); float[] vertices = new float[]{ 0.0f, 0.5f, 0.0f, -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f }; FloatBuffer verticesBuffer = null; try { verticesBuffer = MemoryUtil.memAllocFloat(vertices.length); verticesBuffer.put(vertices).flip(); // Create the VAO and bind to it vaoId = glGenVertexArrays(); glBindVertexArray(vaoId); // Create the VBO and bint to it vboId = glGenBuffers(); glBindBuffer(GL_ARRAY_BUFFER, vboId); glBufferData(GL_ARRAY_BUFFER, verticesBuffer, GL_STATIC_DRAW); // Enable location 0 glEnableVertexAttribArray(0); // Define structure of the data glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0); // Unbind the VBO glBindBuffer(GL_ARRAY_BUFFER, 0); // Unbind the VAO glBindVertexArray(0); } finally { if (verticesBuffer != null) { MemoryUtil.memFree(verticesBuffer); } } }