Advertisement
Guest User

Untitled

a guest
Nov 9th, 2014
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. /**
  2.      * Calculate stride value for given primitive type and tuple size.
  3.      *
  4.      * @param gpuType, one of :
  5.      * - GL_UNSIGNED_BYTE
  6.      * - GL_BYTE
  7.      * - GL_UNSIGNED_SHORT
  8.      * - GL_SHORT
  9.      * - GL_UNSIGNED_INT
  10.      * - GL_INT
  11.      * - GL_FLOAT
  12.      * - GL_DOUBLE
  13.      * @param tupleSize number of elements in a tuple
  14.      * @return stride size
  15.      */
  16.     public static int calculateStride(int gpuType, int tupleSize){
  17.         return byteSize(gpuType)*tupleSize;
  18.     }
  19.    
  20.     /**
  21.      * Get GPU primitive type size in bytes.
  22.      *
  23.      * @param gpuType, one of :
  24.      * - GL_UNSIGNED_BYTE
  25.      * - GL_BYTE
  26.      * - GL_UNSIGNED_SHORT
  27.      * - GL_SHORT
  28.      * - GL_UNSIGNED_INT
  29.      * - GL_INT
  30.      * - GL_FLOAT
  31.      * - GL_DOUBLE
  32.      * @return value size in bytes
  33.      */
  34.     public static int byteSize(final int gpuType){
  35.         switch(gpuType){
  36.             case GL4.GL_UNSIGNED_BYTE :
  37.             case GL4.GL_BYTE :
  38.                 return 1;
  39.             case GL4.GL_UNSIGNED_SHORT :
  40.             case GL4.GL_SHORT :
  41.                 return 2;
  42.             case GL4.GL_UNSIGNED_INT :
  43.             case GL4.GL_INT :
  44.             case GL4.GL_FLOAT :
  45.                 return 4;
  46.             case GL4.GL_DOUBLE :
  47.                 return 8;
  48.             default :
  49.                 throw new IllegalArgumentException("Unexpected type : "+gpuType);
  50.         }
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement