当前位置: 首页>>代码示例>>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;未经允许,请勿转载。