VIZ++ Class: OpenGLVertexArray

 VIZ++ Class Library  VIZ++ Samples  VIZ++ ClassTree 

Source code

/*
 * OpenGLVertexArray.h 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


//2016/07/04 VertexArray of size = 1.

#pragma once

#ifdef GL_ARB_vertex_array_object

#include <viz++/opengl/OpenGLObject.h>

namespace VIZ {

class OpenGLVertexArray : public OpenGLObject {
private:
  GLuint*  ids;
  GLsizei size;
  
protected:
  void destroy(GLsizei s, GLuint* a)
  {
    static PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays = NULL;
    if (glDeleteVertexArrays == NULL) {
      glDeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSPROC)load("glDeleteVertexArrays");
    }
    glDeleteVertexArrays(s, a);
  }

private:
  void create(GLsizei s, GLuint* ids) 
  {
    static PFNGLGENVERTEXARRAYSPROC glGenVertexArrays = NULL;
    if (glGenVertexArrays == NULL) {
      glGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC)load("glGenVertexArrays");
    }
    glGenVertexArrays(s, ids);
  }
  
protected:
  void bind(GLuint n)
  {
    static PFNGLBINDVERTEXARRAYPROC glBindVertexArray = NULL;
    if (glBindVertexArray == NULL) {
      glBindVertexArray = (PFNGLBINDVERTEXARRAYPROC)load("glBindVertexArray");
    }
    glBindVertexArray(n);
  }

protected:
  OpenGLVertexArray(GLsizei s)
  :ids(NULL),
  size(s)
  {
    if (s < 1) {
      throw IException("Invalid size parameter.");
    }
    ids = new GLuint[s];
    memset(ids, 0, s);
    //Create uninitialized vertexArrays of size.
    create(size, ids);
  }
  
public:
  OpenGLVertexArray()
  :ids(NULL),
  size(1)
  {
    this->ids = new GLuint[this->size];
    memset(this->ids, 0, this->size);
    //Create an uninitialized vertexArray of size.
    create(this->size, this->ids);
  }
  
  ~OpenGLVertexArray()
  {
    destroy(this -> size, this->ids);
    delete [] this->ids;
    this->ids = NULL;
  }
  
  GLuint getNth(int i)
  {
    if (i >= 0 && i < size) {
      return ids[i];
    } else {
      throw IException("Invalid argument %d", i); 
    }
    
  }
  
  GLsizei getSize()
  {
    return size;
  }
  
  void bind()
  {
    bind(this->ids[0]);
  }

  void unbind()
  {
    bind(0);
  }

  GLboolean isVertexArray(GLuint n)
  {
    static PFNGLISVERTEXARRAYPROC glIsVertexArray = NULL;
    if (glIsVertexArray == NULL) {
      glIsVertexArray = (PFNGLISVERTEXARRAYPROC)load("glIsVertexArray");
    }
    return glIsVertexArray(n);
  }

  GLboolean isVertexArray()
  {
    static PFNGLISVERTEXARRAYPROC glIsVertexArray = NULL;
    if (glIsVertexArray == NULL) {
      glIsVertexArray = (PFNGLISVERTEXARRAYPROC)load("glIsVertexArray");
    }
    return glIsVertexArray(this->ids[0]);
  }

};

}

#endif


Last modified: 10 Feb 2017

Copyright (c) 2009-2017 Antillia.com ALL RIGHTS RESERVED.