Java Code Examples for java.nio.IntBuffer#capacity()

The following examples show how to use java.nio.IntBuffer#capacity() . 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: ImageUtils.java    From JglTF with MIT License 6 votes vote down vote up
/**
 * Interpret the given byte buffer as pixels, swizzle the bytes
 * of these pixels according to the given shifts, and return a 
 * a direct byte buffer containing the corresponding new pixels
 * 
 * @param pixels The input pixels
 * @param s0 The right-shift for byte 0 
 * @param s1 The right-shift for byte 1 
 * @param s2 The right-shift for byte 2
 * @param s3 The right-shift for byte 3
 * @return The output pixels
 */
private static ByteBuffer swizzle(ByteBuffer pixels,
    int s0, int s1, int s2, int s3)
{
    IntBuffer iBuffer = pixels.asIntBuffer();
    ByteBuffer oByteBuffer = ByteBuffer
        .allocateDirect(iBuffer.capacity() * Integer.BYTES)
        .order(pixels.order());
    IntBuffer oBuffer = oByteBuffer.asIntBuffer();
    for (int i = 0; i < iBuffer.capacity(); i++)
    {
        int input = iBuffer.get(i);
        int output = swizzle(input, s0, s1, s2, s3);
        oBuffer.put(i, output);
    }
    return oByteBuffer;
}
 
Example 2
Source File: GeometryRunner.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
private boolean detectTwoFaceTriangles(HashMapVirtualObject ifcProduct, IntBuffer indicesAsInt, DoubleBuffer verticesAsDouble, float margin) {
	Set<ComplexLine2> complexLines = new TreeSet<>();
	for (int i=0; i<indicesAsInt.capacity(); i+=3) {
		for (int j=0; j<3; j++) {
			int index1 = indicesAsInt.get(i + j);
			int index2 = indicesAsInt.get(i + (j + 1) % 3);
			
			ComplexLine2 line2 = new ComplexLine2(index1, index2, verticesAsDouble, margin);
			if (complexLines.contains(line2)) {
				complexLines.remove(line2);
			} else {
				complexLines.add(line2);
			}
		}
	}
	if (!complexLines.isEmpty()) {
		LOGGER.debug("Probably a non-closed object in " + ifcProduct.eClass().getName() + " (" + complexLines.size() + ")");
		return true;
	}
	return false;
}
 
Example 3
Source File: TestUnsafeOptimizeLongColumnBinaryMaker.java    From yosegi with Apache License 2.0 6 votes vote down vote up
@Test
public void T_chooseDictionaryIndexMaker_Short_1() throws IOException{
  UnsafeOptimizeLongColumnBinaryMaker.IDictionaryIndexMaker indexMaker = UnsafeOptimizeLongColumnBinaryMaker.chooseDictionaryIndexMaker( 0xFFFF );
  assertEquals( ( Short.BYTES * -1 ) , indexMaker.calcBinarySize( -1 ) );
  assertEquals( ( Short.BYTES * 0 ) , indexMaker.calcBinarySize( 0 ) );
  assertEquals( ( Short.BYTES * 256 ) , indexMaker.calcBinarySize( 256 ) );

  int[] dicIndex = new int[128];
  for( int i = 0,n = ( 0xFFFF - 256 ) ; i < dicIndex.length ; i++,n+=2 ){
    dicIndex[i] = n;
  }
  byte[] b = new byte[indexMaker.calcBinarySize( dicIndex.length ) ];
  indexMaker.create( dicIndex , b , 0 , b.length , ByteOrder.nativeOrder() );
  IntBuffer intBuffer = indexMaker.getIndexIntBuffer( b , 0 , b.length , ByteOrder.nativeOrder() );
  for( int i = 0 ; i < intBuffer.capacity() ; i++ ){
    assertEquals( dicIndex[i] , intBuffer.get() );
  }
}
 
