{"action":"created","comment":{"url":"https://api.github.com/repos/SFML/SFML/pulls/comments/41608647","id":41608647,"diff_hunk":"@@ -156,11 +210,50 @@ Shader::CurrentTextureType Shader::CurrentTexture;\n \n \n ////////////////////////////////////////////////////////////\n+struct Shader::UniformBinder : private sf::NonCopyable\n+{\n+    ////////////////////////////////////////////////////////////\n+    /// \\brief Constructor: set up state before uniform is set\n+    ///\n+    ////////////////////////////////////////////////////////////\n+    UniformBinder(Shader* shader, const std::string& name) :\n+    program(0),\n+    location(-1)\n+    {\n+        if (shader->m_shaderProgram)","path":"src/SFML/Graphics/Shader.cpp","position":89,"original_position":89,"commit_id":"df1c2f04b3ac57487551fb8240a6a796515b3fb0","original_commit_id":"df1c2f04b3ac57487551fb8240a6a796515b3fb0","user":{"login":"binary1248","id":949359,"avatar_url":"https://avatars.githubusercontent.com/u/949359?v=3","gravatar_id":"","url":"https://api.github.com/users/binary1248","html_url":"https://github.com/binary1248","followers_url":"https://api.github.com/users/binary1248/followers","following_url":"https://api.github.com/users/binary1248/following{/other_user}","gists_url":"https://api.github.com/users/binary1248/gists{/gist_id}","starred_url":"https://api.github.com/users/binary1248/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/binary1248/subscriptions","organizations_url":"https://api.github.com/users/binary1248/orgs","repos_url":"https://api.github.com/users/binary1248/repos","events_url":"https://api.github.com/users/binary1248/events{/privacy}","received_events_url":"https://api.github.com/users/binary1248/received_events","type":"User","site_admin":false},"body":"What is your definition for a resource? For me, an object that actually stores and even changes the bound shader program is just as much a resource as Texture or Shader.\r\n\r\nThe constructor and destructor in GlResource are there for a reason: to make sure that the shared context is available before anybody calls ensureContext. We already had 2 cases of bugs which involved ensureContext being called before any GlResource was constructed. Working around having to construct a GlResource to access its static member functions is just another potential source of bugs.\r\n\r\nThe constructor and destructor don't even do that much. If the shared context already exists, they simply lock and unlock a mutex.","created_at":"2015-10-09T08:41:34Z","updated_at":"2015-10-09T08:41:34Z","html_url":"https://github.com/SFML/SFML/pull/983#discussion_r41608647","pull_request_url":"https://api.github.com/repos/SFML/SFML/pulls/983","_links":{"self":{"href":"https://api.github.com/repos/SFML/SFML/pulls/comments/41608647"},"html":{"href":"https://github.com/SFML/SFML/pull/983#discussion_r41608647"},"pull_request":{"href":"https://api.github.com/repos/SFML/SFML/pulls/983"}}},"pull_request":{"url":"https://api.github.com/repos/SFML/SFML/pulls/983","id":46760570,"html_url":"https://github.com/SFML/SFML/pull/983","diff_url":"https://github.com/SFML/SFML/pull/983.diff","patch_url":"https://github.com/SFML/SFML/pull/983.patch","issue_url":"https://api.github.com/repos/SFML/SFML/issues/983","number":983,"state":"open","locked":false,"title":"New API to set shader uniforms","user":{"login":"Bromeon","id":708488,"avatar_url":"https://avatars.githubusercontent.com/u/708488?v=3","gravatar_id":"","url":"https://api.github.com/users/Bromeon","html_url":"https://github.com/Bromeon","followers_url":"https://api.github.com/users/Bromeon/followers","following_url":"https://api.github.com/users/Bromeon/following{/other_user}","gists_url":"https://api.github.com/users/Bromeon/gists{/gist_id}","starred_url":"https://api.github.com/users/Bromeon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bromeon/subscriptions","organizations_url":"https://api.github.com/users/Bromeon/orgs","repos_url":"https://api.github.com/users/Bromeon/repos","events_url":"https://api.github.com/users/Bromeon/events{/privacy}","received_events_url":"https://api.github.com/users/Bromeon/received_events","type":"User","site_admin":false},"body":"\r\n\r\n*[Link to forum thread](http://en.sfml-dev.org/forums/index.php?topic=18146.0).*\r\n\r\nThis pull request implements https://github.com/SFML/SFML/issues/538 and introduces a new API to set uniform variables in `sf::Shader`. The old `setParameter()` overloads are deprecated in favor of new `setUniform()` ones.\r\n\r\nThe `sf::Glsl` namespace is added to SFML. It contains type definitions for types that can be passed to `Shader::setUniform()`. Most types are `typedef`s to existing SFML types (such as `sf::Vector2<T>`), there are however a couple of new ones:\r\n```cpp\r\nsf::Glsl::Mat3  // 3x3 matrix\r\nsf::Glsl::Mat4  // 4x4 matrix\r\nsf::Glsl::Vec4  // 4D float vector\r\nsf::Glsl::Ivec4 // 4D int vector\r\nsf::Glsl::Bvec4 // 4D bool vector\r\n```\r\nI provided implicit conversions from `sf::Transform` and `sf::Color` to these types where appropriate. Where necessary for ambiguity reasons, an explicit conversion must be used:\r\n```cpp\r\nsf::Color color;\r\nshader.setUniform(\"color\", sf::Glsl::Vec4(color)); // pass as 4D vector\r\nshader.setUniform(\"color\", color); // same call, implicit conversion\r\n\r\nsf::Transform transform;\r\nshader.setUniform(\"matrix\", sf::Glsl::Mat3(transform)); // pass as 3x3\r\nshader.setUniform(\"matrix\", sf::Glsl::Mat4(transform)); // pass as 4x4\r\n```\r\n\r\nIn addition to basic GLSL types, arrays are now supported as well. They can be specified with `Shader::setUniformArray()` that takes a pointer to the first element and the length:\r\n```cpp\r\nsf::Glsl::Vec2 positions[5] = ...;\r\nshader.setUniformArray(\"positions\", positions, 5);\r\n```\r\n\r\n-----\r\n#### Design rationale\r\n\r\nAfter extensive thinking about the design (see 2 forum threads), I came to the conclusion that `setUniform()` overloads are more appropriate than named functions `setUniformFloat()`, for the following reasons:\r\n* The call is simpler and we don't force the user to type redundant information.\r\n* We allow polymorphism (a user can write a template to pass uniforms of any type, without knowing the function names).\r\n* The number of provided methods is smaller. We can work with conversions where possible. For example, we don't need to overload `setUniformMat3()` for `sf::Glsl::Mat3`, `float*` and `sf::Transform` separately, one method taking `sf::Glsl::Mat3` is enough.\r\n* It is still possible to enforce type safety at compile time and at runtime. The former can be achieved with a wrapper function that explicitly requires the type to be specified.\r\n* There is no way around dedicated types anyway, otherwise we can't support GLSL arrays (or only in a very low-level way).\r\n\r\n-----\r\n#### Try it out\r\n\r\nA self-contained archive containing a C++ file, two GLSL shader files and an image can be downloaded temporarily from my homepage: www.bromeon.ch/sfml/feature-shader-uniforms.zip","created_at":"2015-10-05T09:41:40Z","updated_at":"2015-10-09T08:41:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"58221190d546ded3a84686afa1b794bea6c3f262","assignee":null,"milestone":{"url":"https://api.github.com/repos/SFML/SFML/milestones/10","html_url":"https://github.com/SFML/SFML/milestones/2.4","labels_url":"https://api.github.com/repos/SFML/SFML/milestones/10/labels","id":1043773,"number":10,"title":"2.4","description":"","creator":{"login":"eXpl0it3r","id":920861,"avatar_url":"https://avatars.githubusercontent.com/u/920861?v=3","gravatar_id":"","url":"https://api.github.com/users/eXpl0it3r","html_url":"https://github.com/eXpl0it3r","followers_url":"https://api.github.com/users/eXpl0it3r/followers","following_url":"https://api.github.com/users/eXpl0it3r/following{/other_user}","gists_url":"https://api.github.com/users/eXpl0it3r/gists{/gist_id}","starred_url":"https://api.github.com/users/eXpl0it3r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eXpl0it3r/subscriptions","organizations_url":"https://api.github.com/users/eXpl0it3r/orgs","repos_url":"https://api.github.com/users/eXpl0it3r/repos","events_url":"https://api.github.com/users/eXpl0it3r/events{/privacy}","received_events_url":"https://api.github.com/users/eXpl0it3r/received_events","type":"User","site_admin":false},"open_issues":25,"closed_issues":19,"state":"open","created_at":"2015-03-29T21:47:10Z","updated_at":"2015-10-05T09:51:06Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/SFML/SFML/pulls/983/commits","review_comments_url":"https://api.github.com/repos/SFML/SFML/pulls/983/comments","review_comment_url":"https://api.github.com/repos/SFML/SFML/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SFML/SFML/issues/983/comments","statuses_url":"https://api.github.com/repos/SFML/SFML/statuses/df1c2f04b3ac57487551fb8240a6a796515b3fb0","head":{"label":"SFML:feature/shader_uniforms","ref":"feature/shader_uniforms","sha":"df1c2f04b3ac57487551fb8240a6a796515b3fb0","user":{"login":"SFML","id":4226899,"avatar_url":"https://avatars.githubusercontent.com/u/4226899?v=3","gravatar_id":"","url":"https://api.github.com/users/SFML","html_url":"https://github.com/SFML","followers_url":"https://api.github.com/users/SFML/followers","following_url":"https://api.github.com/users/SFML/following{/other_user}","gists_url":"https://api.github.com/users/SFML/gists{/gist_id}","starred_url":"https://api.github.com/users/SFML/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SFML/subscriptions","organizations_url":"https://api.github.com/users/SFML/orgs","repos_url":"https://api.github.com/users/SFML/repos","events_url":"https://api.github.com/users/SFML/events{/privacy}","received_events_url":"https://api.github.com/users/SFML/received_events","type":"Organization","site_admin":false},"repo":{"id":1524684,"name":"SFML","full_name":"SFML/SFML","owner":{"login":"SFML","id":4226899,"avatar_url":"https://avatars.githubusercontent.com/u/4226899?v=3","gravatar_id":"","url":"https://api.github.com/users/SFML","html_url":"https://github.com/SFML","followers_url":"https://api.github.com/users/SFML/followers","following_url":"https://api.github.com/users/SFML/following{/other_user}","gists_url":"https://api.github.com/users/SFML/gists{/gist_id}","starred_url":"https://api.github.com/users/SFML/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SFML/subscriptions","organizations_url":"https://api.github.com/users/SFML/orgs","repos_url":"https://api.github.com/users/SFML/repos","events_url":"https://api.github.com/users/SFML/events{/privacy}","received_events_url":"https://api.github.com/users/SFML/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SFML/SFML","description":"Simple and Fast Multimedia Library","fork":false,"url":"https://api.github.com/repos/SFML/SFML","forks_url":"https://api.github.com/repos/SFML/SFML/forks","keys_url":"https://api.github.com/repos/SFML/SFML/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SFML/SFML/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SFML/SFML/teams","hooks_url":"https://api.github.com/repos/SFML/SFML/hooks","issue_events_url":"https://api.github.com/repos/SFML/SFML/issues/events{/number}","events_url":"https://api.github.com/repos/SFML/SFML/events","assignees_url":"https://api.github.com/repos/SFML/SFML/assignees{/user}","branches_url":"https://api.github.com/repos/SFML/SFML/branches{/branch}","tags_url":"https://api.github.com/repos/SFML/SFML/tags","blobs_url":"https://api.github.com/repos/SFML/SFML/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SFML/SFML/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SFML/SFML/git/refs{/sha}","trees_url":"https://api.github.com/repos/SFML/SFML/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SFML/SFML/statuses/{sha}","languages_url":"https://api.github.com/repos/SFML/SFML/languages","stargazers_url":"https://api.github.com/repos/SFML/SFML/stargazers","contributors_url":"https://api.github.com/repos/SFML/SFML/contributors","subscribers_url":"https://api.github.com/repos/SFML/SFML/subscribers","subscription_url":"https://api.github.com/repos/SFML/SFML/subscription","commits_url":"https://api.github.com/repos/SFML/SFML/commits{/sha}","git_commits_url":"https://api.github.com/repos/SFML/SFML/git/commits{/sha}","comments_url":"https://api.github.com/repos/SFML/SFML/comments{/number}","issue_comment_url":"https://api.github.com/repos/SFML/SFML/issues/comments{/number}","contents_url":"https://api.github.com/repos/SFML/SFML/contents/{+path}","compare_url":"https://api.github.com/repos/SFML/SFML/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SFML/SFML/merges","archive_url":"https://api.github.com/repos/SFML/SFML/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SFML/SFML/downloads","issues_url":"https://api.github.com/repos/SFML/SFML/issues{/number}","pulls_url":"https://api.github.com/repos/SFML/SFML/pulls{/number}","milestones_url":"https://api.github.com/repos/SFML/SFML/milestones{/number}","notifications_url":"https://api.github.com/repos/SFML/SFML/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SFML/SFML/labels{/name}","releases_url":"https://api.github.com/repos/SFML/SFML/releases{/id}","created_at":"2011-03-25T08:05:25Z","updated_at":"2015-10-08T19:40:27Z","pushed_at":"2015-10-05T14:47:40Z","git_url":"git://github.com/SFML/SFML.git","ssh_url":"git@github.com:SFML/SFML.git","clone_url":"https://github.com/SFML/SFML.git","svn_url":"https://github.com/SFML/SFML","homepage":"http://www.sfml-dev.org/","size":87494,"stargazers_count":2346,"watchers_count":2346,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":510,"mirror_url":null,"open_issues_count":71,"forks":510,"open_issues":71,"watchers":2346,"default_branch":"master"}},"base":{"label":"SFML:master","ref":"master","sha":"6b9781475d70272538a5ce48ad96f583f3a373c3","user":{"login":"SFML","id":4226899,"avatar_url":"https://avatars.githubusercontent.com/u/4226899?v=3","gravatar_id":"","url":"https://api.github.com/users/SFML","html_url":"https://github.com/SFML","followers_url":"https://api.github.com/users/SFML/followers","following_url":"https://api.github.com/users/SFML/following{/other_user}","gists_url":"https://api.github.com/users/SFML/gists{/gist_id}","starred_url":"https://api.github.com/users/SFML/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SFML/subscriptions","organizations_url":"https://api.github.com/users/SFML/orgs","repos_url":"https://api.github.com/users/SFML/repos","events_url":"https://api.github.com/users/SFML/events{/privacy}","received_events_url":"https://api.github.com/users/SFML/received_events","type":"Organization","site_admin":false},"repo":{"id":1524684,"name":"SFML","full_name":"SFML/SFML","owner":{"login":"SFML","id":4226899,"avatar_url":"https://avatars.githubusercontent.com/u/4226899?v=3","gravatar_id":"","url":"https://api.github.com/users/SFML","html_url":"https://github.com/SFML","followers_url":"https://api.github.com/users/SFML/followers","following_url":"https://api.github.com/users/SFML/following{/other_user}","gists_url":"https://api.github.com/users/SFML/gists{/gist_id}","starred_url":"https://api.github.com/users/SFML/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SFML/subscriptions","organizations_url":"https://api.github.com/users/SFML/orgs","repos_url":"https://api.github.com/users/SFML/repos","events_url":"https://api.github.com/users/SFML/events{/privacy}","received_events_url":"https://api.github.com/users/SFML/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SFML/SFML","description":"Simple and Fast Multimedia Library","fork":false,"url":"https://api.github.com/repos/SFML/SFML","forks_url":"https://api.github.com/repos/SFML/SFML/forks","keys_url":"https://api.github.com/repos/SFML/SFML/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SFML/SFML/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SFML/SFML/teams","hooks_url":"https://api.github.com/repos/SFML/SFML/hooks","issue_events_url":"https://api.github.com/repos/SFML/SFML/issues/events{/number}","events_url":"https://api.github.com/repos/SFML/SFML/events","assignees_url":"https://api.github.com/repos/SFML/SFML/assignees{/user}","branches_url":"https://api.github.com/repos/SFML/SFML/branches{/branch}","tags_url":"https://api.github.com/repos/SFML/SFML/tags","blobs_url":"https://api.github.com/repos/SFML/SFML/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SFML/SFML/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SFML/SFML/git/refs{/sha}","trees_url":"https://api.github.com/repos/SFML/SFML/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SFML/SFML/statuses/{sha}","languages_url":"https://api.github.com/repos/SFML/SFML/languages","stargazers_url":"https://api.github.com/repos/SFML/SFML/stargazers","contributors_url":"https://api.github.com/repos/SFML/SFML/contributors","subscribers_url":"https://api.github.com/repos/SFML/SFML/subscribers","subscription_url":"https://api.github.com/repos/SFML/SFML/subscription","commits_url":"https://api.github.com/repos/SFML/SFML/commits{/sha}","git_commits_url":"https://api.github.com/repos/SFML/SFML/git/commits{/sha}","comments_url":"https://api.github.com/repos/SFML/SFML/comments{/number}","issue_comment_url":"https://api.github.com/repos/SFML/SFML/issues/comments{/number}","contents_url":"https://api.github.com/repos/SFML/SFML/contents/{+path}","compare_url":"https://api.github.com/repos/SFML/SFML/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SFML/SFML/merges","archive_url":"https://api.github.com/repos/SFML/SFML/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SFML/SFML/downloads","issues_url":"https://api.github.com/repos/SFML/SFML/issues{/number}","pulls_url":"https://api.github.com/repos/SFML/SFML/pulls{/number}","milestones_url":"https://api.github.com/repos/SFML/SFML/milestones{/number}","notifications_url":"https://api.github.com/repos/SFML/SFML/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SFML/SFML/labels{/name}","releases_url":"https://api.github.com/repos/SFML/SFML/releases{/id}","created_at":"2011-03-25T08:05:25Z","updated_at":"2015-10-08T19:40:27Z","pushed_at":"2015-10-05T14:47:40Z","git_url":"git://github.com/SFML/SFML.git","ssh_url":"git@github.com:SFML/SFML.git","clone_url":"https://github.com/SFML/SFML.git","svn_url":"https://github.com/SFML/SFML","homepage":"http://www.sfml-dev.org/","size":87494,"stargazers_count":2346,"watchers_count":2346,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":510,"mirror_url":null,"open_issues_count":71,"forks":510,"open_issues":71,"watchers":2346,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SFML/SFML/pulls/983"},"html":{"href":"https://github.com/SFML/SFML/pull/983"},"issue":{"href":"https://api.github.com/repos/SFML/SFML/issues/983"},"comments":{"href":"https://api.github.com/repos/SFML/SFML/issues/983/comments"},"review_comments":{"href":"https://api.github.com/repos/SFML/SFML/pulls/983/comments"},"review_comment":{"href":"https://api.github.com/repos/SFML/SFML/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SFML/SFML/pulls/983/commits"},"statuses":{"href":"https://api.github.com/repos/SFML/SFML/statuses/df1c2f04b3ac57487551fb8240a6a796515b3fb0"}}}}