示例#1
0
  private boolean captureScreenshotTextureAndSetViewport() {
    if (!attachEglContext()) {
      return false;
    }
    try {
      if (!mTexNamesGenerated) {
        GLES10.glGenTextures(1, mTexNames, 0);
        if (checkGlErrors("glGenTextures")) {
          return false;
        }
        mTexNamesGenerated = true;
      }

      final SurfaceTexture st = new SurfaceTexture(mTexNames[0]);
      final Surface s = new Surface(st);
      try {
        SurfaceControl.screenshot(
            SurfaceControl.getBuiltInDisplay(SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN), s);
      } finally {
        s.release();
      }

      st.updateTexImage();
      st.getTransformMatrix(mTexMatrix);

      // Set up texture coordinates for a quad.
      // We might need to change this if the texture ends up being
      // a different size from the display for some reason.
      mTexCoordBuffer.put(0, 0f);
      mTexCoordBuffer.put(1, 0f);
      mTexCoordBuffer.put(2, 0f);
      mTexCoordBuffer.put(3, 1f);
      mTexCoordBuffer.put(4, 1f);
      mTexCoordBuffer.put(5, 1f);
      mTexCoordBuffer.put(6, 1f);
      mTexCoordBuffer.put(7, 0f);

      // Set up our viewport.
      GLES10.glViewport(0, 0, mDisplayWidth, mDisplayHeight);
      GLES10.glMatrixMode(GLES10.GL_PROJECTION);
      GLES10.glLoadIdentity();
      GLES10.glOrthof(0, mDisplayWidth, 0, mDisplayHeight, 0, 1);
      GLES10.glMatrixMode(GLES10.GL_MODELVIEW);
      GLES10.glLoadIdentity();
      GLES10.glMatrixMode(GLES10.GL_TEXTURE);
      GLES10.glLoadIdentity();
      GLES10.glLoadMatrixf(mTexMatrix, 0);
    } finally {
      detachEglContext();
    }
    return true;
  }
  /**
   * Draws an animation frame showing the electron beam activated at the specified level.
   *
   * @param level The electron beam level.
   * @return True if successful.
   */
  public boolean draw(float level) {
    if (DEBUG) {
      Slog.d(TAG, "drawFrame: level=" + level);
    }

    if (!mPrepared) {
      return false;
    }

    if (mMode == MODE_FADE) {
      return showSurface(1.0f - level);
    }

    if (!attachEglContext()) {
      return false;
    }

    try {
      // Clear frame to solid black.
      GLES10.glClearColor(0f, 0f, 0f, 1f);
      GLES10.glClear(GLES10.GL_COLOR_BUFFER_BIT);

      if (mElectronBeamMode == 1 || (mElectronBeamMode == 2 && mIsLandscape)) {
        // Draw the frame vertical.
        if (level < VSTRETCH_DURATION) {
          drawHStretch(1.0f - (level / VSTRETCH_DURATION));
        } else {
          drawVStretch(1.0f - ((level - VSTRETCH_DURATION) / HSTRETCH_DURATION));
        }
      } else {
        // Draw the frame horizontal.
        if (level < HSTRETCH_DURATION) {
          drawHStretch(1.0f - (level / HSTRETCH_DURATION));
        } else {
          drawVStretch(1.0f - ((level - HSTRETCH_DURATION) / VSTRETCH_DURATION));
        }
      }

      if (checkGlErrors("drawFrame")) {
        return false;
      }

      EGL14.eglSwapBuffers(mEglDisplay, mEglSurface);
    } finally {
      detachEglContext();
    }
    return showSurface(1.0f);
  }
示例#3
0
 private static boolean checkGlErrors(String func, boolean log) {
   boolean hadError = false;
   int error;
   while ((error = GLES10.glGetError()) != GLES10.GL_NO_ERROR) {
     if (log) {
       Slog.e(TAG, func + " failed: error " + error, new Throwable());
     }
     hadError = true;
   }
   return hadError;
 }
示例#4
0
  // 存在第二次拿拿不到的情况,所以把拿到的数据用一个static变量保存下来
  public static int getTextureSize() {
    if (textureSize > 0) {
      return textureSize;
    }

    int[] params = new int[1];
    GLES10.glGetIntegerv(GLES10.GL_MAX_TEXTURE_SIZE, params, 0);
    textureSize = params[0];

    return textureSize;
  }
示例#5
0
  /**
   * Draws a frame where the electron beam has been stretched out into a thin white horizontal line
   * that fades as it collapses inwards.
   *
   * @param stretch The stretch factor. 0.0 is maximum stretch / no fade, 1.0 is collapsed / maximum
   *     fade.
   */
  private void drawHStretch(float stretch) {
    // compute interpolation scale factor
    final float ag = scurve(stretch, 8.0f);
    if (DEBUG) {
      Slog.d(TAG, "drawHStretch: stretch=" + stretch + ", ag=" + ag);
    }

    if (stretch < 1.0f) {
      // bind vertex buffer
      GLES10.glVertexPointer(2, GLES10.GL_FLOAT, 0, mVertexBuffer);
      GLES10.glEnableClientState(GLES10.GL_VERTEX_ARRAY);

      // draw narrow fading white line
      setHStretchQuad(mVertexBuffer, mDisplayWidth, mDisplayHeight, ag, mSwapNeeded);
      GLES10.glColor4f(1.0f - ag * 0.75f, 1.0f - ag * 0.75f, 1.0f - ag * 0.75f, 1.0f);
      GLES10.glDrawArrays(GLES10.GL_TRIANGLE_FAN, 0, 4);

      // clean up
      GLES10.glDisableClientState(GLES10.GL_VERTEX_ARRAY);
    }
  }
示例#6
0
 private void destroyScreenshotTexture() {
   if (mTexNamesGenerated) {
     mTexNamesGenerated = false;
     if (attachEglContext()) {
       try {
         GLES10.glDeleteTextures(1, mTexNames, 0);
         checkGlErrors("glDeleteTextures");
       } finally {
         detachEglContext();
       }
     }
   }
 }
示例#7
0
 @Override
 protected void onDraw(Canvas canvas) {
   // TODO Auto-generated method stub
   if (mMaxSize == 0) {
     int[] maxTextureSize = new int[1];
     GLES10.glGetIntegerv(GLES10.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0);
     mMaxSize = maxTextureSize[0];
     if (mListener != null) {
       mListener.OnMaxSizeChange();
     }
   }
   super.onDraw(canvas);
 }
示例#8
0
 void SetTextureEnvMODE(float value) {
   // void glTexEnv{if}(GLenum target, GLenum pname, TYPEparam);
   // void glTexEnv{if}v(GLenum target, GLenum pname, TYPE *param);
   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   // Sets the current texturing function. target must be GL_TEXTURE_ENV. If pname is
   // GL_TEXTURE_ENV_MODE, param can be
   // GL_DECAL, GL_REPLACE, GL_MODULATE, or GL_BLEND, to specify how texture values are to be
   // combined with the color
   // values of the fragment being processed. If pname is GL_TEXTURE_ENV_COLOR, param is an array
   // of four floating-point values
   // representing R, G, B, and A components. These values are used only if the GL_BLEND texture
   // function has been specified
   // as well.
   // static void	 glTexEnvf(int target, int pname, float param)
   GLES10.glTexEnvf(GLES10.GL_TEXTURE_ENV, GLES10.GL_TEXTURE_ENV_MODE, value);
 }
示例#9
0
  public static int getSupportedMaxPictureSize() {
    int[] array = new int[1];
    GLES10.glGetIntegerv(GLES10.GL_MAX_TEXTURE_SIZE, array, 0);

    try {
      if (array[0] == 0) {
        GLES11.glGetIntegerv(GLES11.GL_MAX_TEXTURE_SIZE, array, 0);

        if (array[0] == 0) {
          GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_SIZE, array, 0);

          if (array[0] == 0) {
            GLES30.glGetIntegerv(GLES30.GL_MAX_TEXTURE_SIZE, array, 0);
          }
        }
      }
    } catch (NoClassDefFoundError e) {
      // Ignore the exception
    }

    return array[0] != 0 ? array[0] : 2048;
  }
  /**
   * Init CameraManager gl texture id, camera SurfaceTexture, bind to EXTERNAL_OES, and redirect
   * camera preview to the surfaceTexture.
   *
   * @throws IOException when camera cannot be open
   */
  private void initCameraSurface() throws IOException {

    // Gen openGL texture id
    int texture[] = new int[1];
    GLES10.glGenTextures(1, texture, 0);
    mCameraTextureId = texture[0];

    if (mCameraTextureId == 0) {
      throw new RuntimeException("Cannot create openGL texture (initCameraSurface())");
    }

    // Camera preview is redirected to SurfaceTexture.
    // SurfaceTexture works with TEXTURE_EXTERNAL_OES, so we bind this textureId so that camera
    // will automatically fill it with its video.
    GLES10.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mCameraTextureId);

    // Can't do mipmapping with camera source
    GLES10.glTexParameterf(
        GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES10.GL_TEXTURE_MIN_FILTER, GLES10.GL_LINEAR);
    GLES10.glTexParameterf(
        GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES10.GL_TEXTURE_MAG_FILTER, GLES10.GL_LINEAR);

    // Clamp to edge is the only option
    GLES10.glTexParameterf(
        GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES10.GL_TEXTURE_WRAP_S, GLES10.GL_CLAMP_TO_EDGE);
    GLES10.glTexParameterf(
        GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES10.GL_TEXTURE_WRAP_T, GLES10.GL_CLAMP_TO_EDGE);

    // create a SurfaceTexture associated to this openGL texture...
    mCameraSurfaceTex = new SurfaceTexture(mCameraTextureId);
    mCameraSurfaceTex.setDefaultBufferSize(640, 480);

    // ... and redirect camera preview to it
    mCameraManager.setPreviewSurface(mCameraSurfaceTex);

    // Setup viewfinder
    mViewFinder = new TexturedPlane(mViewFinderSize);
    mViewFinder.setTexture(
        BitmapDecoder.safeDecodeBitmap(mContext.getResources(), VIEWFINDER_RESSOURCE_ID));
    mViewFinder.recycleTexture();
    mViewFinder.translate(0, 0, VIEWFINDER_DISTANCE);
    mViewFinder.setAlpha(VIEWFINDER_ATTENUATION_ALPHA);
  }