Example 4
Source File: TestUnsafeOptimizeLongColumnBinaryMaker.java    From multiple-dimension-spread with Apache License 2.0 6 votes vote down vote up
@Test
public void T_chooseDictionaryIndexMaker_Short_1() throws IOException{
  UnsafeOptimizeLongColumnBinaryMaker.IDictionaryIndexMaker indexMaker = UnsafeOptimizeLongColumnBinaryMaker.chooseDictionaryIndexMaker( 0xFFFF );
  assertEquals( ( Short.BYTES * -1 ) , indexMaker.calcBinarySize( -1 ) );
  assertEquals( ( Short.BYTES * 0 ) , indexMaker.calcBinarySize( 0 ) );
  assertEquals( ( Short.BYTES * 256 ) , indexMaker.calcBinarySize( 256 ) );

  int[] dicIndex = new int[128];
  for( int i = 0,n = ( 0xFFFF - 256 ) ; i < dicIndex.length ; i++,n+=2 ){
    dicIndex[i] = n;
  }
  byte[] b = new byte[indexMaker.calcBinarySize( dicIndex.length ) ];
  indexMaker.create( dicIndex , b , 0 , b.length , ByteOrder.nativeOrder() );
  IntBuffer intBuffer = indexMaker.getIndexIntBuffer( b , 0 , b.length , ByteOrder.nativeOrder() );
  for( int i = 0 ; i < intBuffer.capacity() ; i++ ){
    assertEquals( dicIndex[i] , intBuffer.get() );
  }
}
 
Example 5
Source File: TestUnsafeOptimizeLongColumnBinaryMaker.java    From multiple-dimension-spread with Apache License 2.0 6 votes vote down vote up
@Test
public void T_chooseDictionaryIndexMaker_Byte_1() throws IOException{
  UnsafeOptimizeLongColumnBinaryMaker.IDictionaryIndexMaker indexMaker = UnsafeOptimizeLongColumnBinaryMaker.chooseDictionaryIndexMaker( 127 );
  assertEquals( ( Byte.BYTES * -1 ) , indexMaker.calcBinarySize( -1 ) );
  assertEquals( ( Byte.BYTES * 0 ) , indexMaker.calcBinarySize( 0 ) );
  assertEquals( ( Byte.BYTES * 256 ) , indexMaker.calcBinarySize( 256 ) );

  int[] dicIndex = new int[128];
  for( int i = 0,n = 0 ; i < dicIndex.length ; i++,n+=2 ){
    dicIndex[i] = n;
  }
  byte[] b = new byte[indexMaker.calcBinarySize( dicIndex.length ) ];
  indexMaker.create( dicIndex , b , 0 , b.length , ByteOrder.nativeOrder() );
  IntBuffer intBuffer = indexMaker.getIndexIntBuffer( b , 0 , b.length , ByteOrder.nativeOrder() );
  for( int i = 0 ; i < intBuffer.capacity() ; i++ ){
    assertEquals( dicIndex[i] , intBuffer.get() );
  }
}
 
Example 6
Source File: BaseOffHeapMutableDictionary.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
protected long getOffHeapMemUsed() {
  ValueToDictId valueToDictId = _valueToDict;
  long size = 0;
  for (IntBuffer iBuf : valueToDictId._iBufList) {
    size = size + iBuf.capacity() * Integer.BYTES;
  }
  return size;
}
 
Example 7
Source File: BitMapContainer.java    From Kylin with Apache License 2.0 5 votes vote down vote up
private ConciseSet bytesToSet(ImmutableBytesWritable bytes) {
    if (bytes.get() == null || bytes.getLength() == 0) {
        return new ConciseSet();
    } else {
        IntBuffer intBuffer = ByteBuffer.wrap(bytes.get(), bytes.getOffset(), bytes.getLength()).asIntBuffer();
        int[] words = new int[intBuffer.capacity()];
        intBuffer.get(words);
        return new ConciseSet(words, false);
    }
}
 
