Package java.nio

Examples of java.nio.ByteBuffer


      final int num_image_formats = numBuffer.get(0);
      if ( num_image_formats == 0 )
        return null;

      final ByteBuffer formatBuffer = BufferUtils.createByteBuffer(num_image_formats * CLImageFormat.STRUCT_SIZE);
      clGetSupportedImageFormats(context, flags, image_type, formatBuffer, null);

      final List<CLImageFormat> formats = new ArrayList<CLImageFormat>(num_image_formats);
      for ( int i = 0; i < num_image_formats; i++ ) {
        final int offset = num_image_formats * CLImageFormat.STRUCT_SIZE;
        final CLImageFormat format = new CLImageFormat(
          formatBuffer.getInt(offset),
          formatBuffer.getInt(offset + 4)
        );
        if ( filter == null || filter.accept(format) )
          formats.add(format);
      }

View Full Code Here


     *
     * @param filename Name of file to load
     * @return ByteBuffer containing file data
     */
    protected ByteBuffer getData(String filename) {
        ByteBuffer buffer = null;

        System.out.println("Attempting to load: " + filename);
       
        try {
            BufferedInputStream bis = new BufferedInputStream(WaveData.class.getClassLoader().getResourceAsStream(filename));
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
           
            int bufferLength = 4096;
            byte[] readBuffer = new byte[bufferLength];
            int read = -1;
           
            while((read = bis.read(readBuffer, 0, bufferLength)) != -1) {
                baos.write(readBuffer, 0, read);
            }
           
            //done reading, close
            bis.close();
           
            // if ogg vorbis data, we need to pass it unmodified to alBufferData
            if(usingVorbis) {
              buffer = ByteBuffer.allocateDirect(baos.size());
            } else {
              buffer = ByteBuffer.allocate(baos.size());
            }
            buffer.order(ByteOrder.nativeOrder());
            buffer.put(baos.toByteArray());
            buffer.rewind();
        } catch (Exception ioe) {
            ioe.printStackTrace();
        }
        return buffer;
    }   
View Full Code Here

*          $Id: MacOSXContextImplementation.java 3116 2008-08-19 16:46:03Z spasi $
*/
final class MacOSXContextImplementation implements ContextImplementation {

  public ByteBuffer create(PeerInfo peer_info, IntBuffer attribs, ByteBuffer shared_context_handle) throws LWJGLException {
    ByteBuffer peer_handle = peer_info.lockAndGetHandle();
    try {
      return nCreate(peer_handle, attribs, shared_context_handle);
    } finally {
      peer_info.unlock();
    }
View Full Code Here

  }

  private static native void clearDrawable(ByteBuffer handle) throws LWJGLException;

  static void resetView(PeerInfo peer_info, Context context) throws LWJGLException {
    ByteBuffer peer_handle = peer_info.lockAndGetHandle();
    try {
      synchronized ( context ) {
        clearDrawable(context.getHandle());
        setView(peer_handle, context.getHandle());
      }
View Full Code Here

      peer_info.unlock();
    }
  }

  public void makeCurrent(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException {
    ByteBuffer peer_handle = peer_info.lockAndGetHandle();
    try {
      setView(peer_handle, handle);
      nMakeCurrent(handle);
    } finally {
      peer_info.unlock();
View Full Code Here

    }

    public long getProfilingInfoLong(final CLEvent event, final int param_name) {
      event.checkValid();

      final ByteBuffer buffer = APIUtil.getBufferByte(8);
      clGetEventProfilingInfo(event, param_name, buffer, null);

      return buffer.getLong(0);
    }
View Full Code Here

    }

    public long getWorkGroupInfoLong(final CLKernel kernel, final CLDevice device, final int param_name) {
      device.checkValid();

      final ByteBuffer buffer = APIUtil.getBufferByte(8);
      clGetKernelWorkGroupInfo(kernel, device, param_name, buffer, null);

      return buffer.getLong(0);
    }
View Full Code Here

        } else {
            srcPixelFormat = GL_RGB;
        }

        // convert that image into a byte buffer of texture data
        ByteBuffer textureBuffer = convertImageData(bufferedImage,texture);

        if (target == GL_TEXTURE_2D) {
            glTexParameteri(target, GL_TEXTURE_MIN_FILTER, minFilter);
            glTexParameteri(target, GL_TEXTURE_MAG_FILTER, magFilter);
        }
View Full Code Here

     * @param bufferedImage The image to convert to a texture
     * @param texture The texture to store the data into
     * @return A buffer containing the data
     */
    private ByteBuffer convertImageData(BufferedImage bufferedImage,Texture texture) {
        ByteBuffer imageBuffer;
        WritableRaster raster;
        BufferedImage texImage;

        int texWidth = 2;
        int texHeight = 2;

        // find the closest power of 2 for the width and height
        // of the produced texture
        while (texWidth < bufferedImage.getWidth()) {
            texWidth *= 2;
        }
        while (texHeight < bufferedImage.getHeight()) {
            texHeight *= 2;
        }

        texture.setTextureHeight(texHeight);
        texture.setTextureWidth(texWidth);

        // create a raster that can be used by OpenGL as a source
        // for a texture
        if (bufferedImage.getColorModel().hasAlpha()) {
            raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,texWidth,texHeight,4,null);
            texImage = new BufferedImage(glAlphaColorModel,raster,false,new Hashtable());
        } else {
            raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,texWidth,texHeight,3,null);
            texImage = new BufferedImage(glColorModel,raster,false,new Hashtable());
        }

        // copy the source image into the produced image
        Graphics g = texImage.getGraphics();
        g.setColor(new Color(0f,0f,0f,0f));
        g.fillRect(0,0,texWidth,texHeight);
        g.drawImage(bufferedImage,0,0,null);

        // build a byte buffer from the temporary image
        // that be used by OpenGL to produce a texture.
        byte[] data = ((DataBufferByte) texImage.getRaster().getDataBuffer()).getData();

        imageBuffer = ByteBuffer.allocateDirect(data.length);
        imageBuffer.order(ByteOrder.nativeOrder());
        imageBuffer.put(data, 0, data.length);
        imageBuffer.flip();

        return imageBuffer;
    }
View Full Code Here

    protected int getInfo(final CLMem mem, final int param_name, final ByteBuffer param_value, final PointerBuffer param_value_size_ret) {
      return clGetMemObjectInfo(mem, param_name, param_value, param_value_size_ret);
    }

    public CLMem createImage2D(final CLContext context, final long flags, final CLImageFormat image_format, final long image_width, final long image_height, final long image_row_pitch, final Buffer host_ptr, IntBuffer errcode_ret) {
      final ByteBuffer formatBuffer = APIUtil.getBufferByte(2 * 4);
      formatBuffer.putInt(0, image_format.getChannelOrder());
      formatBuffer.putInt(4, image_format.getChannelType());

      final long function_pointer = CLCapabilities.clCreateImage2D;
      BufferChecks.checkFunctionAddress(function_pointer);
      if ( errcode_ret != null )
        BufferChecks.checkBuffer(errcode_ret, 1);
View Full Code Here

TOP

Related Classes of java.nio.ByteBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.