Java Code Examples for com.jme3.util.BufferUtils#createIntBuffer()

The following examples show how to use com.jme3.util.BufferUtils#createIntBuffer() . 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: GeoMap.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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;
}
 
Example 2
Source File: GeoMap.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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;
}
 
Example 3
Source File: VertexBuffer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Creates a {@link Buffer} that satisfies the given type and size requirements
 * of the parameters. The buffer will be of the type specified by
 * {@link Format format} and would be able to contain the given number
 * of elements with the given number of components in each element.
 */
public static Buffer createBuffer(Format format, int components, int numElements){
    if (components < 1 || components > 4)
        throw new IllegalArgumentException("Num components must be between 1 and 4");

    int total = numElements * components;

    switch (format){
        case Byte:
        case UnsignedByte:
            return BufferUtils.createByteBuffer(total);
        case Half:
            return BufferUtils.createByteBuffer(total * 2);
        case Short:
        case UnsignedShort:
            return BufferUtils.createShortBuffer(total);
        case Int:
        case UnsignedInt:
            return BufferUtils.createIntBuffer(total);
        case Float:
            return BufferUtils.createFloatBuffer(total);
        case Double:
            return BufferUtils.createDoubleBuffer(total);
        default:
            throw new UnsupportedOperationException("Unrecoginized buffer format: "+format);
    }
}
 
Example 4
Source File: TestTangentGen.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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;
}
 
Example 5
Source File: OculusViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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
}
 
Example 6
Source File: MeshLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
}
 
Example 7
Source File: VertexBuffer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates a {@link Buffer} that satisfies the given type and size requirements
 * of the parameters. The buffer will be of the type specified by
 * {@link Format format} and would be able to contain the given number
 * of elements with the given number of components in each element.
 */
public static Buffer createBuffer(Format format, int components, int numElements) {
    if (components < 1 || components > 4) {
        throw new IllegalArgumentException("Num components must be between 1 and 4");
    }

    int total = numElements * components;

    switch (format) {
        case Byte:
        case UnsignedByte:
            return BufferUtils.createByteBuffer(total);
        case Half:
            return BufferUtils.createByteBuffer(total * 2);
        case Short:
        case UnsignedShort:
            return BufferUtils.createShortBuffer(total);
        case Int:
        case UnsignedInt:
            return BufferUtils.createIntBuffer(total);
        case Float:
            return BufferUtils.createFloatBuffer(total);
        case Double:
            return BufferUtils.createDoubleBuffer(total);
        default:
            throw new UnsupportedOperationException("Unrecoginized buffer format: " + format);
    }
}
 
Example 8
Source File: MeshLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
}
 
Example 9
Source File: TestTangentGen.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
  }
 
Example 10
Source File: FloatToFixed.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static VertexBuffer convertToFixed(VertexBuffer vb){
    if (vb.getFormat() == Format.Int)
        return vb;

    FloatBuffer fb = (FloatBuffer) vb.getData();
    IntBuffer ib = BufferUtils.createIntBuffer(fb.capacity());
    convertToFixed(fb, ib);

    VertexBuffer newVb = new VertexBuffer(vb.getBufferType());
    newVb.setupData(vb.getUsage(),
                    vb.getNumComponents(),
                    Format.Int,
                    ib);
    return newVb;
}
 