Example 8
Source File: HashingOutputStream.java    From systemsgenetics with GNU General Public License v3.0 5 votes vote down vote up
public static String hashString(byte[] bytes) {
    // assumes hash is a multiple of 4
    IntBuffer ib = ByteBuffer.wrap(bytes).asIntBuffer();
    StringBuilder sb = new StringBuilder();
    while (ib.position() < ib.capacity()) {
        long val = ib.get();
        if (val < 0) {
            val = -val + Integer.MAX_VALUE;
        }
        sb.append(Long.toString(val, 36));
    }
    return sb.toString();
}
 
Example 9
Source File: DumpArrayColumnBinaryMaker.java    From multiple-dimension-spread with Apache License 2.0 5 votes vote down vote up
public ArrayCellManager( final Spread spread , final IntBuffer buffer ){
  int length = buffer.capacity();
  cellArray = new ICell[length];
  int currentIndex = 0;
  for( int i = 0 ; i < length ; i++ ){
    int arrayLength = buffer.get();
    if( arrayLength != 0 ){
      int start = currentIndex;
      int end = start + arrayLength;
      cellArray[i] = new ArrayCell( new SpreadArrayLink( spread , i , start , end ) );
      currentIndex += arrayLength;
    }
  }
}
 
Example 10
Source File: TestStructureArrayBB.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void fillStructureArray(ArrayStructureBB sa) {
  ByteBuffer bb = sa.getByteBuffer();
  IntBuffer ibb = bb.asIntBuffer();
  int count = 0;
  for (int i = 0; i < ibb.capacity(); i++)
    ibb.put(i, count++);
}
 
Example 11
Source File: Buffers.java    From JglTF with MIT License 5 votes vote down vote up
/**
 * Convert the given input buffer into a direct byte buffer with native
 * byte order, by casting all elements to <code>byte</code>.
 * 
 * @param buffer The input buffer
 * @return The byte buffer
 */
public static ByteBuffer castToByteBuffer(IntBuffer buffer)
{
    ByteBuffer byteBuffer = 
        ByteBuffer.allocateDirect(buffer.capacity())
        .order(ByteOrder.nativeOrder());
    for (int i = 0; i < buffer.capacity(); i++)
    {
        byteBuffer.put(i, (byte) buffer.get(i));
    }
    return byteBuffer;
}
 
Example 12
Source File: UnitHelp.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
public static boolean socketPresent(final SocketUDT socket,
        final IntBuffer buffer) {
    for (int index = 0; index < buffer.capacity(); index++) {
        if (buffer.get(index) == socket.id()) {
            return true;
        }
    }
    return false;
}
 
Example 13
Source File: UnitHelp.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
/**
 * Display contents of a buffer.
 */
public static void logBuffer(final String title, final IntBuffer buffer) {
    for (int index = 0; index < buffer.capacity(); index++) {
        final int value = buffer.get(index);
        if (value == 0) {
            continue;
        }
        log.info(String.format("%s [id: 0x%08x]", title, value));
    }
}
 
Example 14
Source File: FloatToFixed.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static void convertToFloat(IntBuffer input, FloatBuffer output){
    if (output.capacity() < input.capacity())
        throw new RuntimeException("Output must be at least as large as input!");

    input.clear();
    output.clear();
    for (int i = 0; i < input.capacity(); i++){
        output.put( ((float)input.get() / (float)(1<<16)) );
    }
    output.flip();
}
 
Example 15
Source File: BufferDirectDictionaryLinkCellManager.java    From multiple-dimension-spread with Apache License 2.0 4 votes vote down vote up
public BufferDirectDictionaryLinkCellManager( final ColumnType columnType , final IDicManager dicManager , final IntBuffer dicIndexIntBuffer ){
  this.columnType = columnType;
  this.dicManager = dicManager;
  this.dicIndexIntBuffer = dicIndexIntBuffer;
  indexSize = dicIndexIntBuffer.capacity();
}
 
