當前位置: 首頁>>代碼示例>>Java>>正文


Java ByteBuffer.asFloatBuffer方法代碼示例

本文整理匯總了Java中java.nio.ByteBuffer.asFloatBuffer方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteBuffer.asFloatBuffer方法的具體用法?Java ByteBuffer.asFloatBuffer怎麽用?Java ByteBuffer.asFloatBuffer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.nio.ByteBuffer的用法示例。


在下文中一共展示了ByteBuffer.asFloatBuffer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setTextureBuffer

import java.nio.ByteBuffer; //導入方法依賴的package包/類
private void setTextureBuffer()
{

    // Set the texture buffer
    float[] uvs = new float[] {
            0.0f, 0.0f,
            0.0f, 1.0f,
            1.0f, 1.0f,
            1.0f, 0.0f
    };

    // The texture buffer
    ByteBuffer bb = ByteBuffer.allocateDirect(uvs.length * 4);
    bb.order(ByteOrder.nativeOrder());
    mTextureBuffer = bb.asFloatBuffer();
    mTextureBuffer.put(uvs);
    mTextureBuffer.position(0);
}
 
開發者ID:kaidenho,項目名稱:spellcaster,代碼行數:19,代碼來源:RenderObject.java

示例2: Square

import java.nio.ByteBuffer; //導入方法依賴的package包/類
/**
 * Sets up the drawing object data for use in an OpenGL ES context.
 */
public Square() {
    // initialize vertex byte buffer for shape coordinates
    ByteBuffer bb = ByteBuffer.allocateDirect(
    // (# of coordinate values * 4 bytes per float)
            squareCoords.length * 4);
    bb.order(ByteOrder.nativeOrder());
    vertexBuffer = bb.asFloatBuffer();
    vertexBuffer.put(squareCoords);
    vertexBuffer.position(0);

    // initialize byte buffer for the draw list
    ByteBuffer dlb = ByteBuffer.allocateDirect(
            // (# of coordinate values * 2 bytes per short)
            drawOrder.length * 2);
    dlb.order(ByteOrder.nativeOrder());
    drawListBuffer = dlb.asShortBuffer();
    drawListBuffer.put(drawOrder);
    drawListBuffer.position(0);
}
 
開發者ID:sdrausty,項目名稱:buildAPKsSamples,代碼行數:23,代碼來源:Square.java

示例3: Texture

import java.nio.ByteBuffer; //導入方法依賴的package包/類
public Texture(Context mContext) {
    this.mContext = mContext;
    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(texture.length * 4);
    byteBuffer.order(ByteOrder.nativeOrder());
    mTextureBuffer = byteBuffer.asFloatBuffer();
    mTextureBuffer.put(texture);
    mTextureBuffer.position(0);

    ByteBuffer vByteBuffer = ByteBuffer.allocateDirect(coordinates.length * 4);
    vByteBuffer.order(ByteOrder.nativeOrder());
    mVertexBuffer = vByteBuffer.asFloatBuffer();
    mVertexBuffer.put(coordinates);
    mVertexBuffer.position(0);

    ByteBuffer iByteBuffer = ByteBuffer.allocateDirect(indices.length * 2);
    iByteBuffer.order(ByteOrder.nativeOrder());
    mIndexBuffer = iByteBuffer.asShortBuffer();
    mIndexBuffer.put(indices);
    mIndexBuffer.position(0);
}
 
開發者ID:zhuangzaiku,項目名稱:AndroidCollection,代碼行數:21,代碼來源:Texture.java

示例4: Square

import java.nio.ByteBuffer; //導入方法依賴的package包/類
public Square() {
    // initialize vertex byte buffer for shape coordinates
    ByteBuffer bb = ByteBuffer.allocateDirect(
            // (# of coordinate values * 4 bytes per float)
            squareCoords.length * 4);
    bb.order(ByteOrder.nativeOrder());
    vertexBuffer = bb.asFloatBuffer();
    vertexBuffer.put(squareCoords);
    vertexBuffer.position(0);

    // initialize byte buffer for the draw list
    ByteBuffer dlb = ByteBuffer.allocateDirect(
            // (# of coordinate values * 2 bytes per short)
            drawOrder.length * 2);
    dlb.order(ByteOrder.nativeOrder());
    drawListBuffer = dlb.asShortBuffer();
    drawListBuffer.put(drawOrder);
    drawListBuffer.position(0);
}
 
開發者ID:FreeSunny,項目名稱:Amazing,代碼行數:20,代碼來源:Square.java

示例5: Square