Example 11
Source File: CursorLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
CursorImageData(BufferedImage[] bi, int delay, int hsX, int hsY, int curType) {
    // cursor type
    // 0 - Undefined (an array of images inside an ICO)
    // 1 - ICO
    // 2 - CUR
    IntBuffer singleCursor = null;
    ArrayList<IntBuffer> cursors = new ArrayList<IntBuffer>();
    int bwidth = 0;
    int bheight = 0;
    boolean multIcons = false;

    // make the cursor image
    for (int i = 0; i < bi.length; i++) {
        BufferedImage img = bi[i];
        bwidth = img.getWidth();
        bheight = img.getHeight();
        if (curType == 1) {
            hsX = 0;
            hsY = bheight - 1;
        } else if (curType == 2) {
            if (hsY == 0) {
                // make sure we flip if 0
                hsY = bheight - 1;
            }
        } else {
            // We force to choose 32x32 icon from
            // the array of icons in that ICO file.
            if (bwidth != 32 && bheight != 32) {
                multIcons = true;
                continue;
            } else {
                if (img.getType() != 2) {
                    continue;
                } else {
                    // force hotspot
                    hsY = bheight - 1;
                }
            }
        }

        // We flip our image because .ICO and .CUR will always be reversed.
        AffineTransform trans = AffineTransform.getScaleInstance(1, -1);
        trans.translate(0, -img.getHeight(null));
        AffineTransformOp op = new AffineTransformOp(trans, AffineTransformOp.TYPE_BILINEAR);
        img = op.filter(img, null);

        singleCursor = BufferUtils.createIntBuffer(img.getWidth() * img.getHeight());
        DataBufferInt dataIntBuf = (DataBufferInt) img.getData().getDataBuffer();
        singleCursor = IntBuffer.wrap(dataIntBuf.getData());
        cursors.add(singleCursor);
    }

    int count;
    if (multIcons) {
        bwidth = 32;
        bheight = 32;
        count = 1;
    } else {
        count = cursors.size();
    }
    // put the image in the IntBuffer
    data = BufferUtils.createIntBuffer(bwidth * bheight);
    imgDelay = BufferUtils.createIntBuffer(bi.length);
    for (int i = 0; i < count; i++) {
        data.put(cursors.get(i));
        if (delay > 0) {
            imgDelay.put(delay);
        }
    }
    width = bwidth;
    height = bheight;
    xHotSpot = hsX;
    yHotSpot = hsY;
    numImages = count;
    data.rewind();
    if (imgDelay != null) {
        imgDelay.rewind();
    }
}
 
Example 12
Source File: VertexBuffer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Reduces the capacity of the buffer to the given amount
 * of elements, any elements at the end of the buffer are truncated
 * as necessary.
 *
 * @param numElements The number of elements to reduce to.
 */
public void compact(int numElements){
    int total = components * numElements;
    data.clear();
    switch (format){
        case Byte:
        case UnsignedByte:
        case Half:
            ByteBuffer bbuf = (ByteBuffer) data;
            bbuf.limit(total);
            ByteBuffer bnewBuf = BufferUtils.createByteBuffer(total);
            bnewBuf.put(bbuf);
            data = bnewBuf;
            break;
        case Short:
        case UnsignedShort:
            ShortBuffer sbuf = (ShortBuffer) data;
            sbuf.limit(total);
            ShortBuffer snewBuf = BufferUtils.createShortBuffer(total);
            snewBuf.put(sbuf);
            data = snewBuf;
            break;
        case Int:
        case UnsignedInt:
            IntBuffer ibuf = (IntBuffer) data;
            ibuf.limit(total);
            IntBuffer inewBuf = BufferUtils.createIntBuffer(total);
            inewBuf.put(ibuf);
            data = inewBuf;
            break;
        case Float:
            FloatBuffer fbuf = (FloatBuffer) data;
            fbuf.limit(total);
            FloatBuffer fnewBuf = BufferUtils.createFloatBuffer(total);
            fnewBuf.put(fbuf);
            data = fnewBuf;
            break;
        default:
            throw new UnsupportedOperationException("Unrecognized buffer format: "+format);
    }
    data.clear();
    setUpdateNeeded();
    dataSizeChanged = true;
}
 
