@Override public int getNumMaxVertices () { return buffer.capacity() * 4 / attributes.vertexSize; }
@Override public int getNumMaxVertices () { return buffer.capacity() * 4 / attributes.vertexSize; }
/** Clears the depth buffer by setting the depth to -1. */ public void clear () { buffer.clear(); while (buffer.position() < buffer.capacity()) buffer.put(-1); }
/** Returns a string representing the state of this float buffer. * * @return a string representing the state of this float buffer. * @since Android 1.0 */ public String toString () { StringBuilder sb = new StringBuilder(); sb.append(getClass().getName()); sb.append(", status: capacity="); //$NON-NLS-1$ sb.append(capacity()); sb.append(" position="); //$NON-NLS-1$ sb.append(position()); sb.append(" limit="); //$NON-NLS-1$ sb.append(limit()); return sb.toString(); } }
/** Returns a string representing the state of this float buffer. * * @return a string representing the state of this float buffer. * @since Android 1.0 */ public String toString () { StringBuilder sb = new StringBuilder(); sb.append(getClass().getName()); sb.append(", status: capacity="); //$NON-NLS-1$ sb.append(capacity()); sb.append(" position="); //$NON-NLS-1$ sb.append(position()); sb.append(" limit="); //$NON-NLS-1$ sb.append(limit()); return sb.toString(); } }
private void mergeTargetBuffer(float[] array, float weight, FloatBuffer src, boolean init) { src.rewind(); for (int j = 0; j < src.capacity(); j++) { if (init) { array[j] = 0; } array[j] += weight * src.get(); } }
public void setNormals(FloatBuffer normals) { normals.position(0); float[] n = new float[normals.capacity()]; normals.get(n); setNormals(n); }
public void setVertices(FloatBuffer vertices) { vertices.position(0); float[] v = new float[vertices.capacity()]; vertices.get(v); setVertices(v); }
private void writeCpuBuffer(int targetNumBuffers, MorphTarget mt) { if (targetNumBuffers >= 1) { FloatBuffer dest = mt.getBuffer(VertexBuffer.Type.Position); dest.rewind(); dest.put(tmpPosArray, 0, dest.capacity()); } if (targetNumBuffers >= 2) { FloatBuffer dest = mt.getBuffer(VertexBuffer.Type.Normal); dest.rewind(); dest.put(tmpNormArray, 0, dest.capacity()); } if (!approximateTangents && targetNumBuffers == 3) { FloatBuffer dest = mt.getBuffer(VertexBuffer.Type.Tangent); dest.rewind(); dest.put(tmpTanArray, 0, dest.capacity()); } }
void ensureCapacity(int size) { while (buffer.remaining() < size) { FloatBuffer newB = allocateDirect(buffer.capacity() * 2); buffer.flip(); newB.put(buffer); buffer = newB; } }
public static float[] getFloatArrayFromBuffer(FloatBuffer buffer) { float[] array = new float[0]; if (buffer != null) { if (buffer.hasArray()) { array = buffer.array(); } else { buffer.rewind(); array = new float[buffer.capacity()]; buffer.get(array); } } return array; }
/** * Creates a float array from the provided {@link FloatBuffer}. * * @param buffer {@link FloatBuffer} the data source. * @return float array containing the data of the buffer. */ public static float[] getFloatArrayFromBuffer(FloatBuffer buffer) { float[] array = null; if (buffer.hasArray()) { array = buffer.array(); } else { buffer.rewind(); array = new float[buffer.capacity()]; buffer.get(array); } return array; }
/** * Ensures there is at least the <code>required</code> number of entries * left after the current position of the buffer. If the buffer is too small * a larger one is created and the old one copied to the new buffer. * * @param buffer * buffer that should be checked/copied (may be null) * @param required * minimum number of elements that should be remaining in the * returned buffer * @return a buffer large enough to receive at least the * <code>required</code> number of entries, same position as the * input buffer, not null */ public static FloatBuffer ensureLargeEnough(FloatBuffer buffer, int required) { if (buffer != null) { buffer.limit(buffer.capacity()); } if (buffer == null || (buffer.remaining() < required)) { int position = (buffer != null ? buffer.position() : 0); FloatBuffer newVerts = createFloatBuffer(position + required); if (buffer != null) { buffer.flip(); newVerts.put(buffer); newVerts.position(position); } buffer = newVerts; } return buffer; }
float maxDepth = Float.NEGATIVE_INFINITY; buffer.clear(); while (buffer.position() < buffer.capacity()) { float depth = MathUtils.clamp(buffer.get(), 0, Float.POSITIVE_INFINITY); minDepth = Math.min(depth, minDepth);
private MorphTarget initCpuMorphTarget(Geometry geom) { MorphTarget res = new MorphTarget(); MorphTarget mt = geom.getMesh().getMorphTargets()[0]; FloatBuffer b = mt.getBuffer(VertexBuffer.Type.Position); if (b != null) { res.setBuffer(VertexBuffer.Type.Position, BufferUtils.createFloatBuffer(b.capacity())); } b = mt.getBuffer(VertexBuffer.Type.Normal); if (b != null) { res.setBuffer(VertexBuffer.Type.Normal, BufferUtils.createFloatBuffer(b.capacity())); } if (!approximateTangents) { b = mt.getBuffer(VertexBuffer.Type.Tangent); if (b != null) { res.setBuffer(VertexBuffer.Type.Tangent, BufferUtils.createFloatBuffer(b.capacity())); } } return res; }
public void updateInstances() { FloatBuffer fb = (FloatBuffer) transformInstanceData.getData(); fb.limit(fb.capacity()); fb.position(0);
/** * Maps the (x,y) coordinates of <code>tileName</code> in <code>atlas</code> * to the TextureCoordinates of this BaseObject3D * * Saves a copy of the original TextureCoordinates in case of future mapping. * * @param tileName * @param atlas */ public void setAtlasTile(String tileName, TextureAtlas atlas) { Tile tile = atlas.getTileNamed(tileName); if(mOriginalTextureCoords == null) { mOriginalTextureCoords = this.getGeometry().getTextureCoords().duplicate(); } FloatBuffer fb = FloatBuffer.allocate(mOriginalTextureCoords.capacity()); for (int i = 0; i < fb.capacity(); i++) { double uvIn = mOriginalTextureCoords.get(i); double uvOut; if (i % 2 == 0) { uvOut = (uvIn * (tile.width / atlas.getWidth())) + tile.x / atlas.getWidth(); } else { uvOut = (uvIn * (tile.height / atlas.getHeight())) + tile.y / atlas.getHeight(); } fb.put(i, (float) uvOut); } mGeometry.changeBufferData(mGeometry.getTexCoordBufferInfo(), fb, 0); }
if (vertexBuffer.getData() instanceof FloatBuffer) { FloatBuffer b = (FloatBuffer) vertexBuffer.getData(); float[] arr = new float[b.capacity()]; b.rewind(); b.get(arr);
private void initVao() { // Create VAO vaoHandle = glGenVertexArrays(gl); // Create UI VAO vaoUiHandle = glGenVertexArrays(gl); // Create UI buffer vboUiHandle = glGenBuffers(gl); gl.glBindVertexArray(vaoUiHandle); FloatBuffer vboUiBuf = GpuFloatBuffer.allocateDirect(5 * 4); vboUiBuf.put(new float[]{ // positions // texture coords 1f, 1f, 0.0f, 1.0f, 0f, // top right 1f, -1f, 0.0f, 1.0f, 1f, // bottom right -1f, -1f, 0.0f, 0.0f, 1f, // bottom left -1f, 1f, 0.0f, 0.0f, 0f // top left }); vboUiBuf.rewind(); gl.glBindBuffer(gl.GL_ARRAY_BUFFER, vboUiHandle); gl.glBufferData(gl.GL_ARRAY_BUFFER, vboUiBuf.capacity() * Float.BYTES, vboUiBuf, gl.GL_STATIC_DRAW); // position attribute gl.glVertexAttribPointer(0, 3, gl.GL_FLOAT, false, 5 * Float.BYTES, 0); gl.glEnableVertexAttribArray(0); // texture coord attribute gl.glVertexAttribPointer(1, 2, gl.GL_FLOAT, false, 5 * Float.BYTES, 3 * Float.BYTES); gl.glEnableVertexAttribArray(1); // unbind VBO gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0); }
public void testGet_io() throws IOException { assertEquals(-1, ArbitraryInstances.get(InputStream.class).read()); assertEquals(-1, ArbitraryInstances.get(ByteArrayInputStream.class).read()); assertEquals(-1, ArbitraryInstances.get(Readable.class).read(CharBuffer.allocate(1))); assertEquals(-1, ArbitraryInstances.get(Reader.class).read()); assertEquals(-1, ArbitraryInstances.get(StringReader.class).read()); assertEquals(0, ArbitraryInstances.get(Buffer.class).capacity()); assertEquals(0, ArbitraryInstances.get(CharBuffer.class).capacity()); assertEquals(0, ArbitraryInstances.get(ByteBuffer.class).capacity()); assertEquals(0, ArbitraryInstances.get(ShortBuffer.class).capacity()); assertEquals(0, ArbitraryInstances.get(IntBuffer.class).capacity()); assertEquals(0, ArbitraryInstances.get(LongBuffer.class).capacity()); assertEquals(0, ArbitraryInstances.get(FloatBuffer.class).capacity()); assertEquals(0, ArbitraryInstances.get(DoubleBuffer.class).capacity()); ArbitraryInstances.get(PrintStream.class).println("test"); ArbitraryInstances.get(PrintWriter.class).println("test"); assertNotNull(ArbitraryInstances.get(File.class)); assertFreshInstanceReturned( ByteArrayOutputStream.class, OutputStream.class, Writer.class, StringWriter.class, PrintStream.class, PrintWriter.class); assertEquals(ByteSource.empty(), ArbitraryInstances.get(ByteSource.class)); assertEquals(CharSource.empty(), ArbitraryInstances.get(CharSource.class)); assertNotNull(ArbitraryInstances.get(ByteSink.class)); assertNotNull(ArbitraryInstances.get(CharSink.class)); }