Example 16
Source File: Gl_450_query_statistics_arb.java    From jogl-samples with MIT License 4 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL4 gl4 = (GL4) gl;

    {
        gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        ByteBuffer pointer = gl4.glMapBufferRange(GL_UNIFORM_BUFFER, 0, Mat4.SIZE,
                GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

        Mat4 projection = glm.perspectiveFov_((float) Math.PI * 0.25f, windowSize.x, windowSize.y, 0.1f, 100.0f);
        Mat4 model = new Mat4(1.0f);
        pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(model).toFa_());

        // Make sure the uniform buffer is uploaded
        gl4.glUnmapBuffer(GL_UNIFORM_BUFFER);
    }

    gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y);
    gl4.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 1.0f, 1.0f, 1.0f}, 0);

    gl4.glBindProgramPipeline(pipelineName.get(0));
    gl4.glActiveTexture(GL_TEXTURE0);
    gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(0));
    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));

    gl4.glBeginQuery(GL_VERTICES_SUBMITTED_ARB, queryName.get(Statistics.VERTICES_SUBMITTED));
    gl4.glBeginQuery(GL_PRIMITIVES_SUBMITTED_ARB, queryName.get(Statistics.PRIMITIVES_SUBMITTED));
    gl4.glBeginQuery(GL_VERTEX_SHADER_INVOCATIONS_ARB, queryName.get(Statistics.VERTEX_SHADER_INVOCATIONS));
    gl4.glBeginQuery(GL_TESS_CONTROL_SHADER_PATCHES_ARB, queryName.get(Statistics.TESS_CONTROL_SHADER_PATCHES));
    gl4.glBeginQuery(GL_TESS_EVALUATION_SHADER_INVOCATIONS_ARB,
            queryName.get(Statistics.TESS_EVALUATION_SHADER_INVOCATIONS));
    gl4.glBeginQuery(GL_GEOMETRY_SHADER_INVOCATIONS, queryName.get(Statistics.GEOMETRY_SHADER_INVOCATIONS));
    gl4.glBeginQuery(GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB,
            queryName.get(Statistics.GEOMETRY_SHADER_PRIMITIVES_EMITTED));
    gl4.glBeginQuery(GL_FRAGMENT_SHADER_INVOCATIONS_ARB, queryName.get(Statistics.FRAGMENT_SHADER_INVOCATIONS));
    gl4.glBeginQuery(GL_COMPUTE_SHADER_INVOCATIONS_ARB, queryName.get(Statistics.COMPUTE_SHADER_INVOCATIONS));
    gl4.glBeginQuery(GL_CLIPPING_INPUT_PRIMITIVES_ARB, queryName.get(Statistics.CLIPPING_INPUT_PRIMITIVES));
    gl4.glBeginQuery(GL_CLIPPING_OUTPUT_PRIMITIVES_ARB, queryName.get(Statistics.CLIPPING_OUTPUT_PRIMITIVES));
    {
        gl4.glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0);
    }
    gl4.glEndQuery(GL_VERTICES_SUBMITTED_ARB);
    gl4.glEndQuery(GL_PRIMITIVES_SUBMITTED_ARB);
    gl4.glEndQuery(GL_VERTEX_SHADER_INVOCATIONS_ARB);
    gl4.glEndQuery(GL_TESS_CONTROL_SHADER_PATCHES_ARB);
    gl4.glEndQuery(GL_TESS_EVALUATION_SHADER_INVOCATIONS_ARB);
    gl4.glEndQuery(GL_GEOMETRY_SHADER_INVOCATIONS);
    gl4.glEndQuery(GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB);
    gl4.glEndQuery(GL_FRAGMENT_SHADER_INVOCATIONS_ARB);
    gl4.glEndQuery(GL_COMPUTE_SHADER_INVOCATIONS_ARB);
    gl4.glEndQuery(GL_CLIPPING_INPUT_PRIMITIVES_ARB);
    gl4.glEndQuery(GL_CLIPPING_OUTPUT_PRIMITIVES_ARB);

    IntBuffer queryResult = GLBuffers.newDirectIntBuffer(Statistics.MAX);
    for (int i = 0; i < queryResult.capacity(); ++i) {
        gl4.glGetQueryObjectuiv(queryName.get(i), GL_QUERY_RESULT, queryResult);
    }
    System.out.println("Verts: " + queryResult.get(Statistics.VERTICES_SUBMITTED)
            + "; Prims: (" + queryResult.get(Statistics.PRIMITIVES_SUBMITTED) + ", "
            + queryResult.get(Statistics.GEOMETRY_SHADER_PRIMITIVES_EMITTED)
            + "); Shaders(" + queryResult.get(Statistics.VERTEX_SHADER_INVOCATIONS) + ", "
            + queryResult.get(Statistics.TESS_CONTROL_SHADER_PATCHES) + ", "
            + queryResult.get(Statistics.TESS_EVALUATION_SHADER_INVOCATIONS) + ", "
            + queryResult.get(Statistics.GEOMETRY_SHADER_INVOCATIONS) + ", "
            + queryResult.get(Statistics.FRAGMENT_SHADER_INVOCATIONS) + ", "
            + queryResult.get(Statistics.COMPUTE_SHADER_INVOCATIONS)
            + "); Clip(" + queryResult.get(Statistics.CLIPPING_INPUT_PRIMITIVES) + ", "
            + queryResult.get(Statistics.CLIPPING_OUTPUT_PRIMITIVES) + ")\r");

    return true;
}
 