Example 13
Source File: ALAudioRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void initOpenAL() {
    try {
        if (!alc.isCreated()) {
            alc.createALC();
        }
    } catch (UnsatisfiedLinkError ex) {
        logger.log(Level.SEVERE, "Failed to load audio library", ex);
        audioDisabled = true;
        return;
    }

    // Find maximum # of sources supported by this implementation
    ArrayList<Integer> channelList = new ArrayList<Integer>();
    for (int i = 0; i < MAX_NUM_CHANNELS; i++) {
        int chan = al.alGenSources();
        if (al.alGetError() != 0) {
            break;
        } else {
            channelList.add(chan);
        }
    }

    channels = new int[channelList.size()];
    for (int i = 0; i < channels.length; i++) {
        channels[i] = channelList.get(i);
    }

    ib = BufferUtils.createIntBuffer(channels.length);
    chanSrcs = new AudioSource[channels.length];

    final String deviceName = alc.alcGetString(ALC.ALC_DEVICE_SPECIFIER);

    logger.log(Level.INFO, "Audio Renderer Information\n" +
                    " * Device: {0}\n" +
                    " * Vendor: {1}\n" +
                    " * Renderer: {2}\n" +
                    " * Version: {3}\n" +
                    " * Supported channels: {4}\n" +
                    " * ALC extensions: {5}\n" +
                    " * AL extensions: {6}",
            new Object[]{
                    deviceName,
                    al.alGetString(AL_VENDOR),
                    al.alGetString(AL_RENDERER),
                    al.alGetString(AL_VERSION),
                    channels.length,
                    alc.alcGetString(ALC.ALC_EXTENSIONS),
                    al.alGetString(AL_EXTENSIONS)
            });

    // Pause device is a feature used specifically on Android
    // where the application could be closed but still running,
    // thus the audio context remains open but no audio should be playing.
    supportPauseDevice = alc.alcIsExtensionPresent("ALC_SOFT_pause_device");
    if (!supportPauseDevice) {
        logger.log(Level.WARNING, "Pausing audio device not supported.");
    }
    
    supportEfx = alc.alcIsExtensionPresent("ALC_EXT_EFX");
    if (supportEfx) {
        ib.position(0).limit(1);
        alc.alcGetInteger(EFX.ALC_EFX_MAJOR_VERSION, ib, 1);
        int major = ib.get(0);
        ib.position(0).limit(1);
        alc.alcGetInteger(EFX.ALC_EFX_MINOR_VERSION, ib, 1);
        int minor = ib.get(0);
        logger.log(Level.INFO, "Audio effect extension version: {0}.{1}", new Object[]{major, minor});

        alc.alcGetInteger(EFX.ALC_MAX_AUXILIARY_SENDS, ib, 1);
        auxSends = ib.get(0);
        logger.log(Level.INFO, "Audio max auxiliary sends: {0}", auxSends);

        // create slot
        ib.position(0).limit(1);
        efx.alGenAuxiliaryEffectSlots(1, ib);
        reverbFxSlot = ib.get(0);

        // create effect
        ib.position(0).limit(1);
        efx.alGenEffects(1, ib);
        reverbFx = ib.get(0);
        efx.alEffecti(reverbFx, EFX.AL_EFFECT_TYPE, EFX.AL_EFFECT_REVERB);

        // attach reverb effect to effect slot
        efx.alAuxiliaryEffectSloti(reverbFxSlot, EFX.AL_EFFECTSLOT_EFFECT, reverbFx);
    } else {
        logger.log(Level.WARNING, "OpenAL EFX not available! Audio effects won't work.");
    }
}
 
Example 14
Source File: VertexBuffer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Reduces the capacity of the buffer to the given amount
 * of elements, any elements at the end of the buffer are truncated
 * as necessary.
 *
 * @param numElements The number of elements to reduce to.
 */
