content: /*
   * Copyright 2014 Google Inc. All rights reserved.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package com.fadcam.opengl.grafika;
  
  import com.fadcam.opengl.grafika.Texture2dProgram;
  
  import java.nio.FloatBuffer;
  
  /**
   * This class essentially represents a viewport-sized sprite that will be rendered with
   * a texture, usually from an external source like the camera.
   */
  public class FullFrameRect {
      private final Drawable2d mRectDrawable = new Drawable2d(Drawable2d.Prefab.FULL_RECTANGLE);
      private Texture2dProgram mProgram;
  
      /**
       * Prepares the object.
       *
       * @param program The program to use.  FullFrameRect takes ownership, and will release
       *     the program when no longer needed.
       */
      public FullFrameRect(Texture2dProgram program) {
          mProgram = program;
      }
  
      /**
       * Releases resources.
       */
      public void release() {
          if (mProgram != null) {
              mProgram.release();
              mProgram = null;
          }
      }
  
      /**
       * Returns the program currently in use.
       */
      public Texture2dProgram getProgram() {
          return mProgram;
      }
  
      /**
       * Changes the program.  The previous program will be released.
       * <p>
       * The appropriate EGL context must be current.
       */
      public void changeProgram(Texture2dProgram program) {
          mProgram.release();
          mProgram = program;
      }
  
      /**
       * Creates a texture object suitable for use with this program.
       */
      public int createTextureObject() {
          return mProgram.createTextureObject();
      }
  
      /**
       * Draws a viewport-filling rect, texturing it with the specified texture object.
       */
      public void drawFrame(int textureId, float[] texMatrix) {
          // Use the identity matrix for MVP so we only end up with a rectangular
          // shape covering the whole screen.
          mProgram.draw(GlUtil.IDENTITY_MATRIX, mRectDrawable.getVertexArray(), 0,
                  mRectDrawable.getVertexCount(), mRectDrawable.getCoordsPerVertex(),
                  mRectDrawable.getVertexStride(),
                  texMatrix, mRectDrawable.getTexCoordArray(), textureId);
      }
  } 