Example 17
Source File: OffHeapHashMap.java    From offheap-store with Apache License 2.0 4 votes vote down vote up
@Override
public long getTableCapacity() {
  IntBuffer table = hashtable;
  return table == null ? 0 : table.capacity() / ENTRY_SIZE;
}
 
Example 18
Source File: UnitHelp.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
/**
 * Zero out buffer.
 */
public static void clear(final IntBuffer buffer) {
    for (int index = 0; index < buffer.capacity(); index++) {
        buffer.put(index, 0);
    }
}
 
Example 19
Source File: Gl_430_perf_monitor_amd.java    From jogl-samples with MIT License 4 votes vote down vote up
public Monitor(GL2 gl2, Gl_430_perf_monitor_amd app) {

            name = GLBuffers.newDirectIntBuffer(1);

            int GROUP_NAME_SIZE = 256;

            IntBuffer groupSize = GLBuffers.newDirectIntBuffer(1);
            gl2.glGetPerfMonitorGroupsAMD(groupSize, 0, null);

            IntBuffer groups_ = GLBuffers.newDirectIntBuffer(groupSize.get(0));
            gl2.glGetPerfMonitorGroupsAMD(null, groupSize.get(0), groups_);

            for (int groupIndex = 0; groupIndex < groups_.capacity(); groupIndex++) {

                ByteBuffer groupName = GLBuffers.newDirectByteBuffer(GROUP_NAME_SIZE);
                gl2.glGetPerfMonitorGroupStringAMD(groups_.get(groupIndex), GROUP_NAME_SIZE, null, groupName);

                IntBuffer numCounters = GLBuffers.newDirectIntBuffer(1);
                IntBuffer maxActiveCounters = GLBuffers.newDirectIntBuffer(1);
                gl2.glGetPerfMonitorCountersAMD(groups_.get(groupIndex), numCounters, maxActiveCounters, 0, null);

                IntBuffer counters = GLBuffers.newDirectIntBuffer(numCounters.get(0));
                gl2.glGetPerfMonitorCountersAMD(groups_.get(groupIndex), null, null, numCounters.get(0), counters);

                for (int counterIndex = 0; counterIndex < counters.capacity(); counterIndex++) {

                    ByteBuffer counterName = GLBuffers.newDirectByteBuffer(GROUP_NAME_SIZE);

                    gl2.glGetPerfMonitorCounterStringAMD(groups_.get(groupIndex), counters.get(counterIndex),
                            GROUP_NAME_SIZE, null, counterName);

                    BufferUtils.destroyDirectBuffer(counterName);
                }

                String groupString = "";
                for (int i = 0; i < groupName.capacity(); ++i) {
                    if ((char) (groupName.get(i) & 0xff) == '\0') {
                        break;
                    } else {
                        groupString += (char) (groupName.get(i) & 0xff);
                    }
                }

                groups.put(groups_.get(groupIndex), new Group(groupString, counters));
                stringToGroup.put(groupString, groups_.get(groupIndex));

                BufferUtils.destroyDirectBuffer(groupName);
                BufferUtils.destroyDirectBuffer(numCounters);
                BufferUtils.destroyDirectBuffer(maxActiveCounters);
                BufferUtils.destroyDirectBuffer(counters);
            }

            gl2.glGenPerfMonitorsAMD(1, name);
        }
 