import java.nio.ByteBuffer; //導入方法依賴的package包/類
public Square() {
    ByteBuffer vByteBuffer = ByteBuffer.allocateDirect(vertices.length * 4);
    vByteBuffer.order(ByteOrder.nativeOrder());
    mVertexBuffer = vByteBuffer.asFloatBuffer();
    mVertexBuffer.put(vertices);
    mVertexBuffer.position(0);

    ByteBuffer iByteBuffer = ByteBuffer.allocateDirect(indices.length * 2);
    iByteBuffer.order(ByteOrder.nativeOrder());
    mIndexBuffer = iByteBuffer.asShortBuffer();
    mIndexBuffer.put(indices);
    mIndexBuffer.position(0);

    ByteBuffer cByteBuffer = ByteBuffer.allocateDirect(colors.length * 4);
    cByteBuffer.order(ByteOrder.nativeOrder());
    mColorBuffer = cByteBuffer.asFloatBuffer();
    mColorBuffer.put(colors);
    mColorBuffer.position(0);
}
 
開發者ID:zhuangzaiku,項目名稱:AndroidCollection,代碼行數:20,代碼來源:Square.java

示例6: setColors

import java.nio.ByteBuffer; //導入方法依賴的package包/類
private void setColors(int[] faceColors) {
    colors = new float[options * 4 * faceColors.length];
    int wOffset = 0;
    for (int faceColor : faceColors) {
        float[] color = hexToRGBA(faceColor);
        for(int j = 0; j < 4; j++) {
            colors[wOffset++] = color[0];
            colors[wOffset++] = color[1];
            colors[wOffset++] = color[2];
            colors[wOffset++] = color[3];
        }
    }
    ByteBuffer cbb = ByteBuffer.allocateDirect(colors.length * (Float.SIZE / 8));
    cbb.order(ByteOrder.nativeOrder());

    colorBuffer = cbb.asFloatBuffer();
    colorBuffer.put(colors);
    colorBuffer.position(0);
}
 
開發者ID:PacktPublishing,項目名稱:Building-Android-UIs-with-Custom-Views,代碼行數:20,代碼來源:GLDrawer.java

示例7: Cube

import java.nio.ByteBuffer; //導入方法依賴的package包/類
public Cube(float width, float height, float depth) {
    ByteBuffer vByteBuffer = ByteBuffer.allocateDirect(vertices.length * 4);
    vByteBuffer.order(ByteOrder.nativeOrder());
    mVertexBuffer = vByteBuffer.asFloatBuffer();
    mVertexBuffer.put(vertices);
    mVertexBuffer.position(0);

    ByteBuffer iByteBuffer = ByteBuffer.allocateDirect(indices.length * 2);
    iByteBuffer.order(ByteOrder.nativeOrder());
    mIndexBuffer = iByteBuffer.asShortBuffer();
    mIndexBuffer.put(indices);
    mIndexBuffer.position(0);

    ByteBuffer cByteBuffer = ByteBuffer.allocateDirect(colors.length * 4);
    cByteBuffer.order(ByteOrder.nativeOrder());
    mColorBuffer = cByteBuffer.asFloatBuffer();
    mColorBuffer.put(colors);
    mColorBuffer.position(0);
    this.width = width / 2;
    this.height = height / 2;
    this.depth = depth / 2;
}
 
開發者ID:zhuangzaiku,項目名稱:AndroidCollection,代碼行數:23,代碼來源:Cube.java

示例8: testUseFloatBufferViewOfByteBufferWithWrongByteOrder

import java.nio.ByteBuffer; //導入方法依賴的package包/類
@Test
public void testUseFloatBufferViewOfByteBufferWithWrongByteOrder() {
    window = glfwCreateWindow(800, 600, "", 0L, 0L);
    glfwMakeContextCurrent(window);
    createCapabilities();
    ByteBuffer bb = ByteBuffer.allocateDirect(16 * 4);
    bb.putFloat(0, 1.0f);
    FloatBuffer fb = bb.asFloatBuffer();
    assertThrows(IllegalArgumentException.class, () -> glLoadMatrixf(fb), "buffer contains values written using non-native endianness.");
}
 
開發者ID:LWJGLX,項目名稱:debug,代碼行數:11,代碼來源:DebugIT.java

示例9: makeFloatBuffer

import java.nio.ByteBuffer; //導入方法依賴的package包/類
static FloatBuffer makeFloatBuffer(int size) {
    ByteBuffer vbb = ByteBuffer.allocateDirect(size * 4);
    vbb.order(ByteOrder.nativeOrder());
    FloatBuffer texBuffer = vbb.asFloatBuffer();
    texBuffer.position(0);
    return texBuffer;
}
 
開發者ID:StringMon,項目名稱:homescreenarcade,代碼行數:8,代碼來源:GLVertexList.java

示例10: Triangle

