{"action":"created","comment":{"url":"https://api.github.com/repos/mapbox/mapbox-gl-js/pulls/comments/40290715","id":40290715,"diff_hunk":"@@ -1,11 +1,10 @@\n 'use strict';\n \n var test = require('prova');\n-var Buffer = require('../../../js/data/buffer/buffer');\n var TriangleElementBuffer = require('../../../js/data/buffer/triangle_element_buffer');\n \n test('TriangleElementBuffer', function(t) {\n-    var buf = new Buffer();\n+    var buf = new TriangleElementBuffer();\n     t.ok(new TriangleElementBuffer(buf), 'default buffer');","path":"test/js/buffer/triangle_element_buffer.test.js","position":10,"original_position":10,"commit_id":"fbe0a60224e4ce5a66d324880b0906781a29c211","original_commit_id":"fbe0a60224e4ce5a66d324880b0906781a29c211","user":{"login":"mourner","id":25395,"avatar_url":"https://avatars.githubusercontent.com/u/25395?v=3","gravatar_id":"","url":"https://api.github.com/users/mourner","html_url":"https://github.com/mourner","followers_url":"https://api.github.com/users/mourner/followers","following_url":"https://api.github.com/users/mourner/following{/other_user}","gists_url":"https://api.github.com/users/mourner/gists{/gist_id}","starred_url":"https://api.github.com/users/mourner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mourner/subscriptions","organizations_url":"https://api.github.com/users/mourner/orgs","repos_url":"https://api.github.com/users/mourner/repos","events_url":"https://api.github.com/users/mourner/events{/privacy}","received_events_url":"https://api.github.com/users/mourner/received_events","type":"User","site_admin":false},"body":"double construction?","created_at":"2015-09-24T07:10:13Z","updated_at":"2015-09-24T07:10:13Z","html_url":"https://github.com/mapbox/mapbox-gl-js/pull/1526#discussion_r40290715","pull_request_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/pulls/1526","_links":{"self":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-js/pulls/comments/40290715"},"html":{"href":"https://github.com/mapbox/mapbox-gl-js/pull/1526#discussion_r40290715"},"pull_request":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-js/pulls/1526"}}},"pull_request":{"url":"https://api.github.com/repos/mapbox/mapbox-gl-js/pulls/1526","id":45731147,"html_url":"https://github.com/mapbox/mapbox-gl-js/pull/1526","diff_url":"https://github.com/mapbox/mapbox-gl-js/pull/1526.diff","patch_url":"https://github.com/mapbox/mapbox-gl-js/pull/1526.patch","issue_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/issues/1526","number":1526,"state":"open","locked":false,"title":"Added Buffer2 class","user":{"login":"lucaswoj","id":281306,"avatar_url":"https://avatars.githubusercontent.com/u/281306?v=3","gravatar_id":"","url":"https://api.github.com/users/lucaswoj","html_url":"https://github.com/lucaswoj","followers_url":"https://api.github.com/users/lucaswoj/followers","following_url":"https://api.github.com/users/lucaswoj/following{/other_user}","gists_url":"https://api.github.com/users/lucaswoj/gists{/gist_id}","starred_url":"https://api.github.com/users/lucaswoj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lucaswoj/subscriptions","organizations_url":"https://api.github.com/users/lucaswoj/orgs","repos_url":"https://api.github.com/users/lucaswoj/repos","events_url":"https://api.github.com/users/lucaswoj/events{/privacy}","received_events_url":"https://api.github.com/users/lucaswoj/received_events","type":"User","site_admin":false},"body":"**recut from #1414**\r\n\r\nUp until now, GL JS has used hand-coded classes to specify buffer layouts and buffer manipulation operations. This worked well pre-data-driven-styling because there were < 10 possible buffer layouts. For example, [here is the `TriangleElementBuffer` class](https://github.com/mapbox/mapbox-gl-js/blob/master/js/data/buffer/triangle_element_buffer.js)\r\n\r\n```js\r\nmodule.exports = TriangleElementBuffer;\r\n\r\nfunction TriangleElementBuffer(buffer) {\r\n    Buffer.call(this, buffer);\r\n}\r\n\r\nTriangleElementBuffer.prototype = util.inherit(Buffer, {\r\n    itemSize: 6, // bytes per triangle (3 * unsigned short == 6 bytes)\r\n    arrayType: 'ELEMENT_ARRAY_BUFFER',\r\n\r\n    add: function(a, b, c) {\r\n        var pos2 = this.pos / 2;\r\n\r\n        this.resize();\r\n\r\n        this.ushorts[pos2 + 0] = a;\r\n        this.ushorts[pos2 + 1] = b;\r\n        this.ushorts[pos2 + 2] = c;\r\n\r\n        this.pos += this.itemSize;\r\n    }\r\n});\r\n```\r\n\r\nPost-data-driven styling, however, the number of possible buffer layouts is [practically infinite](https://en.wikipedia.org/wiki/Zero_one_infinity_rule) because any subset of paint properties might be included in the buffer. \r\n\r\nThe first step towards proper data driven styling was to create a more general and powerful framework for buffers (temporarily called `Buffer2`) which allows buffer layouts to be specified by configuration rather than code. Using `Buffer2`, We could write the same `TriangleElementBuffer` class as\r\n\r\n```js\r\nmodule.exports = function() {\r\n    Buffer2.apply(this, {\r\n        type: Buffer2.BufferType.ELEMENT,\r\n        attributes: {\r\n            verticies: {\r\n                components: 3,\r\n                type: Buffer2.AttributeType.UNSIGNED_SHORT\r\n            }\r\n        }\r\n    });\r\n}\r\n```\r\n\r\n... but in practice we *wouldn't* write it that way. GL JS would choose the attributes for that buffer at runtime for the best performance. \r\n\r\nThe `Buffer2` class will know how to construct, write to, and read from GL buffers but have no semantic understanding of their contents. \r\n\r\nInstances of `Buffer2` can be ([destructively](https://developers.google.com/web/updates/2011/12/Transferable-Objects-Lightning-Fast?hl=en)) serialized and transferred across threads. \r\n\r\ncc @tmcw @mourner @kkaefer ","created_at":"2015-09-22T23:48:23Z","updated_at":"2015-09-24T07:10:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"15dba40cd68827a365cdf5206b77e2a62645f245","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/pulls/1526/commits","review_comments_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/pulls/1526/comments","review_comment_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/issues/1526/comments","statuses_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/statuses/fbe0a60224e4ce5a66d324880b0906781a29c211","head":{"label":"mapbox:buffer2","ref":"buffer2","sha":"fbe0a60224e4ce5a66d324880b0906781a29c211","user":{"login":"mapbox","id":600935,"avatar_url":"https://avatars.githubusercontent.com/u/600935?v=3","gravatar_id":"","url":"https://api.github.com/users/mapbox","html_url":"https://github.com/mapbox","followers_url":"https://api.github.com/users/mapbox/followers","following_url":"https://api.github.com/users/mapbox/following{/other_user}","gists_url":"https://api.github.com/users/mapbox/gists{/gist_id}","starred_url":"https://api.github.com/users/mapbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapbox/subscriptions","organizations_url":"https://api.github.com/users/mapbox/orgs","repos_url":"https://api.github.com/users/mapbox/repos","events_url":"https://api.github.com/users/mapbox/events{/privacy}","received_events_url":"https://api.github.com/users/mapbox/received_events","type":"Organization","site_admin":false},"repo":{"id":8629417,"name":"mapbox-gl-js","full_name":"mapbox/mapbox-gl-js","owner":{"login":"mapbox","id":600935,"avatar_url":"https://avatars.githubusercontent.com/u/600935?v=3","gravatar_id":"","url":"https://api.github.com/users/mapbox","html_url":"https://github.com/mapbox","followers_url":"https://api.github.com/users/mapbox/followers","following_url":"https://api.github.com/users/mapbox/following{/other_user}","gists_url":"https://api.github.com/users/mapbox/gists{/gist_id}","starred_url":"https://api.github.com/users/mapbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapbox/subscriptions","organizations_url":"https://api.github.com/users/mapbox/orgs","repos_url":"https://api.github.com/users/mapbox/repos","events_url":"https://api.github.com/users/mapbox/events{/privacy}","received_events_url":"https://api.github.com/users/mapbox/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mapbox/mapbox-gl-js","description":"Render Mapbox styles in the browser using JavaScript and WebGL","fork":false,"url":"https://api.github.com/repos/mapbox/mapbox-gl-js","forks_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/forks","keys_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/teams","hooks_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/hooks","issue_events_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/issues/events{/number}","events_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/events","assignees_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/assignees{/user}","branches_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/branches{/branch}","tags_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/tags","blobs_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/git/refs{/sha}","trees_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/statuses/{sha}","languages_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/languages","stargazers_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/stargazers","contributors_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/contributors","subscribers_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/subscribers","subscription_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/subscription","commits_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/commits{/sha}","git_commits_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/git/commits{/sha}","comments_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/comments{/number}","issue_comment_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/issues/comments{/number}","contents_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/contents/{+path}","compare_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/merges","archive_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/downloads","issues_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/issues{/number}","pulls_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/pulls{/number}","milestones_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/milestones{/number}","notifications_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/labels{/name}","releases_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/releases{/id}","created_at":"2013-03-07T14:45:24Z","updated_at":"2015-09-21T01:39:32Z","pushed_at":"2015-09-24T03:41:00Z","git_url":"git://github.com/mapbox/mapbox-gl-js.git","ssh_url":"git@github.com:mapbox/mapbox-gl-js.git","clone_url":"https://github.com/mapbox/mapbox-gl-js.git","svn_url":"https://github.com/mapbox/mapbox-gl-js","homepage":"https://www.mapbox.com/mapbox-gl-js/","size":23194,"stargazers_count":702,"watchers_count":702,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":88,"mirror_url":null,"open_issues_count":222,"forks":88,"open_issues":222,"watchers":702,"default_branch":"master"}},"base":{"label":"mapbox:master","ref":"master","sha":"3e27079242df112bc400cfa6933a9eba41d273a6","user":{"login":"mapbox","id":600935,"avatar_url":"https://avatars.githubusercontent.com/u/600935?v=3","gravatar_id":"","url":"https://api.github.com/users/mapbox","html_url":"https://github.com/mapbox","followers_url":"https://api.github.com/users/mapbox/followers","following_url":"https://api.github.com/users/mapbox/following{/other_user}","gists_url":"https://api.github.com/users/mapbox/gists{/gist_id}","starred_url":"https://api.github.com/users/mapbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapbox/subscriptions","organizations_url":"https://api.github.com/users/mapbox/orgs","repos_url":"https://api.github.com/users/mapbox/repos","events_url":"https://api.github.com/users/mapbox/events{/privacy}","received_events_url":"https://api.github.com/users/mapbox/received_events","type":"Organization","site_admin":false},"repo":{"id":8629417,"name":"mapbox-gl-js","full_name":"mapbox/mapbox-gl-js","owner":{"login":"mapbox","id":600935,"avatar_url":"https://avatars.githubusercontent.com/u/600935?v=3","gravatar_id":"","url":"https://api.github.com/users/mapbox","html_url":"https://github.com/mapbox","followers_url":"https://api.github.com/users/mapbox/followers","following_url":"https://api.github.com/users/mapbox/following{/other_user}","gists_url":"https://api.github.com/users/mapbox/gists{/gist_id}","starred_url":"https://api.github.com/users/mapbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapbox/subscriptions","organizations_url":"https://api.github.com/users/mapbox/orgs","repos_url":"https://api.github.com/users/mapbox/repos","events_url":"https://api.github.com/users/mapbox/events{/privacy}","received_events_url":"https://api.github.com/users/mapbox/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mapbox/mapbox-gl-js","description":"Render Mapbox styles in the browser using JavaScript and WebGL","fork":false,"url":"https://api.github.com/repos/mapbox/mapbox-gl-js","forks_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/forks","keys_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/teams","hooks_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/hooks","issue_events_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/issues/events{/number}","events_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/events","assignees_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/assignees{/user}","branches_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/branches{/branch}","tags_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/tags","blobs_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/git/refs{/sha}","trees_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/statuses/{sha}","languages_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/languages","stargazers_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/stargazers","contributors_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/contributors","subscribers_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/subscribers","subscription_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/subscription","commits_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/commits{/sha}","git_commits_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/git/commits{/sha}","comments_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/comments{/number}","issue_comment_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/issues/comments{/number}","contents_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/contents/{+path}","compare_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/merges","archive_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/downloads","issues_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/issues{/number}","pulls_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/pulls{/number}","milestones_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/milestones{/number}","notifications_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/labels{/name}","releases_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/releases{/id}","created_at":"2013-03-07T14:45:24Z","updated_at":"2015-09-21T01:39:32Z","pushed_at":"2015-09-24T03:41:00Z","git_url":"git://github.com/mapbox/mapbox-gl-js.git","ssh_url":"git@github.com:mapbox/mapbox-gl-js.git","clone_url":"https://github.com/mapbox/mapbox-gl-js.git","svn_url":"https://github.com/mapbox/mapbox-gl-js","homepage":"https://www.mapbox.com/mapbox-gl-js/","size":23194,"stargazers_count":702,"watchers_count":702,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":88,"mirror_url":null,"open_issues_count":222,"forks":88,"open_issues":222,"watchers":702,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-js/pulls/1526"},"html":{"href":"https://github.com/mapbox/mapbox-gl-js/pull/1526"},"issue":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-js/issues/1526"},"comments":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-js/issues/1526/comments"},"review_comments":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-js/pulls/1526/comments"},"review_comment":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-js/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-js/pulls/1526/commits"},"statuses":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-js/statuses/fbe0a60224e4ce5a66d324880b0906781a29c211"}}}}