void Light::load() {
    Cube::load();

    if(glIsVertexArray(_lightVAO) == GL_TRUE)
        glDeleteVertexArrays(1,&_lightVAO);

    glGenVertexArrays(1,&_lightVAO);

    glUseProgram(_shader.getProgramID());

    glBindVertexArray(_lightVAO);

        glBindBuffer(GL_ARRAY_BUFFER, _vbo);

            glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,0,BUFFER_OFFSET(0));
            glEnableVertexAttribArray(0);

            GLuint lightColorLoc = glGetUniformLocation(_shader.getProgramID(), "lightColor");
            float toFloat3[3] = {_lightColor.x, _lightColor.y, _lightColor.z};
            glUniform3fv(lightColorLoc, 1, toFloat3);

        glBindBuffer(GL_ARRAY_BUFFER, 0);

    glBindVertexArray(0);

    glUseProgram(0);
}
/* Clean up allocated data in a triangleSoup object */
void soupDelete(triangleSoup *soup) {

	if(glIsVertexArray(soup->vao)) {
		glDeleteVertexArrays(1, &(soup->vao));
	}
	soup->vao = 0;

	if(glIsBuffer(soup->vertexbuffer)) {
		glDeleteBuffers(1, &(soup->vertexbuffer));
	}
	soup->vertexbuffer = 0;

	if(glIsBuffer(soup->indexbuffer)) {
		glDeleteBuffers(1, &(soup->indexbuffer));
	}
	soup->indexbuffer = 0;

	if(soup->vertexarray) {
		free((void*)soup->vertexarray);
	}
	if(soup->indexarray) 	{
		free((void*)soup->indexarray);
	}
	soup->nverts = 0;
	soup->ntris = 0;

};
Exemple #3
0
void VectorIcon::Load (const float (*vertex_array)[2],
                       size_t array_size,
                       const unsigned int (*vertex_indices)[3],
                       size_t indeces_size)
{
  if (!glIsVertexArray(vao_)) {
    glGenVertexArrays(1, &vao_);
  }

  glBindVertexArray(vao_);

  vertex_buffer_.generate();
  vertex_buffer_.bind();
  vertex_buffer_.set_data(array_size * sizeof(vertex_array[0]),
                          vertex_array[0]);

  glEnableVertexAttribArray(AttributeCoord);
  glVertexAttribPointer(AttributeCoord, 2, GL_FLOAT, GL_FALSE, 0, 0);

  element_buffer_.generate();
  element_buffer_.bind();
  element_buffer_.set_data(indeces_size * sizeof(vertex_indices[0]),
                           vertex_indices[0]);

  glBindVertexArray(0);

  vertex_buffer_.reset();
  element_buffer_.reset();

  elements_ = indeces_size * 3;
}
Exemple #4
0
    void OpenGLMesh::Unload ()
    {
#ifndef SINGLE_VAO
        OPENGL_CHECK_ERROR_NO_THROW;
        if ( glIsVertexArray ( mArray ) )
        {
            OPENGL_CHECK_ERROR_NO_THROW;
            glDeleteVertexArrays ( 1, &mArray );
            OPENGL_CHECK_ERROR_NO_THROW;
            mArray = 0;
        }
#endif
        OPENGL_CHECK_ERROR_NO_THROW;
        if ( glIsBuffer ( mVertexBuffer ) )
        {
            OPENGL_CHECK_ERROR_NO_THROW;
            glDeleteBuffers ( 1, &mVertexBuffer );
            OPENGL_CHECK_ERROR_NO_THROW;
            mVertexBuffer = 0;
        }
        OPENGL_CHECK_ERROR_NO_THROW;
        if ( glIsBuffer ( mIndexBuffer ) )
        {
            OPENGL_CHECK_ERROR_NO_THROW;
            glDeleteBuffers ( 1, &mIndexBuffer );
            OPENGL_CHECK_ERROR_NO_THROW;
            mIndexBuffer = 0;
        }
        OPENGL_CHECK_ERROR_NO_THROW;
    }
Exemple #5
0
	MeshRenderer::~MeshRenderer()
	{
		if (glIsBuffer(m_vbo))
			glDeleteBuffers(1, &m_vbo);
		if (glIsVertexArray(m_vao))
			glDeleteVertexArrays(1, &m_vao);
	}
