private void initCurrentMousePosition(long window) { DoubleBuffer x = BufferUtils.createDoubleBuffer(1); DoubleBuffer y = BufferUtils.createDoubleBuffer(1); glfwGetCursorPos(window, x, y); mouseX = (int) Math.round(x.get()); mouseY = (int) currentHeight - (int) Math.round(y.get()); }
/** * Create a new DoubleBuffer of an appropriate size to hold the specified * number of doubles only if the given buffer if not already the right size. * * @param buf * the buffer to first check and rewind * @param size * number of doubles that need to be held by the newly created * buffer * @return the requested new DoubleBuffer */ public static DoubleBuffer createDoubleBuffer(DoubleBuffer buf, int size) { if (buf != null && buf.limit() == size) { buf.rewind(); return buf; } buf = createDoubleBuffer(size); return buf; }
return BufferUtils.createFloatBuffer(total); case Double: return BufferUtils.createDoubleBuffer(total); default: throw new UnsupportedOperationException("Unrecoginized buffer format: "+format);
/** * Creates a new DoubleBuffer with the same contents as the given * DoubleBuffer. The new DoubleBuffer is separate from the old one and * changes are not reflected across. If you want to reflect changes, * consider using Buffer.duplicate(). * * @param buf * the DoubleBuffer to copy * @return the copy */ public static DoubleBuffer clone(DoubleBuffer buf) { if (buf == null) { return null; } buf.rewind(); DoubleBuffer copy; if (isDirect(buf)) { copy = createDoubleBuffer(buf.limit()); } else { copy = DoubleBuffer.allocate(buf.limit()); } copy.put(buf); return copy; }
/** * Create a new DoubleBuffer of an appropriate size to hold the specified * number of doubles only if the given buffer if not already the right size. * * @param buf * the buffer to first check and rewind * @param size * number of doubles that need to be held by the newly created * buffer * @return the requested new DoubleBuffer */ public static DoubleBuffer createDoubleBuffer(DoubleBuffer buf, int size) { if (buf != null && buf.limit() == size) { buf.rewind(); return buf; } buf = createDoubleBuffer(size); return buf; }
/** * Create a new DoubleBuffer of an appropriate size to hold the specified * number of doubles only if the given buffer if not already the right size. * * @param buf * the buffer to first check and rewind * @param size * number of doubles that need to be held by the newly created * buffer * @return the requested new DoubleBuffer */ public static DoubleBuffer createDoubleBuffer(DoubleBuffer buf, int size) { if (buf != null && buf.limit() == size) { buf.rewind(); return buf; } buf = createDoubleBuffer(size); return buf; }
/** * Creates a {@link Buffer} that satisfies the given type and size requirements * of the parameters. The buffer will be of the type specified by * {@link Format format} and would be able to contain the given number * of elements with the given number of components in each element. */ public static Buffer createBuffer(Format format, int components, int numElements){ if (components < 1 || components > 4) throw new IllegalArgumentException("Num components must be between 1 and 4"); int total = numElements * components; switch (format){ case Byte: case UnsignedByte: return BufferUtils.createByteBuffer(total); case Half: return BufferUtils.createByteBuffer(total * 2); case Short: case UnsignedShort: return BufferUtils.createShortBuffer(total); case Int: case UnsignedInt: return BufferUtils.createIntBuffer(total); case Float: return BufferUtils.createFloatBuffer(total); case Double: return BufferUtils.createDoubleBuffer(total); default: throw new UnsupportedOperationException("Unrecoginized buffer format: "+format); } }
/** * Creates a {@link Buffer} that satisfies the given type and size requirements * of the parameters. The buffer will be of the type specified by * {@link Format format} and would be able to contain the given number * of elements with the given number of components in each element. */ public static Buffer createBuffer(Format format, int components, int numElements){ if (components < 1 || components > 4) throw new IllegalArgumentException("Num components must be between 1 and 4"); int total = numElements * components; switch (format){ case Byte: case UnsignedByte: return BufferUtils.createByteBuffer(total); case Half: return BufferUtils.createByteBuffer(total * 2); case Short: case UnsignedShort: return BufferUtils.createShortBuffer(total); case Int: case UnsignedInt: return BufferUtils.createIntBuffer(total); case Float: return BufferUtils.createFloatBuffer(total); case Double: return BufferUtils.createDoubleBuffer(total); default: throw new UnsupportedOperationException("Unrecoginized buffer format: "+format); } }
/** * Creates a new DoubleBuffer with the same contents as the given * DoubleBuffer. The new DoubleBuffer is separate from the old one and * changes are not reflected across. If you want to reflect changes, * consider using Buffer.duplicate(). * * @param buf * the DoubleBuffer to copy * @return the copy */ public static DoubleBuffer clone(DoubleBuffer buf) { if (buf == null) { return null; } buf.rewind(); DoubleBuffer copy; if (isDirect(buf)) { copy = createDoubleBuffer(buf.limit()); } else { copy = DoubleBuffer.allocate(buf.limit()); } copy.put(buf); return copy; }
/** * Creates a new DoubleBuffer with the same contents as the given * DoubleBuffer. The new DoubleBuffer is seperate from the old one and * changes are not reflected across. If you want to reflect changes, * consider using Buffer.duplicate(). * * @param buf * the DoubleBuffer to copy * @return the copy */ public static DoubleBuffer clone(DoubleBuffer buf) { if (buf == null) { return null; } buf.rewind(); DoubleBuffer copy; if (buf.isDirect()) { copy = createDoubleBuffer(buf.limit()); } else { copy = DoubleBuffer.allocate(buf.limit()); } copy.put(buf); return copy; }