<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mike</title>
    <description>The latest articles on DEV Community by Mike (@skaterdad).</description>
    <link>https://dev.to/skaterdad</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F48422%2Fefa2f13d-9285-457b-96df-b8793bf9bff1.png</url>
      <title>DEV Community: Mike</title>
      <link>https://dev.to/skaterdad</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/skaterdad"/>
    <language>en</language>
    <item>
      <title>Perf Tip: Put Your Bitmap Fonts in an Atlas!</title>
      <dc:creator>Mike</dc:creator>
      <pubDate>Wed, 04 Mar 2020 18:54:34 +0000</pubDate>
      <link>https://dev.to/skaterdad/perf-tip-put-your-bitmap-fonts-in-an-atlas-3h9o</link>
      <guid>https://dev.to/skaterdad/perf-tip-put-your-bitmap-fonts-in-an-atlas-3h9o</guid>
      <description>&lt;p&gt;Did you know that Bitmap Fonts can be added to the same Texture Atlas as the rest of your UI textures?  I sure didn't.  Read on to see how I measured and optimized my game's UI performance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Outline
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Background info and example from my game&lt;/li&gt;
&lt;li&gt;Packing fonts in your UI Texture Atlas&lt;/li&gt;
&lt;li&gt;LibGDX: Tell your Bitmap Font to use the new Atlas&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Background
&lt;/h3&gt;

&lt;p&gt;In my &lt;a href="https://dev.to/skaterdad/how-to-use-the-libgdx-glprofiler-4dke"&gt;previous post&lt;/a&gt;, we learned about the importance of minimizing texture bindings in OpenGL.  Using Texture Atlases is one of the easiest and most effective ways of optimizing your game rendering.&lt;/p&gt;

&lt;p&gt;The LibGDX Wiki and many tutorials do a great job at recommending and explaining the use of atlases for your game world, but it was not obvious to me that you should also pack your &lt;a href="https://github.com/libgdx/libgdx/wiki/Bitmap-fonts"&gt;Bitmap Fonts&lt;/a&gt; with your UI textures.&lt;/p&gt;

&lt;p&gt;While making &lt;a href="https://skaterdad.dev/games"&gt;Santa Skate&lt;/a&gt;, I used the &lt;a href="https://github.com/libgdx/libgdx/wiki/Hiero"&gt;Hiero&lt;/a&gt; tool to generate the &lt;code&gt;.fnt&lt;/code&gt; and &lt;code&gt;.png&lt;/code&gt; files for my fonts.  I generated four fonts, each of which had a 512x512 texture with mostly empty space.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LpDIlAc3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/uo4to4rfjmxspw3sccve.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LpDIlAc3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/uo4to4rfjmxspw3sccve.PNG" alt="The generated font textures"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What's the problem?
&lt;/h3&gt;

&lt;p&gt;In the screenshot below, there is a typical scene from Santa Skate.  There is a mixture of game world sprites and Scene2D UI elements.  I had already gone through efforts to minimize draw calls/texture bindings on the game world, but I hadn't put much thought into the UI layer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--awXM9ozq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kfrqagcz3dfz3dht6vh3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--awXM9ozq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kfrqagcz3dfz3dht6vh3.png" alt="In-game screenshot. So pretty."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Measure before optimizing
&lt;/h4&gt;

&lt;p&gt;After setting up the GLProfiler, I was surprised to see &lt;strong&gt;13+ texture bindings in the UI layer per frame!&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Why so many texture bindings?
&lt;/h4&gt;

&lt;p&gt;The reason this happens is that the Scene2D Stage draws each Actor in the order they were added to the stage.  Some of those actors need to draw both an image and text, which required multiple texture files in my project.  The progress bar and the lower power-up icons (which render one at a time) are clear examples of this.&lt;/p&gt;

&lt;h4&gt;
  
  
  Packing your fonts?
&lt;/h4&gt;

&lt;p&gt;While searching online for tips on optimizing Scene2D performance, I found some forum posts that mentioned packing your fonts with the rest of the UI graphics.  &lt;a href="http://www.java-gaming.org/index.php?topic=30592.msg282602#msg282602"&gt;This post by 'davedes' on &lt;em&gt;java-gaming.org&lt;/em&gt; was especially useful&lt;/a&gt;.  In hindsight, that tip made perfect sense and I'm a little annoyed that I didn't think of it!&lt;/p&gt;

&lt;p&gt;Following that advice, I packed up all of my UI layer graphics, fonts, and particles into a single texture atlas.&lt;/p&gt;