void Model::unload() {
    if (loaded && glIsVertexArray(vao) == GL_TRUE) {
        glDeleteVertexArrays(1, &vao);
        glDeleteBuffers(MAX_BUFFER, bufferObjects);
        loaded = false;
        vao = 0;
    }
    if (vertexes != nullptr) {
        if (material != nullptr) {
            ResourcesManager::releaseResource(material->getName());
            material = nullptr;
        }
        if (shader != nullptr) {
            ResourcesManager::releaseResource(shader->getName());
            shader = nullptr;
        }
        delete[] vertexes; // Not really deleting and freeing the memory?!
        delete[] uv_maps;
        delete[] normals;
        delete[] indexes;
        vertexes = nullptr;
        uv_maps = nullptr;
        normals = nullptr;
        indexes = nullptr;
        valid = false;
    }
}
Exemple #7
0
	void Shape::genVAO()
	{
		// Destruction d'un éventuel ancien VAO
	    if(glIsVertexArray(m_vaoID) == GL_TRUE)
        {
            //++m_vaoID;
            m_array_vertex_index += 3;
            m_array_coords_index += 3;
	        //glDeleteVertexArrays(1, &m_vaoID);
	    }

		// Creation du Vertex Array Object
	    glGenVertexArrays(m_vao_index, &m_vaoID);

	    // Verrouillage du VAO
    	glBindVertexArray(m_vaoID);

		    // Verrouillage du VBO
			glBindBuffer(GL_ARRAY_BUFFER, m_vboID);

			    // Accès aux vertices dans la mémoire vidéo
			    glVertexAttribPointer(m_array_vertex_index, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
			    glEnableVertexAttribArray(m_array_vertex_index);

			    glVertexAttribPointer(m_array_coords_index, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(m_sizeofVertices));
    			glEnableVertexAttribArray(m_array_coords_index);

			// Déverrouillage du VBO
			glBindBuffer(GL_ARRAY_BUFFER, 0);

	    // Déverrouillage du VAO
    	glBindVertexArray(0);
	}
Exemple #8
0
// Destroy GL objects
void Box::Cleanup()
{
	if (glIsBuffer(position_vbo) == GL_TRUE)
		glDeleteBuffers(1, &position_vbo);
	if (glIsBuffer(colour_vbo) == GL_TRUE)
		glDeleteBuffers(1, &colour_vbo);
	if (glIsVertexArray(vao) == GL_TRUE)
		glDeleteVertexArrays(1, &vao);
	_ready = false;
}
Exemple #9
0
void Vao2D::load()
{
	//LOAD VBO
	// Destruction d'un éventuel ancien VBO

	if (glIsBuffer(mVboId) == GL_TRUE)
		glDeleteBuffers(1, &mVboId);
	// Génération de l'ID
	glGenBuffers(1, &mVboId);
	// Verrouillage du VBO
	glBindBuffer(GL_ARRAY_BUFFER, mVboId);
	// Allocation de la mémoire vidéo
	glBufferData(GL_ARRAY_BUFFER, 6 * 2 * sizeof(float), 0, GL_STATIC_DRAW);

	// Transfert des données
	float mVertex[12] = {
		-1,-1,
		+1,-1,
		+1,+1,
		-1,-1,
		+1,+1,
		-1,+1
	};

	

	glBufferSubData(GL_ARRAY_BUFFER, 0, 12 * sizeof(float), mVertex);

	// Déverrouillage de l'objet

	glBindBuffer(GL_ARRAY_BUFFER, 0);
	//VBO LOADED

	//LOAD VAO
	// Destruction d'un éventuel ancien VAO

	if (glIsVertexArray(mVaoId) == GL_TRUE)
		glDeleteVertexArrays(1, &mVaoId);

	// Génération de l'identifiant du VAO
	glGenVertexArrays(1, &mVaoId);
	// Verrouillage du VAO
	glBindVertexArray(mVaoId);
	// Verrouillage du VBO
	glBindBuffer(GL_ARRAY_BUFFER, mVboId);
	// Accès aux vertices dans la mémoire vidéo
	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
	glEnableVertexAttribArray(0);
	// Déverrouillage du VBO
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	// Déverrouillage du VAO
	glBindVertexArray(0);
	//VAO LOADED
}
OVRCameraFrustum::~OVRCameraFrustum()
{
    if (glIsBuffer(m_vertexBuffers[0]))
    {
        glDeleteBuffers(3, m_vertexBuffers);
    }

    if (glIsVertexArray(m_vertexArray))
    {
        glDeleteVertexArrays(1, &m_vertexArray);
    }
}
Exemple #11
0
void graphics::mesh::use()
{
	assert(glIsVertexArray(m_VAO));

	// don't bind element buffer, it is already bound within the vao
	for (gl::uint32 i = 0; i < enum_to_t(buffer::MAX); ++i)
		if (i != enum_to_t(buffer::ELEMENT))
			glBindBufferBase(GL_SHADER_STORAGE_BUFFER, i, m_IBO[i]);
	
	glBindVertexArray(m_VAO);
	glDrawElements(GL_TRIANGLES, (gl::sizei)p_FaceIndices.size(), GL_UNSIGNED_INT, gl::bufferOffset(0));
}
Exemple #12
0
	Shape::~Shape()
	{
		// Destruction d'un éventuel ancien VBO
		if(glIsBuffer(m_vboID) == GL_TRUE) {
	        glDeleteBuffers(m_vbo_index, &m_vboID);
	    }

	    // Destruction d'un éventuel ancien VAO
	    if(glIsVertexArray(m_vaoID) == GL_TRUE) {
	        glDeleteVertexArrays(m_vao_index, &m_vaoID);
	    }
	}
GraphicObject::~GraphicObject()
{
    logger->trace(logger->get() << "Graphic object destructor");
    if(glIsBuffer(VBOId_)  == GL_TRUE)
    {
        glDeleteBuffers(1, &VBOId_);
    }

    if(glIsVertexArray(VAOId_) == GL_TRUE)
    {
      glDeleteVertexArrays(1, &VAOId_);
    }
}
Exemple #14
0
	void VertexArrayObject::AttribPointer(GLuint buffer, GLuint index,GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer) {
		if(!glIsVertexArray(this->ID)) {
			throw Exception(DSGL_VAO_DOESNT_EXIST, "DSGL: VAO doesn't exist.");			
		}
		glBindVertexArray(this->ID); {
			glBindBuffer(GL_ARRAY_BUFFER, buffer);
			if(!glIsBuffer(this->VBO)) {
				throw Exception(DSGL_VBO_DOESNT_EXIST, "DSGL: Vertex buffer doesn't exist.");
			}
			glEnableVertexAttribArray(index);
			glVertexAttribPointer(index, size, type, normalized, stride, pointer);
		}
		glBindVertexArray(0);
	}
    void HardwareGeometry::cleanUp
    (

    )
    {
        if( glIsBuffer(m_vbo) )
            GLCheck(glDeleteBuffers(1, &m_vbo));

        if( glIsBuffer(m_ibo) )
            GLCheck(glDeleteBuffers(1, &m_ibo));

        if( glIsVertexArray(m_vao) )
            GLCheck(glDeleteVertexArrays(1, &m_vao));
    }
Exemple #16
0
GC3Dboolean Extensions3DOpenGL::isVertexArrayOES(Platform3DObject array)
{
    if (!array)
        return GL_FALSE;

    m_context->makeContextCurrent();
#if (PLATFORM(GTK) || PLATFORM(EFL) || PLATFORM(WIN) || PLATFORM(NIX) || PLATFORM(JS))
    if (isVertexArrayObjectSupported())
        return glIsVertexArray(array);
#elif defined(GL_APPLE_vertex_array_object) && GL_APPLE_vertex_array_object
    return glIsVertexArrayAPPLE(array);
#endif
    return GL_FALSE;
}
Exemple #17
0
void Mesh::render() {
    initializeOpenGLFunctions();
    if (glIsVertexArray(vao) == GL_FALSE || glIsBuffer(vbo) == GL_FALSE) {
        return;
    }
    glBindVertexArray(vao);
    if (glIsBuffer(ibo) == GL_TRUE) {
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
        glDrawElements(GL_TRIANGLES, indicesCount, GL_UNSIGNED_INT, 0);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    } else {
        glDrawArrays(GL_TRIANGLES, 0, verticesCount);
    }
    glBindVertexArray(0);
}
Exemple #18
0
void
piglit_init(int argc, char **argv)
{
	GLuint id;
	GLboolean apple = GL_FALSE;

	if (argc == 2 && strcmp(argv[1], "apple") == 0) {
		printf("apple\n");
		apple = GL_TRUE;
	}

	piglit_require_gl_version(15);
	if (apple)
		piglit_require_extension("GL_APPLE_vertex_array_object");
	else
		piglit_require_extension("GL_ARB_vertex_array_object");

	glGenVertexArrays(1, &id);

	if (glIsVertexArray(id)) {
		fprintf(stderr, "id recognized incorrectly as a vertex array object.\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	if (apple)
		glBindVertexArrayAPPLE(id);
	else
		glBindVertexArray(id);

	if (!glIsVertexArray(id)) {
		fprintf(stderr, "id not recognized correctly as a vertex array object.\n");
		piglit_report_result(PIGLIT_FAIL);
	}

	piglit_report_result(PIGLIT_PASS);
}
Exemple #19
0
void menuBox::clean() {
	if (glIsVertexArray(vao)) {
		glDeleteVertexArrays(1, &vao);
	}
	vao = 0;

	if (glIsBuffer(vertexbuffer)) {
		glDeleteBuffers(1, &vertexbuffer);
	}
	vertexbuffer = 0;

	if (glIsBuffer(indexbuffer)) {
		glDeleteBuffers(1, &indexbuffer);
	}
	indexbuffer = 0;
}
Exemple #20
0
void Mesh::loadTangents(vec3f *tangents, int size) {
    initializeOpenGLFunctions();
    if (glIsVertexArray(vao) == GL_FALSE) {
        glGenVertexArrays(1, &vao);
    }
    if (glIsBuffer(tbo) == GL_TRUE) {
        glDeleteBuffers(1, &tbo);
    }
    glGenBuffers(1, &tbo);
    glBindVertexArray(vao);
    glBindBuffer(GL_ARRAY_BUFFER, tbo);
    glBufferData(GL_ARRAY_BUFFER, size, tangents, GL_STATIC_DRAW);
    glEnableVertexAttribArray(3);
    glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, 0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindVertexArray(0);
}
Exemple #21
0
void Mesh::loadTexture2DCoordinates(float *texture2DCoordinates, int size) {
    initializeOpenGLFunctions();
    if (glIsVertexArray(vao) == GL_FALSE) {
        glGenVertexArrays(1, &vao);
    }
    if (glIsBuffer(t2dbo) == GL_TRUE) {
        glDeleteBuffers(1, &t2dbo);
    }
    glGenBuffers(1, &t2dbo);
    glBindVertexArray(vao);
    glBindBuffer(GL_ARRAY_BUFFER, t2dbo);
    glBufferData(GL_ARRAY_BUFFER, size, texture2DCoordinates, GL_STATIC_DRAW);
    glEnableVertexAttribArray(2);
    glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, 0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindVertexArray(0);
}
Exemple #22
0
void Mesh::loadVertices(vec3f *vertices, int size) {
    initializeOpenGLFunctions();
    if (glIsVertexArray(vao) == GL_FALSE) {
        glGenVertexArrays(1, &vao);
    }
    if (glIsBuffer(vbo) == GL_TRUE) {
        glDeleteBuffers(1, &vbo);
    }
    glGenBuffers(1, &vbo);
    glBindVertexArray(vao);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_STATIC_DRAW);
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindVertexArray(0);
    verticesCount = size / sizeof(vec3f);
}
void BasePoint::load()
{
	if (glIsVertexArray(m_vao)) {glDeleteVertexArrays(1, &m_vao);}
	glGenVertexArrays(1, &m_vao);
	glBindVertexArray(m_vao);
	if (glIsBuffer(m_vbo)) { glDeleteBuffers(1, &m_vbo); }
	glGenBuffers(1, &m_vbo);
	printf("Bp vbo = %i\n", m_vbo);
	glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
	glBufferData(GL_ARRAY_BUFFER, m_coordsBytesSize*2, m_coords, GL_STATIC_DRAW);
	glBufferSubData(GL_ARRAY_BUFFER, m_coordsBytesSize, m_coordsBytesSize, m_colors);

	glVertexAttribPointer(0, 3, GL_FLOAT,GL_FALSE,0,0) ;
	glVertexAttribPointer(1, 3, GL_FLOAT,GL_FALSE,0,BUFFER_OFFSET(m_coordsBytesSize));
	glEnableVertexAttribArray(0);
	glEnableVertexAttribArray(1);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindVertexArray(0);
}
Exemple #24
0
void Sphere::clean() 
{
	

	if (glIsVertexArray(shape->vao)) {
		glDeleteVertexArrays(1, &shape->vao);
	}
	shape->vao = 0;

	if (glIsBuffer(shape->vertexbuffer)) {
		glDeleteBuffers(1, &shape->vertexbuffer);
	}
	shape->vertexbuffer = 0;

	if (glIsBuffer(shape->indexbuffer)) {
		glDeleteBuffers(1, &shape->indexbuffer);
	}
	shape->indexbuffer = 0;
}
Exemple #25
0
ModelGL::ModelGL(
	GLuint vao,
       	GLuint vertData,
       	GLuint indexData,
       	int numIndices
)
	: vao(vao)
	, vertData(vertData)
	, indexData(indexData)
	, numIndices(numIndices)
{
	if(!glIsBuffer(vertData))
		LOG_MSG(LOG, "Iffy buffer for vert data (%d)",
			vertData);
	if(!glIsBuffer(indexData))
		LOG_MSG(LOG, "Iffy buffer for index data(%d)",
			indexData);
	if(!glIsVertexArray(vao))
		LOG_MSG(LOG, "Iffy vertex array (%d)", vao);
}
Exemple #26
0
	void OpenGLContext::deleteResources()
	{
		if (m_impl->isCurrent())
		{
			for (auto vao : m_deletedVaos)
			{
				if (glIsVertexArray(vao) == GL_TRUE)
					glDeleteVertexArrays(1, &vao);
			}

			m_deletedVaos.clear();

			for (auto fbo : m_deletedFbos)
			{
				if (glIsFramebuffer(fbo) == GL_TRUE)
					glDeleteFramebuffers(1, &fbo);
			}

			m_deletedFbos.clear();
		}
	}
GC3Dboolean Extensions3DOpenGL::isVertexArrayOES(Platform3DObject array)
{
    if (!array)
        return GL_FALSE;

    m_context->makeContextCurrent();
#if (PLATFORM(GTK) || PLATFORM(EFL) || PLATFORM(WIN))
    if (isVertexArrayObjectSupported())
        return glIsVertexArray(array);
#elif PLATFORM(QT)
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
    if (isVertexArrayObjectSupported())
        return m_vaoFunctions->glIsVertexArray(array);
#endif
#elif defined(GL_APPLE_vertex_array_object) && GL_APPLE_vertex_array_object
    return glIsVertexArrayAPPLE(array);
#endif

    m_context->synthesizeGLError(GL_INVALID_OPERATION);
    return GL_FALSE;
}
Exemple #28
0
  void RawModel::cleanup()
  {
    if(glIsVertexArray(VAO))
    {
      glDeleteVertexArrays(1, &VAO);
    }


    VAO = 0;

    for (GLuint& VBO : VBOs)
    {
      if(glIsBuffer(VBO))
      {
        glDeleteBuffers(1, &VBO);
      }


      VBO = 0;
    }
  }
Exemple #29
0
void Crate::load()
{
    //VBO
    if(glIsBuffer(VBOId_) == GL_TRUE)
    {
        glDeleteBuffers(1, &VBOId_);
    }

    glGenBuffers(1, &VBOId_);
    glBindBuffer(GL_ARRAY_BUFFER, VBOId_);

        glBufferData(GL_ARRAY_BUFFER, nbVerticesBytes() + nbTextureBytes(), 0, GL_STATIC_DRAW);


        glBufferSubData(GL_ARRAY_BUFFER, 0, nbVerticesBytes(), vertices_.data());
        glBufferSubData(GL_ARRAY_BUFFER, nbVerticesBytes(), nbTextureBytes(), textureCoord_.data());

    glBindBuffer(GL_ARRAY_BUFFER, 0);

    //VAO
    if(glIsVertexArray(VAOId_) == GL_TRUE)
    {
        glDeleteVertexArrays(1, &VAOId_);
    }

    glGenVertexArrays(1, &VAOId_);
    glBindVertexArray(VAOId_);

        glBindBuffer(GL_ARRAY_BUFFER, VBOId_);

            glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0,  BUFFER_OFFSET(0));
            glEnableVertexAttribArray(0);

            glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0,  BUFFER_OFFSET(nbVerticesBytes()));
            glEnableVertexAttribArray(2);

        glBindBuffer(GL_ARRAY_BUFFER, 0);

        glBindVertexArray(0);
}
Exemple #30
0
void CGLvbo::Cleanup()
{
	checkGLError();
	if(mVertObjId != UINT_MAX)
	{
		const GLboolean glbIsBuffer = glIsBuffer(mVertObjId);
		if(glbIsBuffer==GL_TRUE) {
			glDeleteBuffers(1, &mVertObjId);
			mVertObjId = UINT_MAX;
		}
		checkGLError();
	}
	if(mNormObjId != UINT_MAX)
	{
		const GLboolean glbIsBuffer = glIsBuffer(mNormObjId);
		if(glbIsBuffer==GL_TRUE) {
			glDeleteBuffers(1, &mNormObjId);
			mNormObjId = UINT_MAX;
		}
		checkGLError();
	}
	if(mUVObjId != UINT_MAX)
	{
		const GLboolean glbIsBuffer = glIsBuffer(mUVObjId);
		if(glbIsBuffer==GL_TRUE) {
			glDeleteBuffers(1, &mUVObjId);
			mUVObjId = UINT_MAX;
		}
		checkGLError();
	}
	if(mVAO != UINT_MAX)
	{
		const GLboolean glbIsVA = glIsVertexArray(mVAO);
		if(glbIsVA==GL_TRUE) {
			glDeleteVertexArrays(1, &mVAO);
			mVAO = UINT_MAX;
		}
		checkGLError();
	}
}