@SuppressLint("NewApi")
  @Override
  public void onSurfaceCreated(GL10 unused, EGLConfig config) {
    Logging.d(TAG, "VideoRendererGui.onSurfaceCreated");
    // Store render EGL context.
    if (CURRENT_SDK_VERSION >= EGL14_SDK_VERSION) {
      synchronized (VideoRendererGui.class) {
        eglContext = EGL14.eglGetCurrentContext();
        Logging.d(TAG, "VideoRendererGui EGL Context: " + eglContext);
      }
    }

    synchronized (yuvImageRenderers) {
      // Create drawer for YUV/OES frames.
      drawer = new GlRectDrawer();
      // Create textures for all images.
      for (YuvImageRenderer yuvImageRenderer : yuvImageRenderers) {
        yuvImageRenderer.createTextures();
      }
      onSurfaceCreatedCalled = true;
    }
    GlUtil.checkNoGLES2Error("onSurfaceCreated done");
    GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
    GLES20.glClearColor(0.15f, 0.15f, 0.15f, 1.0f);

    // Fire EGL context ready event.
    synchronized (VideoRendererGui.class) {
      if (eglContextReady != null) {
        eglContextReady.run();
      }
    }
  }
Exemple #2
0
  public Texture(Context context, int idpicture) {

    int[] names = new int[1];
    GLES20.glGenTextures(1, names, 0);
    name = names[0];
    GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, name);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), idpicture);
    GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
    bitmap.recycle();
    GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
  }
  public Texture loadSingleTexture(int resId, int slotId, int compression) {

    int[] texturesId = new int[1];

    GLES20.glGenTextures(texturesId.length, texturesId, 0);

    GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);

    Texture mTexture = new Texture(compression, texturesId[0], slotId, resId);
    mTexture.load(context);
    textures.add(mTexture);

    return mTexture;
  }
  public Texture loadCubeMapTexture(
      int front, int left, int back, int right, int up, int down, int slotId, int compression) {

    int[] texturesId = new int[1];

    GLES20.glGenTextures(texturesId.length, texturesId, 0);

    GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);

    Texture mTexture =
        new Texture(compression, texturesId[0], slotId, front, left, back, right, up, down);
    mTexture.load(context);
    textures.add(mTexture);

    return mTexture;
  }