import java.nio.ByteBuffer; //導入方法依賴的package包/類
/**
 * Sets up the drawing object data for use in an OpenGL ES context.
 */
public Triangle() {
    // initialize vertex byte buffer for shape coordinates
    ByteBuffer bb = ByteBuffer.allocateDirect(
            // (number of coordinate values * 4 bytes per float)
            triangleCoords.length * 4);
    // use the device hardware's native byte order
    bb.order(ByteOrder.nativeOrder());

    // create a floating point buffer from the ByteBuffer
    vertexBuffer = bb.asFloatBuffer();
    // add the coordinates to the FloatBuffer
    vertexBuffer.put(triangleCoords);
    // set the buffer to read the first coordinate
    vertexBuffer.position(0);

    // prepare shaders and OpenGL program
    int vertexShader = MyGLRenderer.loadShader(
            GLES20.GL_VERTEX_SHADER, vertexShaderCode);
    int fragmentShader = MyGLRenderer.loadShader(
            GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);

    mProgram = GLES20.glCreateProgram();             // create empty OpenGL Program
    GLES20.glAttachShader(mProgram, vertexShader);   // add the vertex shader to program
    GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment shader to program
    GLES20.glLinkProgram(mProgram);                  // create OpenGL program executables

}
 
開發者ID:biezhihua,項目名稱:Android_OpenGL_Demo,代碼行數:31,代碼來源:Triangle.java

示例11: snapshotToBuffer

import java.nio.ByteBuffer; //導入方法依賴的package包/類
/**
 * Convert the timeseries snapshot into a run of (x, y, z) bytes.
 */
private FloatBuffer snapshotToBuffer(TimeSeriesSnapshot snapshot) {
  float[] asFloats = snapshotToFloat(snapshot);

  // Create buffer to store result.
  ByteBuffer bb = ByteBuffer.allocateDirect(snapshot.length * VERTEX_STRIDE);
  bb.order(ByteOrder.nativeOrder());

  // Write to buffer usign floats:
  FloatBuffer vertexBuffer = bb.asFloatBuffer();
  vertexBuffer.put(asFloats);
  vertexBuffer.position(0);
  return vertexBuffer;
}
 
開發者ID:padster,項目名稱:Muse-EEG-Toolkit,代碼行數:17,代碼來源:GraphGLLine.java

示例12: Init

import java.nio.ByteBuffer; //導入方法依賴的package包/類
private void Init( float w, float h, float x, float y, float z ) {

		mWidth = w;
		mHeight = h;

		ByteBuffer vbb = ByteBuffer.allocateDirect(VERTS * 3 * 4);
		vbb.order(ByteOrder.nativeOrder());
		mFVertexBuffer = vbb.asFloatBuffer();

		ByteBuffer tbb = ByteBuffer.allocateDirect(VERTS * 2 * 4);
		tbb.order(ByteOrder.nativeOrder());
		mTexBuffer = tbb.asFloatBuffer();

		ByteBuffer ibb = ByteBuffer.allocateDirect(VERTS * 2);
		ibb.order(ByteOrder.nativeOrder());
		mIndexBuffer = ibb.asShortBuffer();

		int n = 0;
		for (int i=0; i<VERTS; i++) {
			mFVertexBuffer.put( COORDS[n++]*mWidth  + x);
			mFVertexBuffer.put( COORDS[n++]*mHeight + y);
			mFVertexBuffer.put( COORDS[n++]         + z);
		}

		for (int i = 0; i < 2*VERTS; i++) {
			mTexBuffer.put(TEX_COORDS[i]);	//TODO ???
		}

		for(int i = 0; i < VERTS; i++) {
			mIndexBuffer.put((short) i);
		}

		mFVertexBuffer.position(0);
		mTexBuffer.position(0);
		mIndexBuffer.position(0);
	}
 
開發者ID:archos-sa,項目名稱:aos-MediaLib,代碼行數:37,代碼來源:Icon.java

示例13: TextureRenderer

