Advertisement
Guest User

SpriteBatch Switching textures

a guest
Oct 27th, 2014
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. /** Flushes the batch. */
  2.     public void flush () {
  3.         flushes++;
  4.         buffer.flip();
  5.         MESH.setVertices(buffer);
  6.         lastTexture.bind();
  7.         MESH.draw();
  8.         buffer.clear();
  9.         RenderUtil.unbindTextures();
  10.     }
  11.  
  12.     /** Begins the SpriteBatch. */
  13.     public void begin () {
  14.         if (rendering) {
  15.             new IllegalStateException("You have to SpriteBatch.end() before calling begin again!").printStackTrace();
  16.         }
  17.         flushes = 0;
  18.         rendering = true;
  19.         shader.bind();
  20.         shader.setUniformMat4f("projection", camera.getCombined());
  21.         shader.setUniformVec4("color", color);
  22.     }
  23.  
  24.     /** Ends the SpriteBatch, also flushes it. */
  25.     public void end () {
  26.         if (!rendering) {
  27.             new IllegalStateException("You've to SpriteBatch.begin before ending the spritebatch").printStackTrace();
  28.         }
  29.         rendering = false;
  30.         flush();
  31.         RenderUtil.unbindShaders();
  32.         RenderUtil.unbindTextures();
  33.     }
  34.  
  35.     /** Switches the textures and flushes the old one.
  36.      * @param t */
  37.     private void switchTextures (Texture t) {
  38.         if (lastTexture != null) {
  39.             flush();
  40.         }
  41.         lastTexture = t;
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement