@Override public void destroyDirectBuffer(final Buffer buffer) { final long address = getAddress(buffer); if (address == -1) { LOGGER.warning("Not found address of the " + buffer); return; } // disable deallocator final Deallocator deallocator = DEALLOCATORS.remove(address); if (deallocator == null) { LOGGER.warning("Not found a deallocator for address " + address); return; } deallocator.setAddress(null); MemoryUtil.memFree(buffer); }
/** * ASCII encodes the specified strings with a null-terminator and ensures * space for a buffer filled with the memory addresses of the encoded * strings. * * <p> * The encoded buffers must be later freed with * {@link #pointerArrayFree(int, int)}.</p> * * @return the offset to the memory address buffer */ public int pointerArrayParamASCII(CharSequence... strings) { int buffersAddress = bufferParam(strings.length << POINTER_SHIFT); for (int i = 0; i < strings.length; i++) { ByteBuffer buffer = MemoryUtil.memASCII(strings[i]); pointerParam(buffersAddress, i, memAddress(buffer)); } return buffersAddress; }
@Override public ByteBuffer allocate(final int size) { final Long address = MemoryUtil.nmemAlloc(size); final ByteBuffer byteBuffer = MemoryUtil.memByteBuffer(address, size); DEALLOCATORS.put(address, createDeallocator(address, byteBuffer)); return byteBuffer; }
/** * UTF16 encodes the specified strings with a null-terminator and ensures * space for a buffer filled with the memory addresses of the encoded * strings. * * <p> * The encoded buffers must be later freed with * {@link #pointerArrayFree(int, int)}.</p> * * @return the offset to the memory address buffer */ public int pointerArrayParamUTF16(CharSequence... strings) { int buffersAddress = bufferParam(strings.length << POINTER_SHIFT); for (int i = 0; i < strings.length; i++) { ByteBuffer buffer = MemoryUtil.memUTF16(strings[i]); pointerParam(buffersAddress, i, memAddress(buffer)); } return buffersAddress; }
/** * Robust version of {@link ARBImaging#glGetSeparableFilter GetSeparableFilter} * * @param target the filter target. Must be:<br><table><tr><td>{@link ARBImaging#GL_SEPARABLE_2D SEPARABLE_2D}</td></tr></table> * @param format the filter data format. One of:<br><table><tr><td>{@link GL11#GL_RED RED}</td><td>{@link GL11#GL_GREEN GREEN}</td><td>{@link GL11#GL_BLUE BLUE}</td><td>{@link GL11#GL_ALPHA ALPHA}</td><td>{@link GL11#GL_RGB RGB}</td><td>{@link GL11#GL_RGBA RGBA}</td><td>{@link GL12#GL_BGR BGR}</td><td>{@link GL12#GL_BGRA BGRA}</td><td>{@link GL11#GL_LUMINANCE LUMINANCE}</td><td>{@link GL11#GL_LUMINANCE_ALPHA LUMINANCE_ALPHA}</td></tr></table> * @param type the filter data type. One of:<br><table><tr><td>{@link GL11#GL_UNSIGNED_BYTE UNSIGNED_BYTE}</td><td>{@link GL11#GL_BYTE BYTE}</td><td>{@link GL11#GL_UNSIGNED_SHORT UNSIGNED_SHORT}</td><td>{@link GL11#GL_SHORT SHORT}</td></tr><tr><td>{@link GL11#GL_UNSIGNED_INT UNSIGNED_INT}</td><td>{@link GL11#GL_INT INT}</td><td>{@link GL12#GL_UNSIGNED_BYTE_3_3_2 UNSIGNED_BYTE_3_3_2}</td><td>{@link GL12#GL_UNSIGNED_BYTE_2_3_3_REV UNSIGNED_BYTE_2_3_3_REV}</td></tr><tr><td>{@link GL12#GL_UNSIGNED_SHORT_5_6_5 UNSIGNED_SHORT_5_6_5}</td><td>{@link GL12#GL_UNSIGNED_SHORT_5_6_5_REV UNSIGNED_SHORT_5_6_5_REV}</td><td>{@link GL12#GL_UNSIGNED_SHORT_4_4_4_4 UNSIGNED_SHORT_4_4_4_4}</td><td>{@link GL12#GL_UNSIGNED_SHORT_4_4_4_4_REV UNSIGNED_SHORT_4_4_4_4_REV}</td></tr><tr><td>{@link GL12#GL_UNSIGNED_SHORT_5_5_5_1 UNSIGNED_SHORT_5_5_5_1}</td><td>{@link GL12#GL_UNSIGNED_SHORT_1_5_5_5_REV UNSIGNED_SHORT_1_5_5_5_REV}</td><td>{@link GL12#GL_UNSIGNED_INT_8_8_8_8 UNSIGNED_INT_8_8_8_8}</td><td>{@link GL12#GL_UNSIGNED_INT_8_8_8_8_REV UNSIGNED_INT_8_8_8_8_REV}</td></tr><tr><td>{@link GL12#GL_UNSIGNED_INT_10_10_10_2 UNSIGNED_INT_10_10_10_2}</td><td>{@link GL12#GL_UNSIGNED_INT_2_10_10_10_REV UNSIGNED_INT_2_10_10_10_REV}</td></tr></table> * @param row a buffer in which to return the filter row * @param column a buffer in which to return the filter column */ public static void glGetnSeparableFilterARB(@NativeType("GLenum") int target, @NativeType("GLenum") int format, @NativeType("GLenum") int type, @NativeType("void *") ByteBuffer row, @NativeType("void *") ByteBuffer column, @Nullable @NativeType("void *") ByteBuffer span) { nglGetnSeparableFilterARB(target, format, type, row.remaining(), memAddress(row), column.remaining(), memAddress(column), memAddressSafe(span)); }
public void createImages(){ IntBuffer pImageCount = memAllocInt(1); int err = vkGetSwapchainImagesKHR(device, handle, pImageCount, null); int imageCount = pImageCount.get(0); if (err != VK_SUCCESS) { throw new AssertionError("Failed to get number of swapchain images: " + VkUtil.translateVulkanResult(err)); } LongBuffer pSwapchainImages = memAllocLong(imageCount); err = vkGetSwapchainImagesKHR(device, handle, pImageCount, pSwapchainImages); if (err != VK_SUCCESS) { throw new AssertionError("Failed to get swapchain images: " + VkUtil.translateVulkanResult(err)); } swapChainImages = new ArrayList<>(imageCount); for (int i = 0; i < imageCount; i++) { swapChainImages.add(pSwapchainImages.get(i)); } memFree(pImageCount); memFree(pSwapchainImages); }
IntBuffer pFormatCount = memAllocInt(1); err = vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, pFormatCount, null); int formatCount = pFormatCount.get(0); IntBuffer pPresentModeCount = memAllocInt(1); err = vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, surface, pPresentModeCount, null); int presentModeCount = pPresentModeCount.get(0); presentModes = memAllocInt(presentModeCount); err = vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, surface, pPresentModeCount, presentModes); if (err != VK_SUCCESS) { memFree(pPresentModeCount); memFree(pFormatCount);
public InstancedMesh(float[] positions, float[] textCoords, float[] normals, int[] indices, int numInstances) { super(positions, textCoords, normals, indices, createEmptyIntArray(MAX_WEIGHTS * positions.length / 3, 0), createEmptyFloatArray(MAX_WEIGHTS * positions.length / 3, 0)); this.numInstances = numInstances; glBindVertexArray(vaoId); // Model View Matrix modelViewVBO = glGenBuffers(); vboIdList.add(modelViewVBO); this.modelViewBuffer = MemoryUtil.memAllocFloat(numInstances * MATRIX_SIZE_FLOATS); glBindBuffer(GL_ARRAY_BUFFER, modelViewVBO); int start = 5; for (int i = 0; i < 4; i++) { glVertexAttribPointer(start, 4, GL_FLOAT, false, MATRIX_SIZE_BYTES, i * VECTOR4F_SIZE_BYTES); glVertexAttribDivisor(start, 1); start++; } // Light view matrix modelLightViewVBO = glGenBuffers(); vboIdList.add(modelLightViewVBO); this.modelLightViewBuffer = MemoryUtil.memAllocFloat(numInstances * MATRIX_SIZE_FLOATS); glBindBuffer(GL_ARRAY_BUFFER, modelLightViewVBO); for (int i = 0; i < 4; i++) { glVertexAttribPointer(start, 4, GL_FLOAT, false, MATRIX_SIZE_BYTES, i * VECTOR4F_SIZE_BYTES); glVertexAttribDivisor(start, 1); start++; } glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); }
posBuffer = MemoryUtil.memAllocFloat(positions.length); posBuffer.put(positions).flip(); glBindBuffer(GL_ARRAY_BUFFER, posVboId); indicesBuffer = MemoryUtil.memAllocInt(indices.length); indicesBuffer.put(indices).flip(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, idxVboId); } finally { if (posBuffer != null) { MemoryUtil.memFree(posBuffer); MemoryUtil.memFree(indicesBuffer);
public void mapMemory(ByteBuffer buffer){ PointerBuffer pData = memAllocPointer(1); int err = vkMapMemory(device, memory, 0, buffer.remaining(), 0, pData); long data = pData.get(0); memFree(pData); if (err != VK_SUCCESS) { throw new AssertionError("Failed to map buffer memory: " + VkUtil.translateVulkanResult(err)); } memCopy(memAddress(buffer), data, buffer.remaining()); memFree(buffer); vkUnmapMemory(device, memory); }
public PhysicalDevice(VkInstance vkInstance, long surface) { IntBuffer pPhysicalDeviceCount = memAllocInt(1); int err = vkEnumeratePhysicalDevices(vkInstance, pPhysicalDeviceCount, null); if (err != VK_SUCCESS) { PointerBuffer pPhysicalDevices = memAllocPointer(pPhysicalDeviceCount.get(0)); err = vkEnumeratePhysicalDevices(vkInstance, pPhysicalDeviceCount, pPhysicalDevices); long physicalDevice = pPhysicalDevices.get(0); memFree(pPhysicalDeviceCount); memFree(pPhysicalDevices);
public void setWaitSemaphores(LongBuffer waitSemaphore){ IntBuffer pWaitDstStageMask = memAllocInt(1); pWaitDstStageMask.put(0, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT); submitInfo.setWaitDstStageMask(pWaitDstStageMask); submitInfo.setWaitSemaphores(waitSemaphore); }
public APIBuffer() { buffer = BufferUtils.createByteBuffer(DEFAULT_CAPACITY); address = memAddress(buffer); }
/** * UTF8 encodes the specified strings with a null-terminator and ensures * space for a buffer filled with the memory addresses of the encoded * strings. * * <p> * The encoded buffers must be later freed with * {@link #pointerArrayFree(int, int)}.</p> * * @return the offset to the memory address buffer */ public int pointerArrayParamUTF8(CharSequence... strings) { int buffersAddress = bufferParam(strings.length << POINTER_SHIFT); for (int i = 0; i < strings.length; i++) { ByteBuffer buffer = MemoryUtil.memUTF8(strings[i]); pointerParam(buffersAddress, i, memAddress(buffer)); } return buffersAddress; }
PointerBuffer pHmd = memAllocPointer(1); OVRGraphicsLuid luid = OVRGraphicsLuid.calloc(); if (ovr_Create(pHmd, luid) != ovrSuccess) { memFree(pHmd); luid.free(); sessionStatus = OVRSessionStatus.calloc();
/** * Returns a new {@link SECURITY_ATTRIBUTES.Buffer} instance allocated with {@link MemoryUtil#memCalloc memCalloc}. The instance must be explicitly freed. * * @param capacity the buffer capacity */ public static SECURITY_ATTRIBUTES.Buffer calloc(int capacity) { return wrap(Buffer.class, nmemCallocChecked(capacity, SIZEOF), capacity); }
/** * Returns a new {@link RECT.Buffer} instance allocated with {@link MemoryUtil#memAlloc memAlloc}. The instance must be explicitly freed. * * @param capacity the buffer capacity */ public static RECT.Buffer malloc(int capacity) { return wrap(Buffer.class, nmemAllocChecked(__checkMalloc(capacity, SIZEOF)), capacity); }
public void draw(VkQueue queue, VkSemaphore waitSemaphore){ int err = vkAcquireNextImageKHR(device, handle, UINT64_MAX, imageAcquiredSemaphore.getHandle(), VK_NULL_HANDLE, pAcquiredImageIndex); if (err != VK_SUCCESS) { throw new AssertionError("Failed to acquire next swapchain image: " + VkUtil.translateVulkanResult(err)); } CommandBuffer currentRenderCommandBuffer = renderCommandBuffers.get(pAcquiredImageIndex.get(0)); IntBuffer pWaitDstStageMask = memAllocInt(2); pWaitDstStageMask.put(0, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT); pWaitDstStageMask.put(1, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); LongBuffer pWaitSemaphores = memAllocLong(2); pWaitSemaphores.put(0, imageAcquiredSemaphore.getHandle()); pWaitSemaphores.put(1, waitSemaphore.getHandle()); submitInfo.setCommandBuffers(currentRenderCommandBuffer.getHandlePointer()); submitInfo.setWaitDstStageMask(pWaitDstStageMask); submitInfo.setWaitSemaphores(pWaitSemaphores); submitInfo.submit(queue); VkUtil.vkCheckResult(vkQueuePresentKHR(queue, presentInfo)); }
/** * Converts the specified {@link STBIWriteCallback} arguments to a ByteBuffer. * * <p>This method may only be used inside a STBIWriteCallback invocation.</p> * * @param data the STBIWriteCallback {@code data} argument * @param size the STBIWriteCallback {@code size} argument * * @return the data as a ByteBuffer */ public static ByteBuffer getData(long data, int size) { return memByteBuffer(data, size); }
@Override public void invoke(long userData, int level, long message) { LOGGER.fine("LibOVR [" + userData + "] [" + level + "] " + memASCII(message)); } };