public int alGenSources() { IntBuffer ib = BufferUtils.createIntBuffer(1); joalAl.alGenSources(1, ib); return ib.get(0); }
public int alGetSourcei(int source, int param) { IntBuffer ib = BufferUtils.createIntBuffer(1); joalAl.alGetSourcei(source, param, ib); return ib.get(0); }
public void setBuffer(Type type, int components, int[] buf){ setBuffer(type, components, BufferUtils.createIntBuffer(buf)); }
/** * @return indexes buffer */ public Buffer getIndexBuffer() { if (indexes.size() <= Short.MAX_VALUE) { short[] indices = new short[indexes.size()]; for (int i = 0; i < indexes.size(); ++i) { indices[i] = indexes.get(i).shortValue(); } return BufferUtils.createShortBuffer(indices); } else { int[] indices = new int[indexes.size()]; for (int i = 0; i < indexes.size(); ++i) { indices[i] = indexes.get(i).intValue(); } return BufferUtils.createIntBuffer(indices); } }
@Override public int[] generateProfilingTasks(int numTasks) { IntBuffer ids = BufferUtils.createIntBuffer(numTasks); gl.glGenQueries(numTasks, ids); return BufferUtils.getIntArray(ids); }
/** * Generate a new IntBuffer using the given array of ints. The IntBuffer * will be data.length long and contain the int data as data[0], data[1]... * etc. * * @param data * array of ints to place into a new IntBuffer */ public static IntBuffer createIntBuffer(int... data) { if (data == null) { return null; } IntBuffer buff = createIntBuffer(data.length); buff.clear(); buff.put(data); buff.flip(); return buff; }
/** * Create a new IntBuffer of an appropriate size to hold the specified * number of ints only if the given buffer if not already the right size. * * @param buf * the buffer to first check and rewind * @param size * number of ints that need to be held by the newly created * buffer * @return the requested new IntBuffer */ public static IntBuffer createIntBuffer(IntBuffer buf, int size) { if (buf != null && buf.limit() == size) { buf.rewind(); return buf; } buf = createIntBuffer(size); return buf; }
public static IntBuffer ensureLargeEnough(IntBuffer buffer, int required) { if (buffer != null) { buffer.limit(buffer.capacity()); } if (buffer == null || (buffer.remaining() < required)) { int position = (buffer != null ? buffer.position() : 0); IntBuffer newVerts = createIntBuffer(position + required); if (buffer != null) { buffer.flip(); newVerts.put(buffer); newVerts.position(position); } buffer = newVerts; } return buffer; }
+ ", data contains " + strings.length); IntBuffer tmp = BufferUtils.createIntBuffer(strings.length); for (String s : strings) tmp.put(Integer.parseInt(s)); tmp.flip();
private Mesh createTriangleStripMesh() { Mesh strip = new Mesh(); strip.setMode(Mode.TriangleStrip); FloatBuffer vb = BufferUtils.createFloatBuffer(3*3*3); // 3 rows * 3 columns * 3 floats vb.rewind(); vb.put(new float[]{0,2,0}); vb.put(new float[]{1,2,0}); vb.put(new float[]{2,2,0}); vb.put(new float[]{0,1,0}); vb.put(new float[]{1,1,0}); vb.put(new float[]{2,1,0}); vb.put(new float[]{0,0,0}); vb.put(new float[]{1,0,0}); vb.put(new float[]{2,0,0}); FloatBuffer nb = BufferUtils.createFloatBuffer(3*3*3); nb.rewind(); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); FloatBuffer tb = BufferUtils.createFloatBuffer(3*3*2); tb.rewind(); tb.put(new float[]{0,0}); tb.put(new float[]{0.5f,0}); tb.put(new float[]{1,0}); tb.put(new float[]{0,0.5f}); tb.put(new float[]{0.5f,0.5f}); tb.put(new float[]{1,0.5f}); tb.put(new float[]{0,1}); tb.put(new float[]{0.5f,1}); tb.put(new float[]{1,1}); int[] indexes = new int[]{0,3,1,4,2,5, 5,3, 3,6,4,7,5,8}; IntBuffer ib = BufferUtils.createIntBuffer(indexes.length); ib.put(indexes); strip.setBuffer(Type.Position, 3, vb); strip.setBuffer(Type.Normal, 3, nb); strip.setBuffer(Type.TexCoord, 2, tb); strip.setBuffer(Type.Index, 3, ib); strip.updateBound(); return strip; }
protected IntBuffer readIntBuffer(byte[] content) throws IOException { int length = readInt(content); if (length == BinaryOutputCapsule.NULL_OBJECT) return null; if (BinaryImporter.canUseFastBuffers()){ ByteBuffer value = BufferUtils.createByteBuffer(length * 4); value.put(content, index, length * 4).rewind(); index += length * 4; return value.asIntBuffer(); }else{ IntBuffer value = BufferUtils.createIntBuffer(length); for (int x = 0; x < length; x++) { value.put(readIntForBuffer(content)); } value.rewind(); return value; } }
/** * Creates an index buffer that can contain the given amount * of vertices. * Returns {@link IndexShortBuffer} * * @param vertexCount The amount of vertices to contain * @param indexCount The amount of indices * to contain. * @return A new index buffer */ public static IndexBuffer createIndexBuffer(int vertexCount, int indexCount){ if (vertexCount > 65535){ return new IndexIntBuffer(BufferUtils.createIntBuffer(indexCount)); }else{ return new IndexShortBuffer(BufferUtils.createShortBuffer(indexCount)); } }
private void startLodFaceList(String submeshindex, String numfaces) { int index = Integer.parseInt(submeshindex); mesh = geoms.get(index).getMesh(); int faceCount = Integer.parseInt(numfaces); VertexBuffer originalIndexBuffer = mesh.getBuffer(Type.Index); vb = new VertexBuffer(VertexBuffer.Type.Index); if (originalIndexBuffer.getFormat() == Format.UnsignedInt) { // LOD buffer should also be integer ib = BufferUtils.createIntBuffer(faceCount * 3); sb = null; vb.setupData(Usage.Static, 3, Format.UnsignedInt, ib); } else { sb = BufferUtils.createShortBuffer(faceCount * 3); ib = null; vb.setupData(Usage.Static, 3, Format.UnsignedShort, sb); } List<VertexBuffer> levels = lodLevels.get(index); if (levels == null) { // Create the LOD levels list levels = new ArrayList<VertexBuffer>(); // Add the first LOD level (always the original index buffer) levels.add(originalIndexBuffer); lodLevels.put(index, levels); } levels.add(vb); }
case Int: case UnsignedInt: return BufferUtils.createIntBuffer(total); case Float: return BufferUtils.createFloatBuffer(total);
public IntBuffer writeIndexArray(IntBuffer store){ int faceN = (getWidth()-1)*(getHeight()-1)*2; if (store!=null){ if (store.remaining() < faceN*3) throw new BufferUnderflowException(); }else{ store = BufferUtils.createIntBuffer(faceN*3); } int i = 0; for (int z = 0; z < getHeight()-1; z++){ for (int x = 0; x < getWidth()-1; x++){ store.put(i).put(i+getWidth()).put(i+getWidth()+1); store.put(i+getWidth()+1).put(i+1).put(i); i++; // TODO: There's probably a better way to do this.. if (x==getWidth()-2) i++; } } store.flip(); return store; }
/** * Creates a new IntBuffer with the same contents as the given IntBuffer. * The new IntBuffer 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 IntBuffer to copy * @return the copy */ public static IntBuffer clone(IntBuffer buf) { if (buf == null) { return null; } buf.rewind(); IntBuffer copy; if (isDirect(buf)) { copy = createIntBuffer(buf.limit()); } else { copy = IntBuffer.allocate(buf.limit()); } copy.put(buf); return copy; }
private void startFaces(String count) throws SAXException { int numFaces = parseInt(count); int indicesPerFace = 0; switch (mesh.getMode()) { case Triangles: indicesPerFace = 3; break; case Lines: indicesPerFace = 2; break; case Points: indicesPerFace = 1; break; default: throw new SAXException("Strips or fans not supported!"); } int numIndices = indicesPerFace * numFaces; vb = new VertexBuffer(VertexBuffer.Type.Index); if (!usesBigIndices) { sb = BufferUtils.createShortBuffer(numIndices); ib = null; vb.setupData(Usage.Static, indicesPerFace, Format.UnsignedShort, sb); } else { ib = BufferUtils.createIntBuffer(numIndices); sb = null; vb.setupData(Usage.Static, indicesPerFace, Format.UnsignedInt, ib); } mesh.setBuffer(vb); }
@Override public void render() { // Calculate the render pose (translation/rotation) for each eye. // LibOVR takes the difference between this and the real position of each eye at display time // to apply AZW (timewarp). OVRPosef.Buffer hmdToEyeOffsets = OVRPosef.calloc(2); hmdToEyeOffsets.put(0, hardware.getEyePose(ovrEye_Left)); hmdToEyeOffsets.put(1, hardware.getEyePose(ovrEye_Right)); //calculate eye poses OVRUtil.ovr_CalcEyePoses(hardware.getHeadPose(), hmdToEyeOffsets, hardware.getLayer0().RenderPose()); hmdToEyeOffsets.free(); for (int eye = 0; eye < 2; eye++) { IntBuffer currentIndexB = BufferUtils.createIntBuffer(1); ovr_GetTextureSwapChainCurrentIndex(session(), hardware.getChain(eye), currentIndexB); int index = currentIndexB.get(); // Constantly (each frame) rotating through a series of // frame buffers, so make sure we write into the correct one. (eye == ovrEye_Left ? leftViewPort : rightViewPort).setOutputFrameBuffer(hardware.getFramebuffers(eye)[index]); } // Now the game will render into the buffers given to us by LibOVR }
@Override public void simpleInitApp() { Mesh mesh = new Mesh(); mesh.setBuffer(VertexBuffer.Type.Index, 1, BufferUtils.createIntBuffer(new int[]{1})); mesh.setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(new float[]{0, 0, 0})); mesh.setMode(Mesh.Mode.Points); mesh.setBound(new BoundingBox(new Vector3f(0, 0, 0), 10, 10, 10)); mesh.updateCounts(); Geometry geometry = new Geometry("Test", mesh); geometry.updateGeometricState(); geometry.setMaterial(new Material(assetManager, "Materials/Geom/SimpleGeom.j3md")); //geometry.getMaterial().getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off); //geometry.setMaterial(assetManager.loadMaterial("Materials/Geom/SimpleTess.j3md")); rootNode.attachChild(geometry); Geometry geometry1 = new Geometry("T1", new Sphere(10, 10, 1)); geometry1.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md")); rootNode.attachChild(geometry1); }
Quad quad = new Quad(10, 10); quad.clearBuffer(VertexBuffer.Type.Index); quad.setBuffer(VertexBuffer.Type.Index, 4, BufferUtils.createIntBuffer(0, 1, 2, 3)); quad.setMode(Mesh.Mode.Patch); quad.setPatchVertexCount(4);