{"id":301104,"date":"2020-04-01T15:00:56","date_gmt":"2020-04-01T15:00:56","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=301104"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=301104","title":{"rendered":"OpenGL \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b \u0432 \u0441\u0442\u0438\u043b\u0435 RAII"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/495068\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/0u\/1b\/ti\/0u1btiovpgzzcwrqhahy0w1yymw.png\" align=\"left\"> \u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c, \u0445\u0430\u0431\u0440\u0430 \u044e\u0437\u0435\u0440\u044b. \u042f \u0434\u0430\u0432\u043d\u043e \u043d\u0435 \u043f\u0438\u0441\u0430\u043b \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043a\u0442\u043e-\u0442\u043e \u0437\u0430\u0436\u0434\u0430\u043b\u0441\u044f \u0441\u0442\u0430\u0442\u0435\u0439 \u043e\u0442 \u043c\u0435\u043d\u044f \u2014 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u043d\u0435\u0442. \u0422\u0430\u043a \u043a\u0430\u043a \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0442\u0430\u043b\u043e \u0447\u0443\u0442\u043a\u0430 \u043f\u043e\u0431\u043e\u043b\u0435\u0435, \u0430 \u043c\u043e\u0439 GitHub \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043f\u0443\u0441\u0442, \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u043a\u043b\u043e\u043d <s>Mein kampf<\/s> Minecraft. \u0421 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e, \u044f \u0437\u0430\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u044e \u044d\u0442\u043e \u2014 \u0441\u043b\u0435\u0434\u0438\u0442\u0435 \u0437\u0430 \u043c\u043e\u0438\u043c\u0438 \u0441\u0442\u0430\u0442\u044c\u044f\u043c\u0438 \u043d\u0430 <a href=\"https:\/\/habr.com\">habr.com<\/a>. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u043a\u0430\u043a \u044f \u043e\u0431\u0435\u0440\u043d\u0443\u043b OpenGL \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b \u0432 RAII \u0441\u0442\u0438\u043b\u0435, \u0435\u0441\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u2014 \u043f\u043e\u0434 \u043a\u0430\u0442.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u042f \u0431\u0443\u0434\u0443 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 <a href=\"https:\/\/www.khronos.org\/opengl\/wiki\/Buffer_Object\" rel=\"nofollow\">Buffer Object<\/a>. \u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u2014 \u0432\u044b\u043d\u0435\u0441\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b (<a href=\"http:\/\/docs.gl\/gl4\/glGenBuffers\" rel=\"nofollow\"> glGenBuffers <\/a>, <a href=\"http:\/\/docs.gl\/gl4\/glDeleteBuffers\" rel=\"nofollow\"> glDeleteBuffers <\/a>) \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441.<\/p>\n<p>  \u0413\u0434\u0435-\u0442\u043e \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cpp\">class buffer_object { public:     buffer_object() noexcept {         glGenBuffers(1, m_object);     }          ~buffer_object() noexcept {         glDeleteBuffers(1, m_object);     }          uint32_t get_object() const noexcept {         return m_object;     } private:     uint32_t m_object; };<\/code><\/pre>\n<p>  <font color=\"#008000\">\u041f\u043b\u044e\u0441\u044b:<\/font><\/p>\n<ul>\n<li>\u041d\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435\u043c \u0431\u0443\u0444\u0435\u0440\u0430<\/li>\n<li>\u0412\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 OpenGL \u0445\u0435\u0434\u0435\u0440\u0430 \u043d\u0435 \u0442\u043e\u0440\u0447\u0438\u0442 \u043d\u0430\u0440\u0443\u0436\u0443 (\u0435\u0441\u043b\u0438 \u043c\u044b \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432 *.cpp)<\/li>\n<\/ul>\n<p>  <font color=\"#FF0000\">\u041c\u0438\u043d\u0443\u0441\u044b:<\/font><\/p>\n<ul>\n<li>\u041d\u0435 \u043c\u043e\u0436\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u0438\u043f \u0431\u0443\u0444\u0435\u0440\u0430 (array, element &#8230;) \u043f\u0440\u0438 \u0431\u0438\u043d\u0434\u0438\u043d\u0433\u0435<\/li>\n<li>\u041d\u0435 \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0443\u0444\u0435\u0440\u043e\u0432 \u043e\u0434\u043d\u0438\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u043c glGenBuffers<\/li>\n<li>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435\u043c \u043a \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443, \u0435\u0441\u043b\u0438 \u0431\u0443\u0444\u0435\u0440 \u0431\u044b\u043b \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d<\/li>\n<\/ul>\n<p>  \u0427\u0442\u043e \u0431 \u0440\u0435\u0448\u0438\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0441 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0435\u0433\u043e \u0437\u0430\u043f\u0440\u0435\u0442\u0438\u043c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 noncopyable \u0438 \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u0435\u0433\u043e.<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 noncopyable:<\/p>\n<pre><code class=\"cpp\">struct noncopyable {     noncopyable() = default;                  noncopyable(noncopyable&amp;&amp;) = default;     noncopyable&amp; operator = (noncopyable&amp;&amp;) = default;                  noncopyable(const noncopyable&amp;) = delete;     noncopyable&amp; operator = (const noncopyable&amp;) = delete; };<\/code><\/pre>\n<p>  \u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u043c\u0438\u043d\u0443\u0441 \u043e\u0434\u043d\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430. \u0414\u0443\u043c\u0430\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435, \u043a\u0430\u043a \u0431\u044b \u043d\u0430\u043c \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0441 \u0431\u0438\u043d\u0434\u0438\u043d\u0433\u043e\u043c\u2026 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 bind\/unbind:<\/p>\n<pre><code class=\"cpp\">void bind(buffer_type type) noexcept {     glBindBuffer(static_cast&lt;GLenum&gt;(type), m_object); }      void unbind() noexcept {     glBindBuffer(static_cast&lt;GLenum&gt;(type), 0); }<\/code><\/pre>\n<p>  buffer_type \u2014 enum class, \u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c extern const (\u0432 *.hpp), \u0430 \u0432 (*.cpp) \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0442\u0438\u043f\u0430:<\/p>\n<pre><code class=\"cpp\">const uint32_t array_buffer = GL_ARRAY_BUFFER;<\/code><\/pre>\n<p>  \u041e\u043f\u044f\u0442\u044c \u0436\u0435, \u0447\u0442\u043e \u0431\u044b \u043d\u0430\u0440\u0443\u0436\u0443 \u043d\u0435 \u0442\u043e\u0440\u0447\u0430\u043b <\/p>\n<pre><code class=\"cpp\">#include &lt;GL\/glew.h&gt;<\/code><\/pre>\n<p>  <font color=\"#008000\">\u041f\u043b\u044e\u0441\u044b:<\/font><\/p>\n<ul>\n<li>\u041d\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435\u043c \u0431\u0443\u0444\u0435\u0440\u0430<\/li>\n<li>\u0412\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 OpenGL \u0445\u0435\u0434\u0435\u0440\u0430 \u043d\u0435 \u0442\u043e\u0440\u0447\u0438\u0442 \u043d\u0430\u0440\u0443\u0436\u0443 (\u0435\u0441\u043b\u0438 \u043c\u044b \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432 *.cpp)<\/li>\n<li>\u041c\u043e\u0436\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u0438\u043f \u0431\u0443\u0444\u0435\u0440\u0430(array, element &#8230;) \u043f\u0440\u0438 \u0431\u0438\u043d\u0434\u0438\u043d\u0433\u0435<\/li>\n<li>\u041d\u0435\u0442 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u2014 \u043d\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c<\/li>\n<\/ul>\n<p>  <font color=\"#FF0000\">\u041c\u0438\u043d\u0443\u0441\u044b:<\/font><\/p>\n<ul>\n<li>\u041d\u0435 \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0443\u0444\u0435\u0440\u043e\u0432 \u043e\u0434\u043d\u0438\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u043c glGenBuffers<\/li>\n<\/ul>\n<p>  \u0422\u0430\u043a, \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435 \u0441\u0443\u043f\u0435\u0440, \u043d\u043e \u043c\u044b \u0435\u0449\u0435 \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0443\u0444\u0435\u0440\u043e\u0432\u2026 \u0418\u0441\u043f\u0440\u0430\u0432\u0438\u043c \u0436\u0435 \u044d\u0442\u043e.<\/p>\n<p>  glGenBuffers \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043c\u0430\u0441\u0441\u0438\u0432 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0443\u0444\u0435\u0440\u043e\u0432 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438.<br \/>  \u041d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u043c\u0430\u0441\u0441\u0438\u0432, \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c std::vector, \u043d\u043e \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0438 \u044f \u0431\u044b \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0435\u043b \u0442\u0443\u0442 std::array, \u0445\u043e\u0442\u044f \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u043d\u0430\u043c \u043f\u0440\u0438\u0439\u0434\u0435\u0442\u0441\u044f \u0438\u0437-\u0437\u0430 \u044d\u0442\u043e\u0433\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438.<\/p>\n<p>  \u041f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043d\u0430\u0448 \u043a\u043b\u0430\u0441\u0441 \u043d\u0430 std::array \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0447\u0443\u0442\u043e\u0447\u043a\u0443 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432: <\/p>\n<pre><code class=\"cpp\">constexpr uint8_t default_object_count = 1; constexpr size_t  default_index        = 0;  template &lt;type::buffer_type type, uint32_t count = default_object_count&gt; class buffer_object : noncopyable { public:     buffer_object() noexcept {         glGenBuffers(count, m_object.data());     }          ~buffer_object() noexcept {         glDeleteBuffers(count, m_object.data());     }          template &lt;size_t index = default_index&gt;     void bind() noexcept     {         static_assert(index &lt; count, &quot;index larger than array size&quot;);         glBindBuffer(static_cast&lt;GLenum&gt;(type), m_object[index]);     }          void unbind() noexcept {         glBindBuffer(static_cast&lt;GLenum&gt;(type), 0);     }          buffer_object(buffer_object&amp;&amp;) = default;     buffer_object&amp; operator = (buffer_object&amp;&amp;) = default;      private:     std::array&lt;uint32_t, count&gt; m_object; };<\/code><\/pre>\n<p>  \u0418 \u0432\u043e\u0442, \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438.<\/p>\n<p>  <font color=\"#008000\">\u041f\u043b\u044e\u0441\u044b:<\/font><\/p>\n<ul>\n<li>\u041d\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435\u043c \u0431\u0443\u0444\u0435\u0440\u0430<\/li>\n<li>\u041c\u043e\u0436\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u0438\u043f \u0431\u0443\u0444\u0435\u0440\u0430(array, element &#8230;) \u043f\u0440\u0438 \u0431\u0438\u043d\u0434\u0438\u043d\u0433\u0435<\/li>\n<li>\u041d\u0435\u0442 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u2014 \u043d\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c<\/li>\n<li>\u041c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0443\u0444\u0435\u0440\u043e\u0432 \u043e\u0434\u043d\u0438\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u043c glGenBuffers<\/li>\n<\/ul>\n<p>  <font color=\"#FF0000\">\u041c\u0438\u043d\u0443\u0441\u044b:<\/font><\/p>\n<ul>\n<li>\u041d\u0435 \u043c\u043e\u0436\u0435\u043c \u0431\u0438\u043d\u0434\u0438\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0431\u0443\u0444\u0435\u0440\u044b \u0443 \u043e\u0434\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430<\/li>\n<li>\u0412\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 OpenGL \u0445\u0435\u0434\u0435\u0440\u0430 \u0442\u043e\u0440\u0447\u0438\u0442 \u043d\u0430\u0440\u0443\u0436\u0443<\/li>\n<\/ul>\n<p>  \u041d\u0443\u2026 \u043c\u0438\u043d\u0443\u0441\u043e\u0432 \u043c\u043d\u043e\u0433\u043e\u0432\u0430\u0442\u043e, \u0447\u0442\u043e \u0442\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c?<\/p>\n<p>  \u0423\u0431\u0440\u0430\u0442\u044c \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 GL\/glew.h, \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 OpenGL (\u0432 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 OpenGL + DirectX). \u0421 \u0431\u0438\u043d\u0434\u0438\u043d\u0433\u043e\u043c \u0440\u0430\u0437\u043d\u044b\u0445 \u0431\u0443\u0444\u0435\u0440\u043e\u043c \u0447\u0443\u0442\u044c \u043f\u043e\u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u0431\u044b\u0442\u044c \u043a\u0430\u043a\u043e\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u0441 \u043a\u0430\u043a\u0438\u043c \u0431\u0443\u0444\u0435\u0440\u043e\u043c \u0431\u044b\u043b \u0437\u0430\u0431\u0438\u043d\u0434\u0436\u0435\u043d, \u043a\u0430\u043a \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2014 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043c\u0430\u0441\u0441\u0438\u0432 \u0438 \u0432 \u043d\u0435\u0433\u043e \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0442\u0438\u043f \u0431\u0443\u0444\u0435\u0440\u0430. \u042f \u043f\u043e\u043a\u0430 \u043d\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u043b\u0441\u044f \u044d\u0442\u0438\u043c, \u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043c\u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0438 \u044d\u0442\u043e\u0433\u043e.<\/p>\n<h3><font color=\"#4682B4\">\u0411\u043e\u043d\u0443\u0441<\/font><\/h3>\n<p>  \u0414\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u044f \u0441\u0434\u0435\u043b\u0430\u043b scoped bind \u043a\u043b\u0430\u0441\u0441. \u0412\u043e\u0442 \u043e\u043d:<\/p>\n<pre><code class=\"cpp\">constexpr uint32_t default_bind_index = 0; template &lt;class T&gt; class binder : utils::noncopyable { public:       template &lt;uint32_t index = default_bind_index&gt;       binder(T&amp; ref) : m_ref(ref) { m_ref.template bind&lt;index&gt;(); }     ~binder()                            { m_ref.unbind();}          private:     T&amp; m_ref; };<\/code><\/pre>\n<p>  \u0423 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043d\u0435\u0434\u043e\u0443\u043c\u0435\u043d\u0438\u0435 \u0432\u043e\u0442 \u044d\u0442\u0430 \u0441\u0442\u0440\u043e\u043a\u0430: <\/p>\n<pre><code class=\"cpp\">m_ref.template bind&lt;index&gt;();<\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u043c\u044b \u043d\u0435 \u0443\u043a\u0430\u0436\u0435\u043c \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u0430 template, \u0442\u043e \u0441\u043b\u043e\u0432\u0438\u043c \u0442\u0430\u043a\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443:<\/p>\n<p>  <font color=\"#FF0000\"><b>binder.hpp:22:46: Missing &#8216;template&#8217; keyword prior to dependent template name &#8216;bind&#8217;<\/b><\/font><br \/>  \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 T \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u043c \u0442\u0438\u043f\u043e\u043c. \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0435\u0449\u0435 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0442\u0438\u043f m_ref. \u0422\u0430\u043a \u043a\u0430\u043a \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u043d\u0438\u044f \u0435\u0449\u0435 \u043d\u0435 \u0431\u044b\u043b\u043e, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0435\u0435 \u0447\u0438\u0441\u0442\u043e \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 &lt; \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043c\u0435\u043d\u044c\u0448\u0435 \u0447\u0435\u043c. \u0427\u0442\u043e\u0431\u044b \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443, \u0447\u0442\u043e \u044d\u0442\u043e, \u043f\u043e \u0441\u0443\u0442\u0438, \u0432\u044b\u0437\u043e\u0432 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u0447\u043b\u0435\u043d\u0430, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e template \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0442\u043e\u0447\u043a\u0438.<\/p>\n<p>  \u0418 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"cpp\">GLuint VAO;      primitive::buffer_object&lt;type::buffer_type::array&gt; vbo; primitive::buffer_object&lt;type::buffer_type::element&gt; ebo;      glGenVertexArrays(1, &amp;VAO); glBindVertexArray(VAO);      {     primitive::binder bind{vbo};              glBufferData(GL_ARRAY_BUFFER, ...);              glVertexAttribPointer(...);     glEnableVertexAttribArray(...);              glVertexAttribPointer(...);     glEnableVertexAttribArray(...); }      {     primitive::binder bind{ebo};              glBufferData(GL_ELEMENT_ARRAY_BUFFER, ...);              glBindVertexArray(0); } <\/code><\/pre>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043e\u0434\u0435 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u043b\u044f Vertex Array, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043f\u0440\u0438\u0447\u0438\u043d\u044b \u044f \u0435\u0449\u0435 \u043d\u0435 \u0432\u044b\u044f\u0441\u043d\u0438\u043b, \u043d\u043e \u0441\u043a\u043e\u0440\u043e \u0441 \u044d\u0442\u0438\u043c \u0440\u0430\u0437\u0431\u0435\u0440\u0443\u0441\u044c xD<\/p>\n<p>  \u0422\u0430\u043a \u0436\u0435 \u0435\u0449\u0435 \u043d\u0435 \u0433\u043e\u0442\u043e\u0432\u044b \u043e\u0431\u0435\u0440\u0442\u043a\u0438 \u0434\u043b\u044f Buffer Data \u0438 OpenGL \u0432\u044b\u0437\u043e\u0432\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u043d\u044b \u043d\u0430 <a href=\"https:\/\/habr.com\/ru\/post\/456932\/\">DSA (Direct State Access)<\/a>.<\/p>\n<p>  \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0442\u0435\u043c, \u043a\u0442\u043e \u0434\u043e\u0447\u0438\u0442\u0430\u043b \u044d\u0442\u043e \u0434\u043e \u043a\u043e\u043d\u0446\u0430. \u041e\u0447\u0435\u043d\u044c \u0431\u0443\u0434\u0443 \u0440\u0430\u0434 \u043a\u0440\u0438\u0442\u0438\u043a\u0435 \u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c.<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/495068\/\"> https:\/\/habr.com\/ru\/post\/495068\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/495068\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/0u\/1b\/ti\/0u1btiovpgzzcwrqhahy0w1yymw.png\" align=\"left\"> \u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c, \u0445\u0430\u0431\u0440\u0430 \u044e\u0437\u0435\u0440\u044b. \u042f \u0434\u0430\u0432\u043d\u043e \u043d\u0435 \u043f\u0438\u0441\u0430\u043b \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043a\u0442\u043e-\u0442\u043e \u0437\u0430\u0436\u0434\u0430\u043b\u0441\u044f \u0441\u0442\u0430\u0442\u0435\u0439 \u043e\u0442 \u043c\u0435\u043d\u044f \u2014 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u043d\u0435\u0442. \u0422\u0430\u043a \u043a\u0430\u043a \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0442\u0430\u043b\u043e \u0447\u0443\u0442\u043a\u0430 \u043f\u043e\u0431\u043e\u043b\u0435\u0435, \u0430 \u043c\u043e\u0439 GitHub \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043f\u0443\u0441\u0442, \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u043a\u043b\u043e\u043d <s>Mein kampf<\/s> Minecraft. \u0421 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e, \u044f \u0437\u0430\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u044e \u044d\u0442\u043e \u2014 \u0441\u043b\u0435\u0434\u0438\u0442\u0435 \u0437\u0430 \u043c\u043e\u0438\u043c\u0438 \u0441\u0442\u0430\u0442\u044c\u044f\u043c\u0438 \u043d\u0430 <a href=\"https:\/\/habr.com\">habr.com<\/a>. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u043a\u0430\u043a \u044f \u043e\u0431\u0435\u0440\u043d\u0443\u043b OpenGL \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b \u0432 RAII \u0441\u0442\u0438\u043b\u0435, \u0435\u0441\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u2014 \u043f\u043e\u0434 \u043a\u0430\u0442.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-301104","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/301104","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=301104"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/301104\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=301104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=301104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=301104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}