예제 #1
0
  private void loadShaders() {
    if (phenixLineProgram != null && postProgram != null) {
      return;
    }

    try {
      ShaderManager shaderManager = ShaderManager.getSingletonObject();
      Shader vertex =
          shaderManager.createVertexShader(
              ResourceHelper.loadRawString(openResource(R.raw.phenix_line_vertex)));
      Shader fragment =
          shaderManager.createFragmentShader(
              ResourceHelper.loadRawString(openResource(R.raw.phenix_line_fragment)));
      phenixLineProgram = shaderManager.createShaderProgram(vertex, fragment);

      vertex =
          shaderManager.createVertexShader(
              ResourceHelper.loadRawString(openResource(R.raw.post_blur_vertex)));
      fragment =
          shaderManager.createFragmentShader(
              ResourceHelper.loadRawString(openResource(R.raw.post_blur_fragment)));
      postProgram = shaderManager.createShaderProgram(vertex, fragment);
    } catch (Exception ex) {
      Log.e(TAG, "Unable to load shaders from resources " + ex.toString());
    }
  }
예제 #2
0
  @Override
  public void onSurfaceChanged(GL10 unused, int width, int height) {
    ShaderManager.getSingletonObject().cleanUp();

    GLES20.glViewport(0, 0, width, height);
    float scale = 0.1f;
    float ratio = scale * width / height;
    Matrix.frustumM(P_matrix, 0, -ratio, ratio, -scale, scale, 0.1f, 100.0f);

    surfaceWidth = width;
    surfaceHeight = height;

    if (!useNonPowerOfTwoTextures_) {
      // lets make framebuffer have power of 2 dimension
      // and it should be less then display size
      frameBufferWidth = 1 << (int) (Math.log(width) / Math.log(2));
      if (frameBufferWidth == surfaceWidth) frameBufferWidth >>= 1;
      frameBufferHeight = 1 << (int) (Math.log(height) / Math.log(2));
      if (frameBufferHeight == surfaceHeight) frameBufferHeight >>= 1;
    } else {
      frameBufferWidth = surfaceWidth;
      frameBufferHeight = surfaceHeight;
    }

    if (!useNonSquareTextures_) {
      // http://code.google.com/p/android/issues/detail?id=14835
      // The size of the FBO should have square size.
      if (frameBufferHeight > frameBufferWidth) {
        frameBufferWidth = frameBufferHeight;
      } else if (frameBufferWidth > frameBufferHeight) {
        frameBufferHeight = frameBufferWidth;
      }
    }

    if (useSmallerTextures_) {
      frameBufferWidth >>= 1;
      frameBufferHeight >>= 1;
    }

    Log.i(
        "BL***",
        "frameBufferWidth=" + frameBufferWidth + " frameBufferHeight=" + frameBufferHeight);

    for (int i = 0; i < renderTextures.length; ++i) {
      if (renderTextures[i] != null) {
        renderTextures[i].update(frameBufferWidth, frameBufferHeight);
      }
    }

    resetFramebuffers = true;
  }
예제 #3
0
  @Override
  public void onSurfaceCreated(GL10 unused, EGLConfig config) {
    ShaderManager.getSingletonObject().unloadAll();
    ShaderManager.getSingletonObject().cleanUp();

    TextureManager.getSingletonObject().unloadAll();
    TextureManager.getSingletonObject().cleanUp();

    loadResources();

    if (phenixLineProgram != null) {
      phenixLineProgram.load();
    }

    ShaderManager.getSingletonObject().unloadAllShaders();

    renderTextures = new RenderTexture[2];
    frameBuffers = new FrameBuffer[2];

    setupFrameBuffer(unused);

    Matrix.setLookAtM(V_matrix, 0, 0, 0, 1.0f, 0f, 0f, 0f, 0f, -1.0f, 0.0f);
    Matrix.orthoM(Q_matrix, 0, 0, 1, 0, 1, -1, 1);
  }