public void compact(int numElements) {
    int total = components * numElements;
    data.clear();
    switch (format) {
        case Byte:
        case UnsignedByte:
        case Half:
            ByteBuffer bbuf = (ByteBuffer) data;
            bbuf.limit(total);
            ByteBuffer bnewBuf = BufferUtils.createByteBuffer(total);
            bnewBuf.put(bbuf);
            data = bnewBuf;
            break;
        case Short:
        case UnsignedShort:
            ShortBuffer sbuf = (ShortBuffer) data;
            sbuf.limit(total);
            ShortBuffer snewBuf = BufferUtils.createShortBuffer(total);
            snewBuf.put(sbuf);
            data = snewBuf;
            break;
        case Int:
        case UnsignedInt:
            IntBuffer ibuf = (IntBuffer) data;
            ibuf.limit(total);
            IntBuffer inewBuf = BufferUtils.createIntBuffer(total);
            inewBuf.put(ibuf);
            data = inewBuf;
            break;
        case Float:
            FloatBuffer fbuf = (FloatBuffer) data;
            fbuf.limit(total);
            FloatBuffer fnewBuf = BufferUtils.createFloatBuffer(total);
            fnewBuf.put(fbuf);
            data = fnewBuf;
            break;
        default:
            throw new UnsupportedOperationException("Unrecognized buffer format: " + format);
    }
    data.clear();
    setUpdateNeeded();
    dataSizeChanged = true;
}
 
Example 15
Source File: GLRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public int[] generateProfilingTasks(int numTasks) {
    IntBuffer ids = BufferUtils.createIntBuffer(numTasks);
    gl.glGenQueries(numTasks, ids);
    return BufferUtils.getIntArray(ids);
}
 
Example 16
Source File: CursorLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void addFrame(byte[] imgData, int rate, int jiffy, int width, int height, int numSeq) throws IOException {
            BufferedImage bi[] = parseICOImage(imgData);
            int hotspotx = 0;
            int hotspoty = 0;
            int type = imgData[2] | imgData[3];
            if (type == 2) {
                // CUR type, hotspot might be stored.
                hotspotx = imgData[10] | imgData[11];
                hotspoty = imgData[12] | imgData[13];
            } else if (type == 1) {
                // ICO type, hotspot not stored. Put at 0, height - 1
                // because it's flipped.
                hotspotx = 0;
                hotspoty = height - 1;
            }
//            System.out.println("Image type = " + (type == 1 ? "CUR" : "ICO"));
            if (rate == 0) {
                rate = jiffy;
            }
            CursorLoader.CursorImageData cid = new CursorLoader.CursorImageData(bi, rate, hotspotx, hotspoty, type);
            if (width == 0) {
                this.width = cid.width;
            } else {
                this.width = width;
            }
            if (height == 0) {
                this.height = cid.height;
            } else {
                this.height = height;
            }
            if (data == null) {
                if (numSeq > numImages) {
                    data = BufferUtils.createIntBuffer(this.width * this.height * numSeq);
                } else {
                    data = BufferUtils.createIntBuffer(this.width * this.height * numImages);
                }
                data.put(cid.data);
            } else {
                data.put(cid.data);
            }
            if (imgDelay == null && (numImages > 1 || numSeq > 1)) {
                if (numSeq > numImages) {
                    imgDelay = BufferUtils.createIntBuffer(numSeq);
                } else {
                    imgDelay = BufferUtils.createIntBuffer(numImages);
                }
                imgDelay.put(cid.imgDelay);
            } else if (imgDelay != null) {
                imgDelay.put(cid.imgDelay);
            }
            xHotSpot = cid.xHotSpot;
            yHotSpot = cid.yHotSpot;
            cid = null;
        }
 
Example 17
Source File: IndexBuffer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Creates an index buffer that can contain the given amount of vertices. 
 * <br/>
 * Returns either {@link IndexByteBuffer}, {@link IndexShortBuffer} or 
 * {@link IndexIntBuffer}
 * 
 * @param vertexCount The amount of vertices to contain
 * @param indexCount The amount of indices to contain
 * @return A new, apropriately sized index buffer
 */
public static IndexBuffer createIndexBuffer(int vertexCount, int indexCount){
    if (vertexCount < 128)
        return new IndexByteBuffer(BufferUtils.createByteBuffer (indexCount));
    else if (vertexCount < 65536)
        return new IndexShortBuffer(BufferUtils.createShortBuffer(indexCount));
    else
        return new IndexIntBuffer(BufferUtils.createIntBuffer(indexCount));
}
 
Example 18
Source File: IndexBuffer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * 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));
    }
}