Java Code Examples for android.opengl.GLUtils#getInternalFormat()

The following examples show how to use android.opengl.GLUtils#getInternalFormat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UploadedTexture.java    From PhotoMovie with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the content on GPU's memory.
 *
 * @param canvas
 */
public void updateContent(GLESCanvas canvas) {
    if (!isLoaded()) {
        if (mThrottled && ++sUploadedCount > UPLOAD_LIMIT || canvas == null) {
            return;
        }
        uploadToCanvas(canvas);
    } else if (!mContentValid) {
        Bitmap bitmap = getBitmap();
        int format = GLUtils.getInternalFormat(bitmap);
        int type = GLUtils.getType(bitmap);
        canvas.texSubImage2D(this, mBorder, mBorder, bitmap, format, type);
        freeBitmap();
        mContentValid = true;
    }
}
 
Example 2
Source File: UploadedTexture.java    From android-openGL-canvas with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the content on GPU's memory.
 * @param canvas
 */
public void updateContent(GLCanvas canvas) {
    if (!isLoaded()) {
        if (mThrottled && ++sUploadedCount > UPLOAD_LIMIT) {
            return;
        }
        uploadToCanvas(canvas);
    } else if (!mContentValid) {
        Bitmap bitmap = getBitmap();
        int format = GLUtils.getInternalFormat(bitmap);
        int type = GLUtils.getType(bitmap);
        canvas.texSubImage2D(this, mBorder, mBorder, bitmap, format, type);
        freeBitmap();
        mContentValid = true;
    }
}
 
Example 3
Source File: UploadedTexture.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Updates the content on GPU's memory.
 * @param canvas
 */
public void updateContent(GLCanvas canvas) {
    if (!isLoaded()) {
        if (mThrottled && ++sUploadedCount > UPLOAD_LIMIT) {
            return;
        }
        uploadToCanvas(canvas);
    } else if (!mContentValid) {
        Bitmap bitmap = getBitmap();
        int format = GLUtils.getInternalFormat(bitmap);
        int type = GLUtils.getType(bitmap);
        canvas.texSubImage2D(this, mBorder, mBorder, bitmap, format, type);
        freeBitmap();
        mContentValid = true;
    }
}
 
Example 4
Source File: UploadedTexture.java    From TurboLauncher with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the content on GPU's memory.
 * @param canvas
 */
public void updateContent(GLCanvas canvas) {
    if (!isLoaded()) {
        if (mThrottled && ++sUploadedCount > UPLOAD_LIMIT) {
            return;
        }
        uploadToCanvas(canvas);
    } else if (!mContentValid) {
        Bitmap bitmap = getBitmap();
        int format = GLUtils.getInternalFormat(bitmap);
        int type = GLUtils.getType(bitmap);
        canvas.texSubImage2D(this, mBorder, mBorder, bitmap, format, type);
        freeBitmap();
        mContentValid = true;
    }
}
 
Example 5
Source File: AndroidBitmap.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void uploadToTexture(boolean replace) {
    if (mBitmap.isRecycled()) {
        log.error("Attempted to upload recycled bitmap to texture");
        return;
    }
    int format = GLUtils.getInternalFormat(mBitmap);
    int type = GLUtils.getType(mBitmap);

    if (replace)
        GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0,
                mBitmap, format, type);
    else
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, format,
                mBitmap, type, 0);
}
 
Example 6
Source File: UploadedTexture.java    From LB-Launcher with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the content on GPU's memory.
 * @param canvas
 */
public void updateContent(GLCanvas canvas) {
    if (!isLoaded()) {
        if (mThrottled && ++sUploadedCount > UPLOAD_LIMIT) {
            return;
        }
        uploadToCanvas(canvas);
    } else if (!mContentValid) {
        Bitmap bitmap = getBitmap();
        int format = GLUtils.getInternalFormat(bitmap);
        int type = GLUtils.getType(bitmap);
        canvas.texSubImage2D(this, mBorder, mBorder, bitmap, format, type);
        freeBitmap();
        mContentValid = true;
    }
}
 