Exemple #5
0
 @Override
 public void glPixelStorei(int pname, int param) {
   GLES20.glPixelStorei(pname, param);
 }
  /**
   * @param pGLState
   * @throws IOException
   */
  @Override
  protected void writeTextureToHardware(final GLState pGLState) throws IOException {
    final IPVRTexturePixelBufferStrategyBufferManager pvrTextureLoadStrategyManager =
        this.mPVRTexturePixelBufferStrategy.newPVRTexturePixelBufferStrategyManager(this);

    int width = this.getWidth();
    int height = this.getHeight();

    final int dataLength = this.mPVRTextureHeader.getDataLength();

    final int bytesPerPixel =
        this.mPVRTextureHeader.getBitsPerPixel() / DataConstants.BITS_PER_BYTE;

    final boolean useDefaultAlignment =
        MathUtils.isPowerOfTwo(width)
            && MathUtils.isPowerOfTwo(height)
            && this.mPVRTextureHeader.mPVRTextureFormat == PVRTextureFormat.RGBA_8888;
    if (!useDefaultAlignment) {
      /* Adjust unpack alignment. */
      GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
    }

    int currentLevel = 0;
    int currentPixelDataOffset = 0;
    while (currentPixelDataOffset < dataLength) {
      if (currentLevel > 0 && (width != height || MathUtils.nextPowerOfTwo(width) != width)) {
        Debug.w(
            "Mipmap level '"
                + currentLevel
                + "' is not squared. Width: '"
                + width
                + "', height: '"
                + height
                + "'. Texture won't render correctly.");
      }

      final int currentPixelDataSize = height * width * bytesPerPixel;

      /* Load the current level. */
      this.mPVRTexturePixelBufferStrategy.loadPVRTextureData(
          pvrTextureLoadStrategyManager,
          width,
          height,
          bytesPerPixel,
          this.mPixelFormat,
          currentLevel,
          currentPixelDataOffset,
          currentPixelDataSize);

      currentPixelDataOffset += currentPixelDataSize;

      /* Prepare next mipmap level. */
      width = Math.max(width / 2, 1);
      height = Math.max(height / 2, 1);

      currentLevel++;
    }

    if (!useDefaultAlignment) {
      /* Restore default unpack alignment. */
      GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, GLState.GL_UNPACK_ALIGNMENT_DEFAULT);
    }
  }
  @Override
  protected void writeTextureToHardware(final GLState pGLState) {
    final PixelFormat pixelFormat = this.mBitmapTextureFormat.getPixelFormat();
    final int glInternalFormat = pixelFormat.getGLInternalFormat();
    final int glFormat = pixelFormat.getGLFormat();
    final int glType = pixelFormat.getGLType();

    GLES20.glTexImage2D(
        GLES20.GL_TEXTURE_2D,
        0,
        glInternalFormat,
        this.mWidth,
        this.mHeight,
        0,
        glFormat,
        glType,
        null);

    final boolean preMultipyAlpha = this.mTextureOptions.mPreMultiplyAlpha;
    /* Non alpha premultiplied bitmaps are loaded with ARGB_8888 and converted down manually. */
    final Config bitmapConfig =
        (preMultipyAlpha) ? this.mBitmapTextureFormat.getBitmapConfig() : Config.ARGB_8888;

    final ArrayList<IBitmapTextureAtlasSource> textureSources = this.mTextureAtlasSources;
    final int textureSourceCount = textureSources.size();

    final ITextureAtlasStateListener<IBitmapTextureAtlasSource> textureStateListener =
        this.getTextureAtlasStateListener();
    for (int i = 0; i < textureSourceCount; i++) {
      final IBitmapTextureAtlasSource bitmapTextureAtlasSource = textureSources.get(i);
      try {
        final Bitmap bitmap = bitmapTextureAtlasSource.onLoadBitmap(bitmapConfig);
        if (bitmap == null) {
          throw new NullBitmapException(
              "Caused by: "
                  + bitmapTextureAtlasSource.getClass().toString()
                  + " --> "
                  + bitmapTextureAtlasSource.toString()
                  + " returned a null Bitmap.");
        }

        final boolean useDefaultAlignment =
            MathUtils.isPowerOfTwo(bitmap.getWidth())
                && MathUtils.isPowerOfTwo(bitmap.getHeight())
                && pixelFormat == PixelFormat.RGBA_8888;
        if (!useDefaultAlignment) {
          /* Adjust unpack alignment. */
          GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
        }

        if (preMultipyAlpha) {
          GLUtils.texSubImage2D(
              GLES20.GL_TEXTURE_2D,
              0,
              bitmapTextureAtlasSource.getTextureX(),
              bitmapTextureAtlasSource.getTextureY(),
              bitmap,
              glFormat,
              glType);
        } else {
          pGLState.glTexSubImage2D(
              GLES20.GL_TEXTURE_2D,
              0,
              bitmapTextureAtlasSource.getTextureX(),
              bitmapTextureAtlasSource.getTextureY(),
              bitmap,
              this.mPixelFormat);
        }

        if (!useDefaultAlignment) {
          /* Restore default unpack alignment. */
          GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, GLState.GL_UNPACK_ALIGNMENT_DEFAULT);
        }

        bitmap.recycle();

        if (textureStateListener != null) {
          textureStateListener.onTextureAtlasSourceLoaded(this, bitmapTextureAtlasSource);
        }
      } catch (final NullBitmapException e) {
        if (textureStateListener != null) {
          textureStateListener.onTextureAtlasSourceLoadExeption(this, bitmapTextureAtlasSource, e);
        } else {
          throw e;
        }
      }
    }
  }
Exemple #8
0
 @Override
 public void pixelStorei(final int pname, final int param) {
   checkOpenGLThread();
   GLES20.glPixelStorei(pname, param);
 }