Exemplo n.º 1
0
  /**
   * @param data the data to store into the buffer
   * @param glBindType where OpenGL binds the buffer
   * @param glDrawType the way OpenGL draws the buffer
   */
  public GLBuffer(ArrayList<N> data, int glBindType, int glDrawType) {
    // First call super constructor
    this(data);

    String bindErr = "BIND";
    String drawErr = "DRAW";
    try {
      // Set fields
      this.glDrawType = GLDrawType.getType(glDrawType);
      this.glBindType = GLBindType.getType(glBindType);

      if (this.glBindType == null || this.glDrawType == null) {
        // Creates a string that indicates which values are null
        throw new NullPointerException(
            (this.glBindType == null ? bindErr : "") + (this.glDrawType == null ? drawErr : ""));
      }
    } catch (NullPointerException ex) {
      System.out.println("Could not match input to enumeration, setting necessary default values.");

      // Set to default whichever field was not configured correctly
      String errorStr = ex.toString();
      // Bind getType
      if (errorStr.contains(bindErr)) {
        System.err.println("glBindType does not match an enumerated type");
        this.glBindType = DEFAULT_BIND;

        // Draw getType
      } else if (errorStr.contains(drawErr)) {
        System.err.println("glDrawType does not match an enumerated type");
        this.glDrawType = DEFAULT_DRAW;
      }
    }
  }
Exemplo n.º 2
0
 public static GLDrawType getType(int glDrawType) {
   GLDrawType type = null;
   for (GLDrawType t : GLDrawType.values()) {
     if (t.GL_DRAW == glDrawType) {
       type = t;
       break;
     }
   }
   return type;
 }