示例#11
0
  /**
   * Draws a frame where the content of the electron beam is collapsing inwards upon itself
   * vertically with red / green / blue channels dispersing and eventually merging down to a single
   * horizontal line.
   *
   * @param stretch The stretch factor. 0.0 is no collapse, 1.0 is full collapse.
   */
  private void drawVStretch(float stretch) {
    // compute interpolation scale factors for each color channel
    final float ar = scurve(stretch, 7.5f);
    final float ag = scurve(stretch, 8.0f);
    final float ab = scurve(stretch, 8.5f);
    if (DEBUG) {
      Slog.d(TAG, "drawVStretch: stretch=" + stretch + ", ar=" + ar + ", ag=" + ag + ", ab=" + ab);
    }

    // set blending
    GLES10.glBlendFunc(GLES10.GL_ONE, GLES10.GL_ONE);
    GLES10.glEnable(GLES10.GL_BLEND);

    // bind vertex buffer
    GLES10.glVertexPointer(2, GLES10.GL_FLOAT, 0, mVertexBuffer);
    GLES10.glEnableClientState(GLES10.GL_VERTEX_ARRAY);

    // set-up texturing
    GLES10.glDisable(GLES10.GL_TEXTURE_2D);
    GLES10.glEnable(GLES11Ext.GL_TEXTURE_EXTERNAL_OES);

    // bind texture and set blending for drawing planes
    GLES10.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTexNames[0]);
    GLES10.glTexEnvx(
        GLES10.GL_TEXTURE_ENV,
        GLES10.GL_TEXTURE_ENV_MODE,
        mMode == MODE_WARM_UP ? GLES10.GL_MODULATE : GLES10.GL_REPLACE);
    GLES10.glTexParameterx(
        GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES10.GL_TEXTURE_MAG_FILTER, GLES10.GL_LINEAR);
    GLES10.glTexParameterx(
        GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES10.GL_TEXTURE_MIN_FILTER, GLES10.GL_LINEAR);
    GLES10.glTexParameterx(
        GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES10.GL_TEXTURE_WRAP_S, GLES10.GL_CLAMP_TO_EDGE);
    GLES10.glTexParameterx(
        GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES10.GL_TEXTURE_WRAP_T, GLES10.GL_CLAMP_TO_EDGE);
    GLES10.glEnable(GLES11Ext.GL_TEXTURE_EXTERNAL_OES);
    GLES10.glTexCoordPointer(2, GLES10.GL_FLOAT, 0, mTexCoordBuffer);
    GLES10.glEnableClientState(GLES10.GL_TEXTURE_COORD_ARRAY);

    // draw the red plane
    setVStretchQuad(mVertexBuffer, mDisplayWidth, mDisplayHeight, ar, mSwapNeeded);
    GLES10.glColorMask(true, false, false, true);
    GLES10.glDrawArrays(GLES10.GL_TRIANGLE_FAN, 0, 4);

    // draw the green plane
    setVStretchQuad(mVertexBuffer, mDisplayWidth, mDisplayHeight, ag, mSwapNeeded);
    GLES10.glColorMask(false, true, false, true);
    GLES10.glDrawArrays(GLES10.GL_TRIANGLE_FAN, 0, 4);

    // draw the blue plane
    setVStretchQuad(mVertexBuffer, mDisplayWidth, mDisplayHeight, ab, mSwapNeeded);
    GLES10.glColorMask(false, false, true, true);
    GLES10.glDrawArrays(GLES10.GL_TRIANGLE_FAN, 0, 4);

    // clean up after drawing planes
    GLES10.glDisable(GLES11Ext.GL_TEXTURE_EXTERNAL_OES);
    GLES10.glDisableClientState(GLES10.GL_TEXTURE_COORD_ARRAY);
    GLES10.glColorMask(true, true, true, true);

    // draw the white highlight (we use the last vertices)
    if (mMode == MODE_COOL_DOWN) {
      GLES10.glColor4f(ag, ag, ag, 1.0f);
      GLES10.glDrawArrays(GLES10.GL_TRIANGLE_FAN, 0, 4);
    }

    // clean up
    GLES10.glDisableClientState(GLES10.GL_VERTEX_ARRAY);
    GLES10.glDisable(GLES10.GL_BLEND);
  }
示例#12
0
 private int getMaxTextureSize() {
   // The OpenGL texture size is the maximum size that can be drawn in an ImageView
   int[] maxSize = new int[1];
   GLES10.glGetIntegerv(GLES10.GL_MAX_TEXTURE_SIZE, maxSize, 0);
   return maxSize[0];
 }
示例#13
0
 public void preRender() {
   super.preRender();
   setDrawingMode(GLES20.GL_POINTS);
   GLES10.glPointSize(5.0f);
 }