{"action":"closed","issue":{"url":"https://api.github.com/repos/cinder/Cinder/issues/607","labels_url":"https://api.github.com/repos/cinder/Cinder/issues/607/labels{/name}","comments_url":"https://api.github.com/repos/cinder/Cinder/issues/607/comments","events_url":"https://api.github.com/repos/cinder/Cinder/issues/607/events","html_url":"https://github.com/cinder/Cinder/issues/607","id":49779606,"number":607,"title":"VBO with tangents corrupts OpenGL Active texture state","user":{"login":"FrozenTarzan","id":9420021,"avatar_url":"https://avatars.githubusercontent.com/u/9420021?v=3","gravatar_id":"","url":"https://api.github.com/users/FrozenTarzan","html_url":"https://github.com/FrozenTarzan","followers_url":"https://api.github.com/users/FrozenTarzan/followers","following_url":"https://api.github.com/users/FrozenTarzan/following{/other_user}","gists_url":"https://api.github.com/users/FrozenTarzan/gists{/gist_id}","starred_url":"https://api.github.com/users/FrozenTarzan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FrozenTarzan/subscriptions","organizations_url":"https://api.github.com/users/FrozenTarzan/orgs","repos_url":"https://api.github.com/users/FrozenTarzan/repos","events_url":"https://api.github.com/users/FrozenTarzan/events{/privacy}","received_events_url":"https://api.github.com/users/FrozenTarzan/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2014-11-22T09:02:20Z","updated_at":"2015-06-05T18:56:53Z","closed_at":"2015-06-05T18:56:52Z","body":"Hi all,\r\n\r\nthis is my first report, so I hope I give all information that is necessary :-)\r\n\r\nIt's about an extension for the VBO written by Paul Houx. Here is the cinder forum thread:\r\nhttps://forum.libcinder.org/topic/mesh-tangent-buffer\r\n\r\nAnd here is Paul's pull request thread here on github:\r\nhttps://github.com/cinder/Cinder/pull/388\r\n\r\nI'm actually using only the 4 source file (TriMesh.h + cpp and Vbo.h + cpp) from the branch and found an extremely strange bug where I got an access violation in a simply draw call (glDrawArrays) of a texture that was not related to anything in my project. glGetError returned invalid operation all the time, which is another strange bug because it usually should only return such an error once.\r\n\r\nI found that in enableClientStates the active texture as well as the texture coord array state are set properly: \r\n```\r\nvoid VboMesh::enableClientStates() const { \r\n  //... \r\n  for( size_t t = 0; t <= ATTR_MAX_TEXTURE_UNIT; ++t ) { \r\n    if( mObj->mLayout.hasTexCoords( t ) ) { \r\n      glClientActiveTexture( GL_TEXTURE0 + (GLenum)t ); \r\n      glEnableClientState( GL_TEXTURE_COORD_ARRAY ); \r\n    } \r\n  } \r\n  //... \r\n} \r\n```\r\nIn the method disableClientStates on the other hand there is the corresponding code missing (original code): \r\n```\r\nvoid VboMesh::disableClientStates() const { \r\n  //... \r\n  for( size_t t = 0; t <= ATTR_MAX_TEXTURE_UNIT; ++t ) { \r\n    if( mObj->mLayout.hasTexCoords( t ) ) { \r\n      glClientActiveTexture( GL_TEXTURE0 + (GLenum)t ); \r\n    } \r\n  } \r\n  glDisableClientState( GL_TEXTURE_COORD_ARRAY ); \r\n  //... \r\n} \r\n```\r\nTo overcome this bug, I changed the code to the following: \r\n```\r\nvoid VboMesh::disableClientStates() const { \r\n  //... \r\n  for( size_t t = 0; t <= ATTR_MAX_TEXTURE_UNIT; ++t ) { \r\n    if( mObj->mLayout.hasTexCoords( t ) ) { \r\n      glClientActiveTexture( GL_TEXTURE0 + (GLenum)t ); \r\n      glDisableClientState( GL_TEXTURE_COORD_ARRAY ); // 1. disable the client states \r\n    } \r\n  } \r\n  glClientActiveTexture( GL_TEXTURE7 ); // 2. set the active texture unit so that we can actually disable the client state for our tangents \r\n  glDisableClientState( GL_TEXTURE_COORD_ARRAY ); \r\n  glClientActiveTexture( GL_TEXTURE0 ); // 3. set back to active texture unit 0, the \"default\" one. at least Cinder seems to count on this everywhere else?! \r\n  //... \r\n} \r\n```\r\nI hope this all makes sense. It took me sooo long to find a solution. Is it the right one? ;-)\r\n"}}