{"id":988,"date":"2011-05-06T12:34:21","date_gmt":"2011-05-06T03:04:21","guid":{"rendered":"http:\/\/www.clearchain.com\/blog\/?p=988"},"modified":"2011-05-06T12:34:21","modified_gmt":"2011-05-06T03:04:21","slug":"opengl-gltexsubimage2d-very-slow-a-solution","status":"publish","type":"post","link":"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution","title":{"rendered":"OpenGL glTexSubImage2D very slow &#8211; a solution!"},"content":{"rendered":"<p><a href=\"http:\/\/www.clearchain.com\/blog\/images\/\/2011\/05\/opengl2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-medium wp-image-989\" title=\"opengl2\" src=\"http:\/\/www.clearchain.com\/blog\/images\/\/2011\/05\/opengl2-300x135.png\" alt=\"\" width=\"300\" height=\"135\" srcset=\"https:\/\/www.clearchain.com\/blog\/images\/2011\/05\/opengl2-300x135.png 300w, https:\/\/www.clearchain.com\/blog\/images\/2011\/05\/opengl2.png 520w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><em>This article describes a possible reason glTexSubImage2D may be slow.<\/em><\/p>\n<p>Recently I was working on a piece of code that updated a texture with a camera frame. The application was using the fixed function (non shaders) pipeline of OpenGL. Whilst I didn&#8217;t notice it at first, I soon found that the camera image was very delayed. For example the camera was capturing at 30 frames per second, but the screen update rate was only 6 frames per second.<\/p>\n<p>After commenting out vast amounts of code, disabling functions the reason behind the slow frame rates was traced to the OpenGL call: glTexSubImage2D. The exact call that was being made was:<\/p>\n<pre>glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,  mWidth, mHeight,  GL_RGB, GL_UNSIGNED_BYTE, image-&gt;getData());<\/pre>\n<p>Everything to this call looked normal. I tried a simple test program that used glTextSubImage2D and surprizingly it ran fast! So at this point I was a little confused. How could two very similar programs produce different results.<br \/>\nI kept searching. I tried Google searches found various comments but none of them seemed to work.<\/p>\n<p>Eventually I looked at the Texture class I had been using and began commenting lines out of that. It was only when I found and commented out the line:<\/p>\n<pre>glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE );<\/pre>\n<p>Things improved. This makes perfect sense as well. Generating a mipmap each frame is expensive. A quick fix and the application was running smoothly!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article describes a possible reason glTexSubImage2D may be slow. Recently I was working on a piece of code that updated a texture with a camera frame. The application was using the fixed function (non shaders) pipeline of OpenGL. Whilst I didn&#8217;t notice it at first, I soon found that the camera image was very<a href=\"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution\"> <font size=-2>[..more..]<\/font><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[352,354,355,351,358,357,353,356],"class_list":["post-988","post","type-post","status-publish","format-standard","hentry","category-programming","tag-gltexsubimage2d","tag-mipmap","tag-mipmapping","tag-opengl","tag-performance-issue","tag-shader","tag-slow","tag-texture"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>OpenGL glTexSubImage2D very slow - a solution! - ClearChain<\/title>\n<meta name=\"description\" content=\"This article describes a possible reason glTexSubImage2D may be slow. Recently I was working on a piece of code that updated a texture with a camera\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin Close\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution\"},\"author\":{\"name\":\"Benjamin Close\",\"@id\":\"https:\/\/www.clearchain.com\/blog\/#\/schema\/person\/aef6faa2c32188398139db9270ca1c98\"},\"headline\":\"OpenGL glTexSubImage2D very slow &#8211; a solution!\",\"datePublished\":\"2011-05-06T03:04:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution\"},\"wordCount\":227,\"commentCount\":1,\"image\":{\"@id\":\"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution#primaryimage\"},\"thumbnailUrl\":\"http:\/\/www.clearchain.com\/blog\/images\/\/2011\/05\/opengl2-300x135.png\",\"keywords\":[\"glTexSubImage2D\",\"mipmap\",\"mipmapping\",\"opengl\",\"performance issue\",\"shader\",\"slow\",\"texture\"],\"articleSection\":[\"Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution\",\"url\":\"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution\",\"name\":\"OpenGL glTexSubImage2D very slow - a solution! - ClearChain\",\"isPartOf\":{\"@id\":\"https:\/\/www.clearchain.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution#primaryimage\"},\"thumbnailUrl\":\"http:\/\/www.clearchain.com\/blog\/images\/\/2011\/05\/opengl2-300x135.png\",\"datePublished\":\"2011-05-06T03:04:21+00:00\",\"author\":{\"@id\":\"https:\/\/www.clearchain.com\/blog\/#\/schema\/person\/aef6faa2c32188398139db9270ca1c98\"},\"description\":\"This article describes a possible reason glTexSubImage2D may be slow. Recently I was working on a piece of code that updated a texture with a camera\",\"breadcrumb\":{\"@id\":\"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution#primaryimage\",\"url\":\"http:\/\/www.clearchain.com\/blog\/images\/\/2011\/05\/opengl2-300x135.png\",\"contentUrl\":\"http:\/\/www.clearchain.com\/blog\/images\/\/2011\/05\/opengl2-300x135.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.clearchain.com\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"OpenGL glTexSubImage2D very slow &#8211; a solution!\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.clearchain.com\/blog\/#website\",\"url\":\"https:\/\/www.clearchain.com\/blog\/\",\"name\":\"ClearChain\",\"description\":\"-= Daily Happenings =-\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.clearchain.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.clearchain.com\/blog\/#\/schema\/person\/aef6faa2c32188398139db9270ca1c98\",\"name\":\"Benjamin Close\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.clearchain.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/19dca0aa372edfa901b93c556dfda2e78ad4434558fe4d139598e086315d714a?s=96&d=mm&r=pg\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/19dca0aa372edfa901b93c556dfda2e78ad4434558fe4d139598e086315d714a?s=96&d=mm&r=pg\",\"caption\":\"Benjamin Close\"},\"sameAs\":[\"http:\/\/www.clearchain.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"OpenGL glTexSubImage2D very slow - a solution! - ClearChain","description":"This article describes a possible reason glTexSubImage2D may be slow. Recently I was working on a piece of code that updated a texture with a camera","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution","twitter_misc":{"Written by":"Benjamin Close","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution#article","isPartOf":{"@id":"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution"},"author":{"name":"Benjamin Close","@id":"https:\/\/www.clearchain.com\/blog\/#\/schema\/person\/aef6faa2c32188398139db9270ca1c98"},"headline":"OpenGL glTexSubImage2D very slow &#8211; a solution!","datePublished":"2011-05-06T03:04:21+00:00","mainEntityOfPage":{"@id":"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution"},"wordCount":227,"commentCount":1,"image":{"@id":"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution#primaryimage"},"thumbnailUrl":"http:\/\/www.clearchain.com\/blog\/images\/\/2011\/05\/opengl2-300x135.png","keywords":["glTexSubImage2D","mipmap","mipmapping","opengl","performance issue","shader","slow","texture"],"articleSection":["Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution","url":"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution","name":"OpenGL glTexSubImage2D very slow - a solution! - ClearChain","isPartOf":{"@id":"https:\/\/www.clearchain.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution#primaryimage"},"image":{"@id":"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution#primaryimage"},"thumbnailUrl":"http:\/\/www.clearchain.com\/blog\/images\/\/2011\/05\/opengl2-300x135.png","datePublished":"2011-05-06T03:04:21+00:00","author":{"@id":"https:\/\/www.clearchain.com\/blog\/#\/schema\/person\/aef6faa2c32188398139db9270ca1c98"},"description":"This article describes a possible reason glTexSubImage2D may be slow. Recently I was working on a piece of code that updated a texture with a camera","breadcrumb":{"@id":"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution#primaryimage","url":"http:\/\/www.clearchain.com\/blog\/images\/\/2011\/05\/opengl2-300x135.png","contentUrl":"http:\/\/www.clearchain.com\/blog\/images\/\/2011\/05\/opengl2-300x135.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.clearchain.com\/blog\/posts\/opengl-gltexsubimage2d-very-slow-a-solution#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.clearchain.com\/blog"},{"@type":"ListItem","position":2,"name":"OpenGL glTexSubImage2D very slow &#8211; a solution!"}]},{"@type":"WebSite","@id":"https:\/\/www.clearchain.com\/blog\/#website","url":"https:\/\/www.clearchain.com\/blog\/","name":"ClearChain","description":"-= Daily Happenings =-","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.clearchain.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.clearchain.com\/blog\/#\/schema\/person\/aef6faa2c32188398139db9270ca1c98","name":"Benjamin Close","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.clearchain.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/19dca0aa372edfa901b93c556dfda2e78ad4434558fe4d139598e086315d714a?s=96&d=mm&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/19dca0aa372edfa901b93c556dfda2e78ad4434558fe4d139598e086315d714a?s=96&d=mm&r=pg","caption":"Benjamin Close"},"sameAs":["http:\/\/www.clearchain.com"]}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/posts\/988","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/comments?post=988"}],"version-history":[{"count":1,"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/posts\/988\/revisions"}],"predecessor-version":[{"id":990,"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/posts\/988\/revisions\/990"}],"wp:attachment":[{"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/media?parent=988"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/categories?post=988"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/tags?post=988"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}