Example 7
Source File: UploadedTexture.java    From document-viewer with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Updates the content on GPU's memory.
 *
 * @param canvas
 */
public void updateContent(final GLCanvas canvas) {
    if (!isLoaded()) {
        if (mThrottled && ++sUploadedCount > UPLOAD_LIMIT) {
            return;
        }
        uploadToCanvas(canvas);
    } else if (!mContentValid) {
        final Bitmap bitmap = getBitmap();
        final int format = GLUtils.getInternalFormat(bitmap);
        final int type = GLUtils.getType(bitmap);
        canvas.getGLInstance().glBindTexture(GL10.GL_TEXTURE_2D, mId);
        GLUtils.texSubImage2D(GL10.GL_TEXTURE_2D, 0, 0, 0, bitmap, format, type);
        freeBitmap();
        mContentValid = true;
    }
}
 
Example 8
Source File: FileTextureSource.java    From Tanks with MIT License 4 votes vote down vote up
private int loadTexture()
{
  ResultRunnable<Integer> runnable = new ResultRunnable<Integer>()
  {
    @Override
    protected Integer onRun()
    {
      try
      {
        String fileName = getTextureFileName(name);
        InputStream stream = GameContext.context.getAssets().open(fileName);
        Bitmap bitmap = BitmapFactory.decodeStream(stream);
        stream.close();

        int type = GLUtils.getType(bitmap);
        int format = GLUtils.getInternalFormat(bitmap);
        int error;

        int[] textures = new int[1];

        GLES20.glGenTextures(1, textures, 0);
        if ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR)
          throw new GLException(error);

        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
        if ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR)
          throw new GLException(error);

        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
        if ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR)
          throw new GLException(error);

        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, format, bitmap, type, 0);
        if ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR)
          throw new GLException(error);

        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);

        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);

        if (generateMipmap)
        {
          GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
          if ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR)
            throw new GLException(error, Integer.toString(error));
        }

        bitmap.recycle();
        return textures[0];
      }
      catch(Exception e)
      {
        throw new RuntimeException(e);
      }
    }
  };

  GameContext.glThread.sendEvent(runnable);
  return runnable.getResult();
}
 
Example 9
Source File: UploadedTexture.java    From document-viewer with GNU General Public License v3.0 4 votes vote down vote up
private void uploadToCanvas(final GLCanvas canvas) {
    final GL11 gl = canvas.getGLInstance();

    final Bitmap bitmap = getBitmap();
    if (bitmap != null) {
        try {
            final int bWidth = bitmap.getWidth();
            final int bHeight = bitmap.getHeight();
            final int texWidth = getTextureWidth();
            final int texHeight = getTextureHeight();

            // Upload the bitmap to a new texture.
            GLId.glGenTextures(1, sTextureId, 0);
            gl.glBindTexture(GL10.GL_TEXTURE_2D, sTextureId[0]);
            gl.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
            gl.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
            gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
            gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);

            if (bWidth == texWidth && bHeight == texHeight) {
                GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
            } else {
                final int format = GLUtils.getInternalFormat(bitmap);
                final int type = GLUtils.getType(bitmap);

                gl.glTexImage2D(GL10.GL_TEXTURE_2D, 0, format, texWidth, texHeight, 0, format, type, null);
                GLUtils.texSubImage2D(GL10.GL_TEXTURE_2D, 0, 0, 0, bitmap, format, type);
            }
        } finally {
            freeBitmap();
        }
        // Update texture state.
        setAssociatedCanvas(canvas);
        mId = sTextureId[0];
        mState = STATE_LOADED;
        mContentValid = true;
    } else {
        mState = STATE_ERROR;
        throw new RuntimeException("Texture load fail, no bitmap");
    }
}