bool GLInputVertexAttribute::Disable() { if (isCreateOK()) { bool result = false; GLMesh* mesh = (dynamic_cast<GLRenderable*>(this->getRenderable()))->getMesh(); glDisableVertexAttribArray(m_IAHandle); if (mesh->isUseCPUBuffer() == false) { // Unbind VBO glBindBuffer(GL_ARRAY_BUFFER, 0); } result = true; m_bIsEnableOK = !result; } return !isEnableOK(); }
bool GLInputVertexAttribute::Enable() { if (isCreateOK()) { bool result = false; GLSLShader* shader = (dynamic_cast<GLRenderable*>(this->getRenderable()))->getShader(); GLMesh* mesh = (dynamic_cast<GLRenderable*>(this->getRenderable()))->getMesh(); if (shader->isCreateOK() && shader->isEnableOK() && mesh != NULL) { m_IAHandle = glGetAttribLocation(shader->getProgramHandle(), m_InputVertexAttributeName.c_str()); LOGD("call glGetAttribLocation(%d, %s), get the input attribute handle is %d", shader->getProgramHandle(), m_InputVertexAttributeName.c_str(), m_IAHandle); if (m_IAHandle != -1) { glEnableVertexAttribArray(m_IAHandle); if (mesh->isUseCPUBuffer()) { // use cpu memory's vertex buffer pointer glVertexAttribPointer(m_IAHandle, m_IAElementNum, m_IAType, m_IANormalized, m_IAStride, (BYTE*)(mesh->getVertexDataPointer()) + m_IAOffset); } else { // use gpu memory's vertex buffer glBindBuffer(GL_ARRAY_BUFFER, mesh->getVBOHandle()); glVertexAttribPointer(m_IAHandle, m_IAElementNum, m_IAType, m_IANormalized, m_IAStride, (BYTE*)m_IAOffset); } result = true; } else { LOGE("glGetAttribLocation return -1"); result = false; } } m_bIsEnableOK = result; } return isEnableOK(); }