{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/10218","labels_url":"https://api.github.com/repos/golang/go/issues/10218/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/10218/comments","events_url":"https://api.github.com/repos/golang/go/issues/10218/events","html_url":"https://github.com/golang/go/issues/10218","id":63649998,"number":10218,"title":"x/mobile/gl: Suggestions/questions that arose while adding WebGL backend.","user":{"login":"shurcooL","id":1924134,"avatar_url":"https://avatars.githubusercontent.com/u/1924134?v=3","gravatar_id":"","url":"https://api.github.com/users/shurcooL","html_url":"https://github.com/shurcooL","followers_url":"https://api.github.com/users/shurcooL/followers","following_url":"https://api.github.com/users/shurcooL/following{/other_user}","gists_url":"https://api.github.com/users/shurcooL/gists{/gist_id}","starred_url":"https://api.github.com/users/shurcooL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shurcooL/subscriptions","organizations_url":"https://api.github.com/users/shurcooL/orgs","repos_url":"https://api.github.com/users/shurcooL/repos","events_url":"https://api.github.com/users/shurcooL/events{/privacy}","received_events_url":"https://api.github.com/users/shurcooL/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/golang/go/labels/repo-mobile","name":"repo-mobile","color":"ededed"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-23T07:34:33Z","updated_at":"2015-03-23T18:09:25Z","closed_at":null,"body":"Hi @crawshaw,\r\n\r\nBased on your proposal in https://github.com/google/gxui/issues/49#issuecomment-84324901 to try adding a WebGL backend to `x/mobile/gl`, I've been playing on a branch with making that happen.\r\n\r\nOverall, it's going really well, and most things were a natural fit. I got it to work rendering a basic triangle with these imports:\r\n\r\n```Go\r\npackage main\r\n\r\nimport (\r\n\t\"encoding/binary\"\r\n\t\"errors\"\r\n\t\"fmt\"\r\n\r\n\t\"github.com/go-gl/mathgl/mgl32\"\r\n\tglfw \"github.com/shurcooL/goglfw\"\r\n\t\"golang.org/x/mobile/f32\"\r\n\t\"golang.org/x/mobile/gl\"\r\n)\r\n```\r\n\r\n![image](https://cloud.githubusercontent.com/assets/1924134/6774928/08aa2e18-d0e6-11e4-9c84-b5c20ef7257f.png)\r\n\r\nAlong the way, I found some issues with the existing interface of `x/mobile/gl` and I was wondering what your thoughts on making changes are.\r\n\r\nFirst, a summary of my proposed changes, and below is a detailed rationale:\r\n\r\n```diff\r\nBufferData(target, usage, src) -> BufferData(target, src, usage)\r\n\r\nGenBuffer -> CreateBuffer\r\nGenFramebuffer -> CreateFramebuffer\r\nGenRenderbuffer -> CreateRenderbuffer\r\nGenTexture -> CreateTexture\r\n\r\n// Maybe?\r\nGetShaderi -> GetShaderParameteri\r\nGetProgrami -> GetProgramParameteri\r\n\r\n// Even more maybe?\r\n+func GetShaderParameterb(s Shader, pname Enum) bool\r\n+func GetProgramParameterb(p Program, pname Enum) bool\r\n```\r\n\r\n### 1. `func BufferData(target Enum, usage Enum, src []byte)` parameter order.\r\n\r\nThe order of `usage` and `src` seems to be swapped compared to OpenGL ES spec:\r\n\r\nhttp://www.khronos.org/opengles/sdk/docs/man3/html/glBufferData.xhtml\r\n\r\n```\r\nvoid glBufferData(GLenum target,\r\n                  GLsizeiptr size,\r\n                  const GLvoid * data,\r\n                  GLenum usage);\r\n```\r\n\r\nIt is also swapped compared to WebGL spec:\r\n\r\n```\r\nvoid bufferData(GLenum target, GLsizeiptr size, GLenum usage);\r\nvoid bufferData(GLenum target, ArrayBufferView data, GLenum usage);\r\nvoid bufferData(GLenum target, ArrayBuffer? data, GLenum usage);\r\n```\r\n\r\nNotably, `usage` should come last.\r\n\r\nI suggest swapping the order:\r\n\r\n```Go\r\nfunc BufferData(target Enum, src []byte, usage Enum)\r\n```\r\n\r\n### 2. When need to invent new names, consider WebGL names instead of own.\r\n\r\nThe `x/mobile/gl` package offers a higher level API that slightly deviates from the OpenGL ES spec. It comes up with new function names in a few cases where no equivalent func exists in OpenGL ES spec. For example:\r\n\r\nhttp://www.khronos.org/opengles/sdk/docs/man3/html/glGenBuffers.xhtml\r\n\r\n`void glGenBuffers(GLsizei n, GLuint * buffers)`\r\n\r\n`func GenBuffer() Buffer`\r\n\r\n`glGenBuffer` always creates a single buffer, while the OpenGL ES spec's `glGenBuffers` takes a parameter `n`.\r\n\r\n[WebGL spec](https://www.khronos.org/registry/webgl/specs/1.0.2/) does not have `glGenBuffers` either, but instead it provides:\r\n\r\n`WebGLBuffer? createBuffer();`\r\n\r\nWhich is exactly the same signature, just different name. I suggest using `func CreateBuffer() Buffer` to match WebGL spec name.\r\n\r\nIt is more consistent with other OpenGL names like `glCreateProgram` and `glCreateShader`.\r\n\r\nSimilarly:\r\n\r\n```\r\nGenFramebuffer -> CreateFramebuffer\r\nGenRenderbuffer -> CreateRenderbuffer\r\nGenTexture -> CreateTexture\r\n```\r\n\r\nAnother such case is something I'm less sure about, but I'll mention it.\r\n\r\n`x/mobile/gl` has `GetShaderi` and `GetProgrami`. Those do not exist in OpenGL ES, it only has the `GetShaderiv` and `GetProgramiv` variants that accept multiple entries and use pointers.\r\n\r\nWebGL does not have `GetShaderiv` and `GetProgramiv`, but instead it has:\r\n\r\n```\r\nany getShaderParameter(WebGLShader? shader, GLenum pname);\r\nany getProgramParameter(WebGLProgram? program, GLenum pname);\r\n```\r\n\r\nWhich is the same signature, just different name.\r\n\r\nSo, if you want to be more consistent with WebGL spec here, I would recommend renaming:\r\n\r\n```\r\nGetShaderi -> GetShaderParameteri\r\nGetProgrami -> GetProgramParameteri\r\n```\r\n\r\n(And possibly offer the boolean variants `GetShaderParameterb` and `GetProgramParameterb`...)\r\n\r\nReason why I think it's better to reuse existing WebGL names rather invent own ones is (when signatures match), when inventing own, everyone has to find and learn it. But when reusing WebGL names, people porting/looking at existing WebGL code, which I imagine is a lot of code in the wild, will have an easier time porting/understanding Go code that uses `x/mobile/gl` package.\r\n\r\nThoughts?\r\n\r\n/cc @ajhager @slimsag @neelance"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/85127911","html_url":"https://github.com/golang/go/issues/10218#issuecomment-85127911","issue_url":"https://api.github.com/repos/golang/go/issues/10218","id":85127911,"user":{"login":"crawshaw","id":161319,"avatar_url":"https://avatars.githubusercontent.com/u/161319?v=3","gravatar_id":"","url":"https://api.github.com/users/crawshaw","html_url":"https://github.com/crawshaw","followers_url":"https://api.github.com/users/crawshaw/followers","following_url":"https://api.github.com/users/crawshaw/following{/other_user}","gists_url":"https://api.github.com/users/crawshaw/gists{/gist_id}","starred_url":"https://api.github.com/users/crawshaw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crawshaw/subscriptions","organizations_url":"https://api.github.com/users/crawshaw/orgs","repos_url":"https://api.github.com/users/crawshaw/repos","events_url":"https://api.github.com/users/crawshaw/events{/privacy}","received_events_url":"https://api.github.com/users/crawshaw/received_events","type":"User","site_admin":false},"created_at":"2015-03-23T18:09:25Z","updated_at":"2015-03-23T18:09:25Z","body":"I never decided when to freeze the method signatures of the gl package. It definitely should be frozen by the time Go 1.5 comes out. But I suppose it is still safe to change some, as long as nothing breaks silently.\r\n\r\n- BufferData change looks good.\r\n- s/Gen/Create/ is OK. Create is a better word.\r\n- I'm not really interested enough in exactly matching WebGL to change Get{Shader,Program}i to Get{Shader,Program}Parameteri. Seems unnecessarily wordy, and the names are clear enough.\r\n\r\nIf you'd like to send CLs for the first two, please do. Update any call references to them in the mobile repo please."}}