• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2009-2010 jMonkeyEngine
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  *   notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  *   notice, this list of conditions and the following disclaimer in the
14  *   documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17  *   may be used to endorse or promote products derived from this software
18  *   without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 package com.jme3.scene.mesh;
34 
35 import com.jme3.util.BufferUtils;
36 import java.nio.Buffer;
37 
38 /**
39  * <code>IndexBuffer</code> is an abstraction for integer index buffers,
40  * it is used to retrieve indices without knowing in which format they
41  * are stored (ushort or uint).
42  *
43  * @author lex
44  */
45 public abstract class IndexBuffer {
46 
47     /**
48      * Creates an index buffer that can contain the given amount
49      * of vertices.
50      * Returns {@link IndexShortBuffer}
51      *
52      * @param vertexCount The amount of vertices to contain
53      * @param indexCount The amount of indices
54      * to contain.
55      * @return A new index buffer
56      */
createIndexBuffer(int vertexCount, int indexCount)57     public static IndexBuffer createIndexBuffer(int vertexCount, int indexCount){
58         if (vertexCount > 65535){
59             return new IndexIntBuffer(BufferUtils.createIntBuffer(indexCount));
60         }else{
61             return new IndexShortBuffer(BufferUtils.createShortBuffer(indexCount));
62         }
63     }
64 
65     /**
66      * Returns the vertex index for the given index in the index buffer.
67      *
68      * @param i The index inside the index buffer
69      * @return
70      */
get(int i)71     public abstract int get(int i);
72 
73     /**
74      * Puts the vertex index at the index buffer's index.
75      * Implementations may throw an {@link UnsupportedOperationException}
76      * if modifying the IndexBuffer is not supported (e.g. virtual index
77      * buffers).
78      */
put(int i, int value)79     public abstract void put(int i, int value);
80 
81     /**
82      * Returns the size of the index buffer.
83      *
84      * @return the size of the index buffer.
85      */
size()86     public abstract int size();
87 
88     /**
89      * Returns the underlying data-type specific {@link Buffer}.
90      * Implementations may return null if there's no underlying
91      * buffer.
92      *
93      * @return the underlying {@link Buffer}.
94      */
getBuffer()95     public abstract Buffer getBuffer();
96 }
97