当前位置: 首页>>代码示例>>Java>>正文


Java BufferUtils.newByteBuffer方法代码示例

本文整理汇总了Java中com.badlogic.gdx.utils.BufferUtils.newByteBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java BufferUtils.newByteBuffer方法的具体用法?Java BufferUtils.newByteBuffer怎么用?Java BufferUtils.newByteBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.badlogic.gdx.utils.BufferUtils的用法示例。


在下文中一共展示了BufferUtils.newByteBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadTexture

import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
/**
 * 
 * @param image
 * @return
 * @see http://stackoverflow.com/a/10872080
 */
private ByteBuffer loadTexture(PNGDecoder image) {
	int bytesPerComponent = chooseBitsPerComponent() / 8;
	int bytesPerPixel = chooseComponentCount() * bytesPerComponent;
	int imageBufSize = image.getWidth() * image.getHeight() * bytesPerPixel;
	ByteBuffer buffer = BufferUtils.newByteBuffer(imageBufSize);
	Format format = pngDecodingFormatFromComponentCount();
	
	try {
		image.decode(buffer, image.getWidth() * bytesPerPixel, format);
	} catch (IOException e) {
		throw new ResourceException(e);
	}
	
	buffer.flip(); // FOR THE LOVE OF GOD DO NOT FORGET THIS
	
	return buffer;
}
 
开发者ID:urstruktur,项目名称:zierfisch,代码行数:24,代码来源:TextureBuilder.java

示例2: getBuffer

import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
public ByteBuffer getBuffer () {
	if (getRows() == 0)
		// Issue #768 - CheckJNI frowns upon env->NewDirectByteBuffer with NULL buffer or capacity 0
		// "JNI WARNING: invalid values for address (0x0) or capacity (0)"
		// FreeType sets FT_Bitmap::buffer to NULL when the bitmap is empty (e.g. for ' ')
		// JNICheck is on by default on emulators and might have a point anyway...
		// So let's avoid this and just return a dummy non-null non-zero buffer
		return BufferUtils.newByteBuffer(1);
	int offset = getBufferAddress(address);
	int length = getBufferSize(address);
	Int8Array as = getBuffer(address, offset, length);
	ArrayBuffer aBuf = as.buffer();
	ByteBuffer buf = FreeTypeUtil.newDirectReadWriteByteBuffer(aBuf, length, offset);

	return buf;
}
 
开发者ID:intrigus,项目名称:gdx-freetype-gwt,代码行数:17,代码来源:FreeType.java

示例3: getFrameBufferPixmap

import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
public Pixmap getFrameBufferPixmap(Viewport viewport) {
    int w = viewport.getScreenWidth();
    int h = viewport.getScreenHeight();
    int x = viewport.getScreenX();
    int y = viewport.getScreenY();
    final ByteBuffer pixelBuffer = BufferUtils.newByteBuffer(w * h * 4);

    Gdx.gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, fbo.getFramebufferHandle());
    Gdx.gl.glReadPixels(x, y, w, h, GL30.GL_RGBA, GL30.GL_UNSIGNED_BYTE, pixelBuffer);
    Gdx.gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, 0);

    final int numBytes = w * h * 4;
    byte[] imgLines = new byte[numBytes];
    final int numBytesPerLine = w * 4;
    for (int i = 0; i < h; i++) {
        pixelBuffer.position((h - i - 1) * numBytesPerLine);
        pixelBuffer.get(imgLines, i * numBytesPerLine, numBytesPerLine);
    }

    Pixmap pixmap = new Pixmap(w, h, Pixmap.Format.RGBA8888);
    BufferUtils.copy(imgLines, 0, pixmap.getPixels(), imgLines.length);

    return pixmap;
}
 
开发者ID:mbrlabs,项目名称:Mundus,代码行数:25,代码来源:BasePicker.java

示例4: VertexBufferObjectSubData

import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
public VertexBufferObjectSubData(boolean paramBoolean, int paramInt, VertexAttribute[] paramArrayOfVertexAttribute)
{
  this.isStatic = paramBoolean;
  this.attributes = new VertexAttributes(paramArrayOfVertexAttribute);
  this.byteBuffer = BufferUtils.newByteBuffer(paramInt * this.attributes.vertexSize);
  this.isDirect = true;
  if (paramBoolean);
  for (int i = 35044; ; i = 35048)
  {
    this.usage = i;
    this.buffer = this.byteBuffer.asFloatBuffer();
    this.bufferHandle = createBufferObject();
    this.buffer.flip();
    this.byteBuffer.flip();
    return;
  }
}
 
