本文整理汇总了Java中java.nio.ShortBuffer.position方法的典型用法代码示例。如果您正苦于以下问题:Java ShortBuffer.position方法的具体用法?Java ShortBuffer.position怎么用?Java ShortBuffer.position使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.ShortBuffer
的用法示例。
在下文中一共展示了ShortBuffer.position方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: IndexBuffer
import java.nio.ShortBuffer; //导入方法依赖的package包/类
public IndexBuffer(short[] vertexData) {
final int buffers[] = new int[1];
glGenBuffers(buffers.length, buffers, 0);
if (buffers[0] == 0) {
throw new RuntimeException("Could not create a new buffer");
}
bufferId = buffers[0];
//bind to the buffer
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[0]);
//transfer data to native memory
ShortBuffer vertexArray = ByteBuffer.allocateDirect(vertexData.length * BYTE_PER_SHORT)
.order(ByteOrder.nativeOrder())
.asShortBuffer()
.put(vertexData);
vertexArray.position(0);
//transfer data from native memory to the GPU buffer
glBufferData(GL_ELEMENT_ARRAY_BUFFER, vertexArray.capacity() * BYTE_PER_SHORT, vertexArray, GL_STATIC_DRAW);
//Unbind from the buffer when we're done with it
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
示例2: ensureLargeEnough
import java.nio.ShortBuffer; //导入方法依赖的package包/类
public static ShortBuffer ensureLargeEnough(ShortBuffer buffer, int required) {
if (buffer != null) {
buffer.limit(buffer.capacity());
}
if (buffer == null || (buffer.remaining() < required)) {
int position = (buffer != null ? buffer.position() : 0);
ShortBuffer newVerts = createShortBuffer(position + required);
if (buffer != null) {
buffer.flip();
newVerts.put(buffer);
newVerts.position(position);
}
buffer = newVerts;
}
return buffer;
}
示例3: setData
import java.nio.ShortBuffer; //导入方法依赖的package包/类
public void setData(short[] in) {
validate();
ShortBuffer buffer = ShortBuffer.wrap(in);
buffer.position(in.length - 1);
buffer.flip();
oal.alBufferData(id[0], OalConvert.getFormat(stereo, sixteenBit), buffer, in.length * 2 - 4, frequency);
}
示例4: createShortBuffer
import java.nio.ShortBuffer; //导入方法依赖的package包/类
public static ShortBuffer createShortBuffer(short[] coords) {
ByteBuffer bb = ByteBuffer.allocateDirect(coords.length * SIZEOF_SHORT);
bb.order(ByteOrder.nativeOrder());
ShortBuffer ib = bb.asShortBuffer();
ib.put(coords);
ib.position(0);
return ib;
}
示例5: createIbo
import java.nio.ShortBuffer; //导入方法依赖的package包/类
public static int createIbo(ShortBuffer data) {
int[] ibos = new int[1];
data.position(0);
GLES20.glGenBuffers(1, ibos, 0);
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, ibos[0]);
GLES20.glBufferData(GLES20.GL_ELEMENT_ARRAY_BUFFER, data.capacity() * MyGLUtils.SHORT_SIZE,
data, GLES20.GL_STATIC_DRAW);
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
return ibos[0];
}
示例6: getShortBuffer
import java.nio.ShortBuffer; //导入方法依赖的package包/类
public static ShortBuffer getShortBuffer(final short[] array, int offset){
ShortBuffer bb=ByteBuffer.allocateDirect(
array.length * SHORT_SIZE_BYTES)
.order(ByteOrder.nativeOrder())
.asShortBuffer()
.put(array);
bb.position(offset);
return bb;
}
示例7: initAllNames
import java.nio.ShortBuffer; //导入方法依赖的package包/类
protected void initAllNames(int requestedID, HashSet names) {
byte[] name = new byte[256];
ByteBuffer buffer = getTableBuffer(nameTag);
if (buffer != null) {
ShortBuffer sbuffer = buffer.asShortBuffer();
sbuffer.get(); // format - not needed.
short numRecords = sbuffer.get();
/* The name table uses unsigned shorts. Many of these
* are known small values that fit in a short.
* The values that are sizes or offsets into the table could be
* greater than 32767, so read and store those as ints
*/
int stringPtr = ((int) sbuffer.get()) & 0xffff;
for (int i=0; i<numRecords; i++) {
short platformID = sbuffer.get();
if (platformID != MS_PLATFORM_ID) {
sbuffer.position(sbuffer.position()+5);
continue; // skip over this record.
}
short encodingID = sbuffer.get();
short langID = sbuffer.get();
short nameID = sbuffer.get();
int nameLen = ((int) sbuffer.get()) & 0xffff;
int namePtr = (((int) sbuffer.get()) & 0xffff) + stringPtr;
if (nameID == requestedID) {
buffer.position(namePtr);
buffer.get(name, 0, nameLen);
names.add(makeString(name, nameLen, encodingID));
}
}
}
}
示例8: ShortBufferUtil
import java.nio.ShortBuffer; //导入方法依赖的package包/类
private ShortBuffer ShortBufferUtil(short[] arr) {
ByteBuffer dlb = ByteBuffer.allocateDirect(arr.length * 2);
dlb.order(ByteOrder.nativeOrder());
ShortBuffer buffer = dlb.asShortBuffer();
buffer.put(arr);
buffer.position(0);
return buffer;
}
示例9: initAllNames
import java.nio.ShortBuffer; //导入方法依赖的package包/类
protected void initAllNames(int requestedID, HashSet<String> names) {
byte[] name = new byte[256];
ByteBuffer buffer = getTableBuffer(nameTag);
if (buffer != null) {
ShortBuffer sbuffer = buffer.asShortBuffer();
sbuffer.get(); // format - not needed.
short numRecords = sbuffer.get();
/* The name table uses unsigned shorts. Many of these
* are known small values that fit in a short.
* The values that are sizes or offsets into the table could be
* greater than 32767, so read and store those as ints
*/
int stringPtr = ((int) sbuffer.get()) & 0xffff;
for (int i=0; i<numRecords; i++) {
short platformID = sbuffer.get();
if (platformID != MS_PLATFORM_ID) {
sbuffer.position(sbuffer.position()+5);
continue; // skip over this record.
}
short encodingID = sbuffer.get();
short langID = sbuffer.get();
short nameID = sbuffer.get();
int nameLen = ((int) sbuffer.get()) & 0xffff;
int namePtr = (((int) sbuffer.get()) & 0xffff) + stringPtr;
if (nameID == requestedID) {
buffer.position(namePtr);
buffer.get(name, 0, nameLen);
names.add(makeString(name, nameLen, platformID, encodingID));
}
}
}
}
示例10: getIndices
import java.nio.ShortBuffer; //导入方法依赖的package包/类
public static ShortBuffer getIndices( int size ) {
ShortBuffer indices = cache.get(size);
if (indices == null) {
// TODO: Optimize it!
indices = ByteBuffer.
allocateDirect( size * SIZE * Short.SIZE / 8 ).
order( ByteOrder.nativeOrder() ).
asShortBuffer();
short[] values = new short[size * 6];
int pos = 0;
int limit = size * 4;
for (int ofs=0; ofs < limit; ofs += 4) {
values[pos++] = (short)(ofs + 0);
values[pos++] = (short)(ofs + 1);
values[pos++] = (short)(ofs + 2);
values[pos++] = (short)(ofs + 0);
values[pos++] = (short)(ofs + 2);
values[pos++] = (short)(ofs + 3);
}
indices.put( values );
indices.position( 0 );
cache.put(size, indices);
}
return indices;
}
示例11: lookupName
import java.nio.ShortBuffer; //导入方法依赖的package包/类
protected String lookupName(short findLocaleID, int findNameID) {
String foundName = null;
byte[] name = new byte[1024];
ByteBuffer buffer = getTableBuffer(nameTag);
if (buffer != null) {
ShortBuffer sbuffer = buffer.asShortBuffer();
sbuffer.get(); // format - not needed.
short numRecords = sbuffer.get();
/* The name table uses unsigned shorts. Many of these
* are known small values that fit in a short.
* The values that are sizes or offsets into the table could be
* greater than 32767, so read and store those as ints
*/
int stringPtr = ((int) sbuffer.get()) & 0xffff;
for (int i=0; i<numRecords; i++) {
short platformID = sbuffer.get();
if (platformID != MS_PLATFORM_ID) {
sbuffer.position(sbuffer.position()+5);
continue; // skip over this record.
}
short encodingID = sbuffer.get();
short langID = sbuffer.get();
short nameID = sbuffer.get();
int nameLen = ((int) sbuffer.get()) & 0xffff;
int namePtr = (((int) sbuffer.get()) & 0xffff) + stringPtr;
if (nameID == findNameID &&
((foundName == null && langID == ENGLISH_LOCALE_ID)
|| langID == findLocaleID)) {
buffer.position(namePtr);
buffer.get(name, 0, nameLen);
foundName = makeString(name, nameLen, encodingID);
if (langID == findLocaleID) {
return foundName;
}
}
}
}
return foundName;
}
示例12: lookupName
import java.nio.ShortBuffer; //导入方法依赖的package包/类
protected String lookupName(short findLocaleID, int findNameID) {
String foundName = null;
byte[] name = new byte[1024];
ByteBuffer buffer = getTableBuffer(nameTag);
if (buffer != null) {
ShortBuffer sbuffer = buffer.asShortBuffer();
sbuffer.get(); // format - not needed.
short numRecords = sbuffer.get();
/* The name table uses unsigned shorts. Many of these
* are known small values that fit in a short.
* The values that are sizes or offsets into the table could be
* greater than 32767, so read and store those as ints
*/
int stringPtr = ((int) sbuffer.get()) & 0xffff;
for (int i=0; i<numRecords; i++) {
short platformID = sbuffer.get();
if (platformID != MS_PLATFORM_ID) {
sbuffer.position(sbuffer.position()+5);
continue; // skip over this record.
}
short encodingID = sbuffer.get();
short langID = sbuffer.get();
short nameID = sbuffer.get();
int nameLen = ((int) sbuffer.get()) & 0xffff;
int namePtr = (((int) sbuffer.get()) & 0xffff) + stringPtr;
if (nameID == findNameID &&
((foundName == null && langID == ENGLISH_LOCALE_ID)
|| langID == findLocaleID)) {
buffer.position(namePtr);
buffer.get(name, 0, nameLen);
foundName = makeString(name, nameLen, platformID, encodingID);
if (langID == findLocaleID) {
return foundName;
}
}
}
}
return foundName;
}