&lt;h4&gt;
  
  
  The result?
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Only 5 texture bindings/draw calls in the UI layer per frame!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Why not 1 draw call?  My UI uses multiple &lt;code&gt;Group&lt;/code&gt; actors, &lt;a href="https://github.com/libgdx/libgdx/blob/2932c93f5fddfd29dd241fee44282cc9e695ab44/gdx/src/com/badlogic/gdx/scenes/scene2d/Group.java#L204"&gt;which can trigger&lt;/a&gt; &lt;a href="https://github.com/libgdx/libgdx/blob/2932c93f5fddfd29dd241fee44282cc9e695ab44/gdx/src/com/badlogic/gdx/graphics/g2d/SpriteBatch.java#L1053"&gt;SpriteBatch flush() calls&lt;/a&gt; that &lt;a href="https://github.com/libgdx/libgdx/blob/2932c93f5fddfd29dd241fee44282cc9e695ab44/gdx/src/com/badlogic/gdx/graphics/g2d/SpriteBatch.java#L960"&gt;force a texture binding&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Packing fonts in your UI Texture Atlas
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Open your favorite texture packer tool.  I really like &lt;a href="https://github.com/crashinvaders/gdx-texture-packer-gui"&gt;GDX Texture Packer GUI&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;If you have a UI textures project already, open it.  Otherwise, add all of your UI graphics to the list of files to pack.&lt;/li&gt;
&lt;li&gt;Add your bitmap font PNG files to the list!&lt;/li&gt;
&lt;li&gt;Turn on the option "Strip whitespace Y" to get rid of all the empty vertical space in your fonts.&lt;/li&gt;
&lt;li&gt;Configure the other options to your needs.&lt;/li&gt;
&lt;li&gt;Pack it!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uwcwwk2j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/k4co52qd8s39o9f35ysc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uwcwwk2j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/k4co52qd8s39o9f35ysc.png" alt="Packed and efficient."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Tell your Bitmap Font to use the new atlas
&lt;/h3&gt;

&lt;p&gt;When you create Bitmap fonts with tools like Hiero, the &lt;code&gt;.fnt&lt;/code&gt; file references the PNG that was generated with it.  We won't be including those PNG files in our assets anymore, so we need to tell the BitmapFont classes where to find the atlas.&lt;/p&gt;

&lt;p&gt;If you're using an &lt;code&gt;AssetManager&lt;/code&gt; to load your resources, it only takes a couple lines of code to update your fonts to use the Texture Atlas.  Create a &lt;code&gt;BitmapFontParameter&lt;/code&gt; object, and set the &lt;code&gt;atlasName&lt;/code&gt; property to the internal filepath of your texture atlas definition file (normally a &lt;code&gt;.atlas&lt;/code&gt; or &lt;code&gt;.pack&lt;/code&gt; extension).  Pass that parameter as the third argument to the AssetManager &lt;code&gt;load()&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;For my game, this is how I updated all 4 fonts.  No other code changes were required!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;  &lt;span class="c1"&gt;// 1. Create a BitmapFontParameter, pointing to your atlas&lt;/span&gt;
  &lt;span class="nc"&gt;BitmapFontLoader&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;BitmapFontParameter&lt;/span&gt; &lt;span class="n"&gt;fontParameter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BitmapFontLoader&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;BitmapFontParameter&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
  &lt;span class="n"&gt;fontParameter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;atlasName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"ui/gameui.pack"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// 2. Pass that parameter as the third argument to "load"&lt;/span&gt;
  &lt;span class="n"&gt;assetManager&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;load&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"fonts/red32.fnt"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;BitmapFont&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fontParameter&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="n"&gt;assetManager&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;load&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"fonts/red64.fnt"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;BitmapFont&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fontParameter&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="n"&gt;assetManager&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;load&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"fonts/yellow64.fnt"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="nc"&gt;BitmapFont&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fontParameter&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="n"&gt;assetManager&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;load&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"fonts/yellow32.fnt"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="nc"&gt;BitmapFont&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fontParameter&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you are not using &lt;code&gt;AssetManager&lt;/code&gt; and are creating your BitmapFonts manually, you will need to &lt;a href="https://libgdx.badlogicgames.com/ci/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/BitmapFont.html#BitmapFont-com.badlogic.gdx.files.FileHandle-com.badlogic.gdx.graphics.g2d.TextureRegion-"&gt;pass in the TextureRegion to the constructor&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;  &lt;span class="c1"&gt;// This code has not been tested!&lt;/span&gt;
  &lt;span class="c1"&gt;// Consider it inspiration.&lt;/span&gt;

  &lt;span class="nc"&gt;TextureAtlas&lt;/span&gt; &lt;span class="n"&gt;atlas&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TextureAtlas&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Gdx&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;files&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;internal&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"textures/gui.pack"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;

  &lt;span class="nc"&gt;BitmapFont&lt;/span&gt; &lt;span class="n"&gt;font&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BitmapFont&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="nc"&gt;Gdx&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;files&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;internal&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"fonts/yourFont.fnt"&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;atlas&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;findRegion&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"yourFont"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
  &lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>gamedev</category>
      <category>performance</category>
      <category>opengl</category>
      <category>libgdx</category>
    </item>
    <item>
      <title>How To Use The LibGDX GLProfiler</title>
      <dc:creator>Mike</dc:creator>
      <pubDate>Wed, 26 Feb 2020 02:02:21 +0000</pubDate>
      <link>https://dev.to/skaterdad/how-to-use-the-libgdx-glprofiler-4dke</link>
      <guid>https://dev.to/skaterdad/how-to-use-the-libgdx-glprofiler-4dke</guid>
      <description>&lt;p&gt;When optimizing a LibGDX game's performance, sometimes you need to look under the hood.  Let's add the &lt;code&gt;GLProfiler&lt;/code&gt; to a Screen and see how (in)efficiently we're rendering.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why?
