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


Java GL10.GL_TRIANGLES属性代码示例

本文整理汇总了Java中javax.microedition.khronos.opengles.GL10.GL_TRIANGLES属性的典型用法代码示例。如果您正苦于以下问题:Java GL10.GL_TRIANGLES属性的具体用法?Java GL10.GL_TRIANGLES怎么用?Java GL10.GL_TRIANGLES使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在javax.microedition.khronos.opengles.GL10的用法示例。


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

示例1: getModelIndices

private static int[] getModelIndices(InputStream modelStream)
    throws IOException, IndexTypeNotSupportedException, PrimitiveTypeNotSupportedException {
  byte[] indexBufferSize32Bits = new byte[4];
  byte[] dataTypeBytes = new byte[4];
  byte[] primTypeBytes = new byte[4];
  byte[] sizePerElementBytes = new byte[4];
  byte[] numIndices32Bits = new byte[4];

  modelStream.read(indexBufferSize32Bits, 0, 4);
  modelStream.read(dataTypeBytes, 0, 4);
  modelStream.read(primTypeBytes, 0, 4);
  modelStream.read(sizePerElementBytes, 0, 4);
  modelStream.read(numIndices32Bits, 0, 4);

  int indexBufferSize = ByteBuffer.wrap(indexBufferSize32Bits).order(ByteOrder.LITTLE_ENDIAN).getInt();
  int primType = ByteBuffer.wrap(primTypeBytes).order(ByteOrder.LITTLE_ENDIAN).getInt();
  int numIndices = ByteBuffer.wrap(numIndices32Bits).order(ByteOrder.LITTLE_ENDIAN).getInt();

  if (primType != GL10.GL_TRIANGLES) {
    // We only support the triangle primitives right now
    throw new PrimitiveTypeNotSupportedException("Only triangle primitives are supported");
  }

  int indexTypeSize = indexBufferSize / numIndices;

  int[] indices = new int[numIndices];
  byte[] currentIndexBytes = new byte[indexTypeSize];

  // Read the indices into a buffer
  for (int i = 0; i < numIndices; i++) {
    modelStream.read(currentIndexBytes, 0, indexTypeSize);

    int currentIndex = -1;

    switch (indexTypeSize) {
      case 4:
        currentIndex = ByteBuffer.wrap(currentIndexBytes).order(ByteOrder.LITTLE_ENDIAN).getInt();
        break;
      case 2:
        currentIndex = ByteBuffer.wrap(currentIndexBytes).order(ByteOrder.LITTLE_ENDIAN).getShort();
        break;
      case 1:
        currentIndex = currentIndexBytes[0];
        break;
      default:
        // We don't support other types
        throw new IndexTypeNotSupportedException("Only integer, short and byte indices are supported");
    }

    indices[i] = currentIndex;
  }

  return indices;
}
 
开发者ID:rastapasta,项目名称:react-native-gl-model-view,代码行数:54,代码来源:RNGLModelViewModelLoader.java


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