Example 20
Source File: FrameRenderer.java    From tango with MIT License 4 votes vote down vote up
@Override
public void onDrawFrame(GL10 gl) {
    activity_.updateTexture(TangoCameraIntrinsics.TANGO_CAMERA_COLOR);

    if (!saveNextFrame_) {
        glBindBuffer(GL_ARRAY_BUFFER, videoVertexBuffer_);
        glVertexAttribPointer(videoVertexAttribute_, 2, GL_BYTE, false, 0, 0);
        glEnableVertexAttribArray(videoVertexAttribute_);
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, videoTextureName_);
        glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    }
    else {
        Log.i(activity_.TAG, "Saving Image");
        // Switch to the offscreen buffer.
        glBindFramebuffer(GL_FRAMEBUFFER, offscreenBuffer_);

        // Save current viewport and change to offscreen size.
        IntBuffer viewport = IntBuffer.allocate(4);
        glGetIntegerv(GL_VIEWPORT, viewport);
        glViewport(0, 0, offscreenSize_.x, offscreenSize_.y);

        // Render in capture mode. Setting this flags tells the shader
        // program to draw the texture right-side up and change the color
        // order to ARGB for compatibility with Bitmap.
        glUniform1i(glGetUniformLocation(videoProgram_, "cap"), 1);

        // Render.
        glBindBuffer(GL_ARRAY_BUFFER, videoVertexBuffer_);
        glVertexAttribPointer(videoVertexAttribute_, 2, GL_BYTE, false, 0, 0);
        glEnableVertexAttribArray(videoVertexAttribute_);
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, videoTextureName_);
        glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

        // Read offscreen buffer.
        IntBuffer intBuffer = ByteBuffer.allocateDirect(offscreenSize_.x * offscreenSize_.y * 4)
                .order(ByteOrder.nativeOrder())
                .asIntBuffer();
        glReadPixels(0, 0, offscreenSize_.x, offscreenSize_.y, GL_RGBA, GL_UNSIGNED_BYTE, intBuffer.rewind());

        // Restore onscreen state.
        glBindFramebuffer(GL_FRAMEBUFFER, 0);
        glViewport(viewport.get(0), viewport.get(1), viewport.get(2), viewport.get(3));
        glUniform1i(glGetUniformLocation(videoProgram_, "cap"), 0);

        // Convert to an array for Bitmap.createBitmap().
        int[] pixels = new int[intBuffer.capacity()];
        intBuffer.rewind();
        intBuffer.get(pixels);
        saveNextFrame_ = false;

        try {
            // Create/access a pictures subdirectory.
            File directory = new File(
                    Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS),
                    "myScans");
            if (!directory.mkdirs() && !directory.isDirectory()) {
                Toast.makeText(
                        activity_,
                        "Could not access save directory",
                        Toast.LENGTH_SHORT).show();
                return;
            }

            // Get the current capture index to construct a unique filename.
            SharedPreferences prefs = activity_.getPreferences(Context.MODE_PRIVATE);

            // Create the capture file.
            String filename = String.format("tango%05d.png", activity_.scanNumber-1);
            Log.i(activity_.TAG, String.format("Saving to %s", filename));
            File file = new File(directory, filename);
            FileOutputStream fileOutputStream = new FileOutputStream(file);

            // Bitmap conveniently provides file output.
            Bitmap bitmap = Bitmap.createBitmap(pixels, offscreenSize_.x, offscreenSize_.y, Bitmap.Config.ARGB_8888);
            bitmap.compress(Bitmap.CompressFormat.PNG, 90, fileOutputStream);
            fileOutputStream.close();

            // Make the new file visible to other apps.
            activity_.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}