&lt;/h3&gt;

&lt;p&gt;In OpenGL, binding textures on the GPU can be an expensive operation.  For each texture switch, there is a draw call.  By minimizing these calls, you can improve rendering performance.&lt;/p&gt;

&lt;p&gt;Thankfully, LibGDX has a built-in class to help us inspect the OpenGL calls: &lt;code&gt;GLProfiler&lt;/code&gt; (&lt;a href="https://libgdx.badlogicgames.com/ci/nightlies/docs/api/com/badlogic/gdx/graphics/profiling/GLProfiler.html"&gt;Docs&lt;/a&gt; | &lt;a href="https://github.com/libgdx/libgdx/wiki/Profiling#opengl"&gt;Wiki&lt;/a&gt;).&lt;/p&gt;

&lt;h3&gt;
  
  
  Profiler Code
&lt;/h3&gt;

&lt;p&gt;Here's the code needed to set up the GLProfiler in a theoretical "GameScreen" and read the number of draw calls and texture bindings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;  &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;com.badlogic.gdx.graphics.profiling.GLProfiler&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;GameScreen&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Screen&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Add this class member&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;GLProfiler&lt;/span&gt; &lt;span class="n"&gt;profiler&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;GameScreen&lt;/span&gt;&lt;span class="o"&gt;(...)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// Your setup code&lt;/span&gt;

      &lt;span class="c1"&gt;// create &amp;amp; enable the profiler&lt;/span&gt;
      &lt;span class="n"&gt;profiler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;GLProfiler&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Gdx&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;graphics&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
      &lt;span class="n"&gt;profiler&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;enable&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;delta&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// reset on each frame&lt;/span&gt;
      &lt;span class="n"&gt;profiler&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;reset&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

      &lt;span class="c1"&gt;// Do all your rendering here&lt;/span&gt;
      &lt;span class="c1"&gt;// ...&lt;/span&gt;

      &lt;span class="c1"&gt;// Check the profiler data.&lt;/span&gt;
      &lt;span class="c1"&gt;// You can view in debugger, log it, etc...&lt;/span&gt;
      &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;drawCalls&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;profiler&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getDrawCalls&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
      &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;textureBinds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;profiler&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getTextureBindings&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

      &lt;span class="c1"&gt;// also handy&lt;/span&gt;
      &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;fps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Gdx&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;graphics&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getFramesPerSecond&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  What should you look for?
&lt;/h3&gt;

&lt;p&gt;Many factors can result in extra draw calls &amp;amp; texture bindings.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Maybe you aren't using &lt;a href="https://github.com/libgdx/libgdx/wiki/Texture-packer#texturepacker"&gt;TextureAtlases&lt;/a&gt;?&lt;/li&gt;
&lt;li&gt;Maybe you are, but there are more than needed?&lt;/li&gt;
&lt;li&gt;Maybe you're rendering things in whatever order was convenient 6 years ago while your baby was sleeping?&lt;/li&gt;
&lt;li&gt;Are you using Scene2D, and did not consider the textures when adding Actors to the Stage?&lt;/li&gt;
&lt;li&gt;Scene2D actors (like TextButton) with BitmapFonts that are not packed with the other UI graphics.&lt;/li&gt;
&lt;li&gt;Gremlins&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;a href="https://github.com/libgdx/libgdx/wiki/Spritebatch,-Textureregions,-and-Sprites"&gt;LibGDX Wiki page on SpriteBatch, TextureRegions, and Sprites&lt;/a&gt; is a great resource to learn more.&lt;/p&gt;

&lt;p&gt;In general, use fewer texture files, and try to render your objects in texture-order as much as possible.&lt;/p&gt;

&lt;h3&gt;
  
  
  Case study coming soon
&lt;/h3&gt;

&lt;p&gt;I recently went through a profiling &amp;amp; optimization effort for &lt;a href="https://skaterdad.dev/games"&gt;Santa Skate&lt;/a&gt;.  Before release, I had not profiled it once!  Performance was still okay, but my engineering brain was not satisfied knowing there were still slowdowns.  In the coming days (weeks), I plan on writing another post explaining how I tamed the texture binds related to Scene2D widgets and the game world. &lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>libgdx</category>
      <category>java</category>
      <category>profiling</category>
    </item>
  </channel>
</rss>
