title: Android: performance issue multiple textures Opengl ES
body: <p>The game I made in android is based on a canvas, and for performance reason I am to lift this game to OpenGL ES instead. </p>
  
  <p>The problem is still performance - I have a background and a sprite bouncing around the screen - this works very well but it seem to be the same performance issue as with using a Canvas. Now and then the sprite animation are not perfectly smooth. I guess my design is bad or really bad. </p>
  
  <p>Is it wrong to call texImage2D for every frame? What are the alternatives to this? </p>
  
  <p>Thanks!!!</p>
  
  <pre><code> @Override
  public void onDrawFrame(GL10 unused) {
  
      GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
  
      long speedFactor = 5000;
      long time = SystemClock.uptimeMillis() % speedFactor;
      float angleInDegrees = (360.0f / speedFactor) * ((int) time);
  
      GLES20.glUseProgram(mProgramHandle);
  
      mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_MVPMatrix");
      mMVMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_MVMatrix");
      mColorHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Color");
      mNormalHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Normal");
      mTextureCoordinateHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_TexCoordinate");
  
      GLES20.glEnable(GLES20.GL_BLEND);
      GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA);
  
  
      //BACKGROUND
      GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, background, 0);
      //GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, background);
      Matrix.setIdentityM(mModelMatrix, 0);
      Matrix.translateM(mModelMatrix, 0, 0, 0.0f, -2.00001f);
      drawTriangle(mCubePositions);
  
  
  
      // THE MOVING SPRITE.
      int rest = 0;
      if (modulo &gt; 0) {
          rest = frameCntr % modulo;
      }
  
      GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, alien[bitmapIndex], 0);
      //GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, alien[bitmapIndex]);
      if (rest == 0) {
          bitmapIndex++;
      }
  
      if (bitmapIndex == alien.length) {
          bitmapIndex = 0;
      }
  
      frameCntr++;
  
      float deltaX = (motion.get_velocityX() * motion.get_xDirection());
      float deltaY = (motion.get_velocityY() * motion.get_yDirection());
      anim_x += deltaX;
      anim_y += deltaY;
  
      Matrix.setIdentityM(mModelMatrix, 0);
      Matrix.translateM(mModelMatrix, 0, anim_x, anim_y, -7f);
      //Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
      drawTriangle(mAlienPositions);
      calcPos();
      collision.collisionWalls(motion, xPos, yPos, game_width, game_height);
  }
  </code></pre>