Package java.nio

Examples of java.nio.IntBuffer


   * @param contextRefresh Refresh rate to add
   * @param contextSynchronized Whether to synchronize the context
   * @return
   */
  static IntBuffer createAttributeList(int contextFrequency, int contextRefresh, int contextSynchronized) {
    IntBuffer attribList = BufferUtils.createIntBuffer(7);

    attribList.put(ALC10.ALC_FREQUENCY);
    attribList.put(contextFrequency);
    attribList.put(ALC10.ALC_REFRESH);
    attribList.put(contextRefresh);
    attribList.put(ALC10.ALC_SYNC);
    attribList.put(contextSynchronized);
    attribList.put(0); //terminating int

    return attribList;
  }
View Full Code Here


        }
       
        int lastError;
       
        //create 1 buffer and 1 source
        IntBuffer buffers = BufferUtils.createIntBuffer(1);
        IntBuffer sources = BufferUtils.createIntBuffer(1);       
       
        // al generate buffers and sources
        buffers.position(0).limit(1);
        AL10.alGenBuffers(buffers);
        if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
            exit(lastError);
        }

        sources.position(0).limit(1);
        AL10.alGenSources(sources);
        if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
            exit(lastError);
        }
       
        //load wave data
        ByteBuffer filebuffer = getData(args[0]);
        if(filebuffer == null) {
            System.out.println("Error loading file: " + args[0]);
            System.exit(-1);
        }
       
        System.out.println("loaded " + filebuffer.capacity());
       
        //ALUTLoadWAVData file = alut.loadWAVMemory(Sys.getDirectBufferAddress(filebuffer));
        if(usingVorbis) {
          // pass directly to buffer data
          AL10.alBufferData(buffers.get(0), AL10.AL_FORMAT_VORBIS_EXT, filebuffer, -1);
          filebuffer.clear();
        } else {
          // load wave data from buffer
          WaveData wavefile = WaveData.create(filebuffer.array());

          //copy to buffers
          AL10.alBufferData(buffers.get(0), wavefile.format, wavefile.data, wavefile.samplerate);
       
          //unload file again
          wavefile.dispose();       
        }
       
        // check for errors
        if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
            exit(lastError);
        }
 
       
        //set up source input           
        AL10.alSourcei(sources.get(0), AL10.AL_BUFFER, buffers.get(0));
        if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
            exit(lastError);
        }       
       
        //lets loop the sound
        AL10.alSourcei(sources.get(0), AL10.AL_LOOPING, AL10.AL_TRUE);
        if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
            exit(lastError);
        }       
       
        //play source 0
        AL10.alSourcePlay(sources.get(0));
        if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
            exit(lastError);
        }       
       
        //wait 5 secs
        try {
            System.out.println("Waiting 5 seconds for sound to complete");
            Thread.sleep(5000);
        } catch (InterruptedException inte) {
        }
       
        //stop source 0
        AL10.alSourceStop(sources.get(0));
        if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
            exit(lastError);
        }       
       
        //delete buffers and sources
        sources.position(0).limit(1);
        AL10.alDeleteSources(sources);
        if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
            exit(lastError);
        }
       
View Full Code Here

  /**
   * Creates the actual cursor, using a platform specific class
   */
  private static CursorElement[] createCursors(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException {
    // create copy and flip images to match ogl
    IntBuffer images_copy = BufferUtils.createIntBuffer(images.remaining());
    flipImages(width, height, numImages, images, images_copy);

    // Win32 doesn't (afaik) allow for animation based cursors, except when they're
    // in the .ani format, which we don't support.
    // The cursor animation was therefor developed using java side time tracking.
    // unfortunately X flickers when changing cursor. We therefore check for either
    // Win32 or X and do accordingly. This hasn't been implemented on Mac, but we
    // might want to split it into a X/Win/Mac cursor if it gets too cluttered

    CursorElement[] cursors;
    switch (LWJGLUtil.getPlatform()) {
      case LWJGLUtil.PLATFORM_MACOSX:
        /* Fall through */
      case LWJGLUtil.PLATFORM_WINDOWS:
        // create our cursor elements
        cursors = new CursorElement[numImages];
        for(int i=0; i<numImages; i++) {

          // iterate through the images, and make sure that the pixels are either 0xffxxxxxx or 0x00000000
          int size = width * height;
          for(int j=0; j<size; j++) {
            int index = j + (i*size);
            int alpha = images_copy.get(index) >> 24 & 0xff;
            if(alpha != 0xff) {
              images_copy.put(index, 0);
            }
          }

          Object handle = Mouse.getImplementation().createCursor(width, height, xHotspot, yHotspot, 1, images_copy, null);
          long delay = (delays != null) ? delays.get(i) : 0;
          long timeout = System.currentTimeMillis();
          cursors[i] = new CursorElement(handle, delay, timeout);

          // offset to next image
          images_copy.position(width*height*(i+1));
        }
        break;
      case LWJGLUtil.PLATFORM_LINUX:
        // create our cursor elements
        Object handle = Mouse.getImplementation().createCursor(width, height, xHotspot, yHotspot, numImages, images_copy, delays);
View Full Code Here

      return clCreateContextFromType(properties, device_type, pfn_notify, errcode_ret);
    }

    public List<CLImageFormat> getSupportedImageFormats(final CLContext context, final long flags, final int image_type, final Filter<CLImageFormat> filter) {
      final IntBuffer numBuffer = APIUtil.getBufferInt();
      clGetSupportedImageFormats(context, flags, image_type, null, numBuffer);

      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);
View Full Code Here

    cursors = new Cursor[3];

    int cursorImageCount = 1;
    int cursorWidth = Math.min(64, Cursor.getMaxCursorSize());
    int cursorHeight = cursorWidth;
    IntBuffer cursorImages;
    IntBuffer cursorDelays;


    // Create a single cursor
    // ==================================
    cursorImages = ByteBuffer.allocateDirect(cursorWidth*cursorHeight*cursorImageCount*4).order(ByteOrder.nativeOrder()).asIntBuffer();
    cursorDelays = null;
    for(int j=0; j<cursorWidth; j++) {
      for(int l=0; l<cursorHeight; l++) {
        cursorImages.put(0xffffffff);
      }
    }
    cursorImages.flip();
    cursors[0] = new Cursor(cursorWidth, cursorHeight, cursorWidth/2, cursorHeight/2, cursorImageCount, cursorImages, cursorDelays);
    // ----------------------------------

    // Create 3 piece animation
    // ==================================
    cursorImageCount = 3;
    cursorImages = ByteBuffer.allocateDirect(cursorWidth*cursorHeight*cursorImageCount*4).order(ByteOrder.nativeOrder()).asIntBuffer();
    cursorDelays = ByteBuffer.allocateDirect(cursorImageCount*4).order(ByteOrder.nativeOrder()).asIntBuffer();
    for(int i=0; i<cursorImageCount; i++) {

      // make a colored square with a chocolate center
      int offColor = 0x00000000;
      int onColor = 0xffff0000;

      // change color according to cursor
      if(i == 1) {
        onColor = 0xff00ff00;
      } else if (i == 2) {
        onColor = 0xff0000ff;
      }

      // calculate size of center
      int centerSize  = (cursorWidth / 5) * (i + 1);
      int centerLeft  = cursorWidth / 2 - centerSize / 2;
      int centerRight = cursorWidth / 2 + centerSize / 2;

      // go!
      for(int j=0; j<cursorWidth; j++) {
        for(int l=0; l<cursorHeight; l++) {
          if(j >= centerLeft && j < centerRight && l >= centerLeft && l < centerRight) {
            cursorImages.put(offColor);
          } else {
            cursorImages.put(onColor);
          }
        }
      }
    }
    cursorDelays.put(2000).put(2000).put(2000);
    cursorDelays.flip();
    cursorImages.flip();

    cursors[1] = new Cursor(cursorWidth, cursorHeight, cursorWidth/2, cursorHeight/2, cursorImageCount, cursorImages, cursorDelays);
    // ----------------------------------


    // Create a 20 piece animation
    // ==================================
    cursorImageCount = 20;
    cursorImages = ByteBuffer.allocateDirect(cursorWidth*cursorHeight*cursorImageCount*4).order(ByteOrder.nativeOrder()).asIntBuffer();
    cursorDelays = ByteBuffer.allocateDirect(cursorImageCount*4).order(ByteOrder.nativeOrder()).asIntBuffer();
    cursorDelays.put(
                     new int[] {
                         100, 100, 100, 100, 100,
                        100, 100, 100, 100, 100,
                        100, 100, 100, 100, 100,
                        100, 100, 100, 100, 100
                     });

    float step = 0xffffffff / 20.0f;
    for(int i=0; i<cursorImageCount; i++) {
      for(int j=0; j<cursorWidth; j++) {
        for(int l=0; l<cursorHeight; l++) {
          cursorImages.put((int)step);
        }
      }
      step += step;
    }
    cursorImages.flip();
    cursorDelays.flip();
    cursors[2] = new Cursor(cursorWidth, cursorHeight, cursorWidth/2, cursorHeight/2, cursorImageCount, cursorImages, cursorDelays);
    // ----------------------------------

    Mouse.setNativeCursor(cursors[0]);
  }
View Full Code Here

    }

    public int getGLObjectType(final CLMem mem) {
      mem.checkValid();

      final IntBuffer buffer = APIUtil.getBufferInt();
      clGetGLObjectInfo(mem, buffer, null);

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

    }

    public int getGLObjectName(final CLMem mem) {
      mem.checkValid();

      final IntBuffer buffer = APIUtil.getBufferInt();
      clGetGLObjectInfo(mem, null, buffer);

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

    protected int getInfo(final CLPlatform platform, final int param_name, final ByteBuffer param_value, final PointerBuffer param_value_size_ret) {
      return clGetPlatformInfo(platform, param_name, param_value, param_value_size_ret);
    }

    public List<CLPlatform> getPlatforms(final Filter<CLPlatform> filter) {
      final IntBuffer numBuffer = APIUtil.getBufferInt();
      clGetPlatformIDs(null, numBuffer);

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

      final PointerBuffer platformIDs = APIUtil.getBufferPointer(num_platforms);
      clGetPlatformIDs(platformIDs, null);
View Full Code Here

    }

    public List<CLDevice> getDevices(final CLPlatform platform, final int device_type, final Filter<CLDevice> filter) {
      platform.checkValid();

      final IntBuffer numBuffer = APIUtil.getBufferInt();
      clGetDeviceIDs(platform, device_type, null, numBuffer);

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

      final PointerBuffer deviceIDs = APIUtil.getBufferPointer(num_devices);
      clGetDeviceIDs(platform, device_type, deviceIDs, null);
View Full Code Here

          throw new IllegalArgumentException("Unsupported parameter: " + LWJGLUtil.toHexString(param_name));
      }
    }

    public CLKernel[] createKernelsInProgram(final CLProgram program) {
      final IntBuffer numBuffer = APIUtil.getBufferInt();
      clCreateKernelsInProgram(program, null, numBuffer);

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

      final PointerBuffer kernelIDs = APIUtil.getBufferPointer(num_kernels);
      clCreateKernelsInProgram(program, kernelIDs, null);
View Full Code Here

TOP

Related Classes of java.nio.IntBuffer

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.