import java.nio.ByteBuffer; //導入方法依賴的package包/類
public TextureRenderer(boolean isOesTexture) {
    mOesTexture = isOesTexture;

    ByteBuffer bb = ByteBuffer.allocateDirect(squareVertices.length * 4);
    bb.order(ByteOrder.nativeOrder());
    vertexBuffer = bb.asFloatBuffer();
    vertexBuffer.put(squareVertices);
    vertexBuffer.position(0);

    ByteBuffer dlb = ByteBuffer.allocateDirect(drawOrder.length * 2);
    dlb.order(ByteOrder.nativeOrder());
    drawListBuffer = dlb.asShortBuffer();
    drawListBuffer.put(drawOrder);
    drawListBuffer.position(0);

    ByteBuffer bb2 = ByteBuffer.allocateDirect(textureVertices.length * 4);
    bb2.order(ByteOrder.nativeOrder());
    textureVerticesBuffer = bb2.asFloatBuffer();
    textureVerticesBuffer.put(textureVertices);
    textureVerticesBuffer.position(0);

    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, mVertexShader);
    int fragmentShader;
    if (mOesTexture) {
        fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, mFragmentShaderOes);
    } else {
        fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, mFragmentShaderRgba);
    }

    mProgram = GLES20.glCreateProgram();             // create empty OpenGL ES Program
    GLES20.glAttachShader(mProgram, vertexShader);   // add the vertex shader to program
    GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment shader to program
    GLES20.glLinkProgram(mProgram);

    muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
    muSTMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uSTMatrix");

    Matrix.setIdentityM(mMVPMatrix, 0);
    Matrix.setIdentityM(mSTMatrix, 0);
}
 
開發者ID:AgoraIO,項目名稱:Agora-Video-Source-Android,代碼行數:41,代碼來源:TextureRenderer.java

示例14: update

import java.nio.ByteBuffer; //導入方法依賴的package包/類
/**
 * Update wave position.
 *
 * @param dAngle delta angle
 */
public void update(float dAngle) {
  if (vertexBuffer == null) {
    ByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect(vertices.length * SIZE_OF_FLOAT);
    vertexByteBuffer.order(ByteOrder.nativeOrder());
    vertexBuffer = vertexByteBuffer.asFloatBuffer();
    vertexBuffer.put(vertices);
    vertexBuffer.position(0);
  }
  float angle = currentAngle;
  angle += dAngle;
  currentAngle = angle;
  if (coefficient == 0 && latestCoefficient > 0) {
    coefficient = Utils.smooth(0, latestCoefficient, SMOOTH_A);
  }

  float val = (float) Math.sin(angle) * coefficient;
  if (prevVal > 0 && val <= 0 || prevVal < 0 && val >= 0) {
    coefficient = Utils.smooth(coefficient, latestCoefficient, SMOOTH_A);
    waveX = random.nextFloat() * 0.3f * (random.nextBoolean() ? 1 : -1);
  }
  prevVal = val;
  int i = 0;
  double step = 1.0 / POINTS_PER_WAVE;
  float posX = Utils.normalizeGl(waveX, fromX, toX);
  float posY = Utils.normalizeGl(val, fromY, toY);
  for (float time = 0; time < 1 - step / 2; time += step) {
    vertices[COORDS_PER_VERTEX * i + 1 + SKIP] = angle;
    vertexBuffer.put(COORDS_PER_VERTEX * i + SKIP,
        Utils.quad(time, vertices[6], posX, vertices[vertices.length - 6]));
    vertexBuffer.put(COORDS_PER_VERTEX * i + 1 + SKIP,
        Utils.quad(time, vertices[7], posY, vertices[vertices.length - 5]));
    i++;
  }
}
 
開發者ID:Arjun-sna,項目名稱:Android-AudioRecorder-App,代碼行數:40,代碼來源:GLWave.java

示例15: Init

import java.nio.ByteBuffer; //導入方法依賴的package包/類
private void Init( float w, float h, float x, float y, float z ) {

		mWidth = w;
		mHeight = h;

		ByteBuffer vbb = ByteBuffer.allocateDirect(VERTS * 3 * 4);
		vbb.order(ByteOrder.nativeOrder());
		mFVertexBuffer = vbb.asFloatBuffer();

		ByteBuffer ibb = ByteBuffer.allocateDirect(VERTS * 2);
		ibb.order(ByteOrder.nativeOrder());
		mIndexBuffer = ibb.asShortBuffer();

		int n = 0;
		for (int i=0; i<VERTS; i++) {
			mFVertexBuffer.put( COORDS[n++]*mWidth  + x);
			mFVertexBuffer.put( COORDS[n++]*mHeight + y);
			mFVertexBuffer.put( COORDS[n++]         + z);
		}

		for(int i = 0; i < VERTS; i++) {
			mIndexBuffer.put((short) i);
		}


        ByteBuffer cbb = ByteBuffer.allocateDirect(COLORS.length*4);
        cbb.order(ByteOrder.nativeOrder());
        mColorBuffer = cbb.asIntBuffer();
        mColorBuffer.put(COLORS);
        
		mFVertexBuffer.position(0);
		mIndexBuffer.position(0);
        mColorBuffer.position(0);
	}
 
開發者ID:archos-sa,項目名稱:aos-MediaLib,代碼行數:35,代碼來源:FadeOutBand.java


注:本文中的java.nio.ByteBuffer.asFloatBuffer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。