开发者ID:isnuryusuf,项目名称:ingress-indonesia-dev,代码行数:18,代码来源:VertexBufferObjectSubData.java

示例5: loadFile

import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
public boolean loadFile(final com.badlogic.gdx.files.FileHandle fileHandle) {
		final int len = (int) fileHandle.length();
		if (len <= 0)
			throw new com.badlogic.gdx.utils.GdxRuntimeException("Incorrect file specified");
		java.nio.ByteBuffer buff = BufferUtils.newByteBuffer(len);
		buff.put(fileHandle.readBytes());
		buff.position(0);
		boolean result = loadFileFromMemory(buff, len);
//		com.badlogic.gdx.utils.BufferUtils.disposeUnsafeByteBuffer(buff);
		return result;
	}
 
开发者ID:xpenatan,项目名称:gdx-bullet-gwt,代码行数:12,代码来源:btBulletWorldImporter.java

示例6: FreeTypeFontGenerator

import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
/** Creates a new generator from the given font file. Uses {@link FileHandle#length()} to determine the file size. If the file
 * length could not be determined (it was 0), an extra copy of the font bytes is performed. Throws a
 * {@link GdxRuntimeException} if loading did not succeed. */
public FreeTypeFontGenerator (FileHandle fontFile) {
	name = fontFile.pathWithoutExtension();
	int fileSize = (int)fontFile.length();

	library = FreeType.initFreeType();
	if (library == null) throw new GdxRuntimeException("Couldn't initialize FreeType");

	ByteBuffer buffer;
	InputStream input = fontFile.read();
	try {
		if (fileSize == 0) {
			// Copy to a byte[] to get the file size, then copy to the buffer.
			byte[] data = StreamUtils.copyStreamToByteArray(input, fileSize > 0 ? (int)(fileSize * 1.5f) : 1024 * 16);
			buffer = BufferUtils.newByteBuffer(data.length);
			BufferUtils.copy(data, 0, buffer, data.length);
		} else {
			// Trust the specified file size.
			buffer = BufferUtils.newByteBuffer(fileSize);
			StreamUtils.copyStream(input, buffer);
		}
	} catch (IOException ex) {
		throw new GdxRuntimeException(ex);
	} finally {
		StreamUtils.closeQuietly(input);
	}

	face = library.newMemoryFace(buffer, 0);
	if (face == null) throw new GdxRuntimeException("Couldn't create face for font: " + fontFile);

	if (checkForBitmapFont()) return;
	setPixelSizes(0, 15);
}
 
开发者ID:intrigus,项目名称:gdx-freetype-gwt,代码行数:36,代码来源:FreeTypeFontGenerator.java

示例7: VertexBufferObjectSubData

import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
/** Constructs a new interleaved VertexBufferObject.
 * 
 * @param isStatic whether the vertex data is static.
 * @param numVertices the maximum number of vertices
 * @param attributes the {@link VertexAttribute}s. */
public VertexBufferObjectSubData (boolean isStatic, int numVertices, VertexAttribute... attributes) {
	this.isStatic = isStatic;
	this.attributes = new VertexAttributes(attributes);
	byteBuffer = BufferUtils.newByteBuffer(this.attributes.vertexSize * numVertices);
	isDirect = true;

	usage = isStatic ? GL20.GL_STATIC_DRAW : GL20.GL_DYNAMIC_DRAW;
	buffer = byteBuffer.asFloatBuffer();
	bufferHandle = createBufferObject();
	buffer.flip();
	byteBuffer.flip();
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:18,代码来源:VertexBufferObjectSubData.java

示例8: IndexBufferObjectSubData

import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
/** Creates a new IndexBufferObject.
 * 
 * @param isStatic whether the index buffer is static
 * @param maxIndices the maximum number of indices this buffer can hold */
public IndexBufferObjectSubData (boolean isStatic, int maxIndices) {
	byteBuffer = BufferUtils.newByteBuffer(maxIndices * 2);
	isDirect = true;

	usage = isStatic ? GL20.GL_STATIC_DRAW : GL20.GL_DYNAMIC_DRAW;
	buffer = byteBuffer.asShortBuffer();
	buffer.flip();
	byteBuffer.flip();
	bufferHandle = createBufferObject();
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:15,代码来源:IndexBufferObjectSubData.java

示例9: getBuffer

import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
public ByteBuffer getBuffer() {
	if (getRows() == 0)
		// Issue #768 - CheckJNI frowns upon env->NewDirectByteBuffer with NULL buffer or capacity 0
		//                  "JNI WARNING: invalid values for address (0x0) or capacity (0)"
		//              FreeType sets FT_Bitmap::buffer to NULL when the bitmap is empty (e.g. for ' ')
		//              JNICheck is on by default on emulators and might have a point anyway...
		//              So let's avoid this and just return a dummy non-null non-zero buffer
		return BufferUtils.newByteBuffer(1);
	return getBuffer(address);
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:11,代码来源:FreeType.java

示例10: benchByte

import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
private void benchByte () {
	ByteBuffer bb = BufferUtils.newByteBuffer(1024 * 1024);
	byte[] bytes = new byte[1024 * 1024];
	int len = bytes.length;
	final int NUM_MB = 5;

	// relative put
	long start = TimeUtils.nanoTime();
	for (int j = 0; j < NUM_MB; j++) {
		bb.clear();
		for (int i = 0; i < len; i++)
			bb.put(bytes[i]);
	}
	Gdx.app.log("BufferUtilsTest", "ByteBuffer relative put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);

	// absolute put
	start = TimeUtils.nanoTime();
	for (int j = 0; j < NUM_MB; j++) {
		bb.clear();
		for (int i = 0; i < len; i++)
			bb.put(i, bytes[i]);
	}
	Gdx.app.log("BufferUtilsTest", "ByteBuffer absolute put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);

	// bulk put
	start = TimeUtils.nanoTime();
	for (int j = 0; j < NUM_MB; j++) {
		bb.clear();
		bb.put(bytes);
	}
	Gdx.app.log("BufferUtilsTest", "ByteBuffer bulk put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);

	// JNI put
	start = TimeUtils.nanoTime();
	for (int j = 0; j < NUM_MB; j++) {
		bb.clear();
		BufferUtils.copy(bytes, 0, bb, len);
	}
	Gdx.app.log("BufferUtilsTest", "ByteBuffer native bulk put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:41,代码来源:BufferUtilsTest.java

示例11: getPixelBuffer

import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
private static ByteBuffer getPixelBuffer(int capacity) {
	ByteBuffer pixels = pixelBuffers[indexPixelBuffer];
	if (pixels == null || pixels.capacity() != capacity) {
		pixels = BufferUtils.newByteBuffer(capacity);
		pixelBuffers[indexPixelBuffer] = pixels;
	}
	indexPixelBuffer++;
	if (indexPixelBuffer >= pixelBuffers.length) {
		indexPixelBuffer = 0;
	}
	return pixels;
}
 
开发者ID:0x0ade,项目名称:shadow-engine,代码行数:13,代码来源:ScreenshotUtil.java

示例12: ensureBufferCapacity

import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
private void ensureBufferCapacity(int paramInt)
{
  if ((this.buffer == null) || (this.buffer.capacity() != paramInt))
  {
    this.buffer = BufferUtils.newByteBuffer(paramInt);
    this.floatBuffer = this.buffer.asFloatBuffer();
    this.intBuffer = this.buffer.asIntBuffer();
  }
}
 
开发者ID:isnuryusuf,项目名称:ingress-indonesia-dev,代码行数:10,代码来源:ShaderProgram.java

示例13: IndexBufferObjectSubData

import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
public IndexBufferObjectSubData(int paramInt)
{
  this.byteBuffer = BufferUtils.newByteBuffer(paramInt * 2);
  this.isDirect = true;
  this.usage = 35044;
  this.buffer = this.byteBuffer.asShortBuffer();
  this.buffer.flip();
  this.byteBuffer.flip();
  this.bufferHandle = createBufferObject();
}
 
开发者ID:isnuryusuf,项目名称:ingress-indonesia-dev,代码行数:11,代码来源:IndexBufferObjectSubData.java

示例14: PipelineState

import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
protected PipelineState () {
	byteBuffer = BufferUtils.newByteBuffer(32);
}
 
开发者ID:Osaris31,项目名称:exterminate,代码行数:4,代码来源:PipelineState.java

示例15: PipelineState

import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
protected PipelineState() {
   byteBuffer = BufferUtils.newByteBuffer(32);
}
 
开发者ID:bitbrain,项目名称:braingdx,代码行数:4,代码来源:PipelineState.java


注:本文中的com.badlogic.gdx.utils.BufferUtils.newByteBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。