Skip to content

Commit

Permalink
get max texture size from gl context.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashqal committed Apr 7, 2017
1 parent 8a5f0fa commit e0cd48f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ private void loadImage(Uri uri, final MD360BitmapTexture.Callback callback){
mTarget = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
Log.d(TAG, "loaded image, size:" + bitmap.getWidth() + "," + bitmap.getHeight());

// notify if size changed
getVRLibrary().onTextureResize(bitmap.getWidth(),bitmap.getHeight());
getVRLibrary().onTextureResize(bitmap.getWidth(), bitmap.getHeight());

// texture
callback.texture(bitmap);
Expand All @@ -68,7 +70,14 @@ public void onPrepareLoad(Drawable placeHolderDrawable) {

}
};
Picasso.with(getApplicationContext()).load(uri).resize(3072,2048).centerInside().memoryPolicy(NO_CACHE, NO_STORE).into(mTarget);
Log.d(TAG, "load image with max texture size:" + callback.getMaxTextureSize());
Picasso.with(getApplicationContext())
.load(uri)
.resize(callback.getMaxTextureSize(),callback.getMaxTextureSize())
.onlyScaleDown()
.centerInside()
.memoryPolicy(NO_CACHE, NO_STORE)
.into(mTarget);
}

private Uri currentUri(){
Expand Down
23 changes: 20 additions & 3 deletions vrlib/src/main/java/com/asha/vrlib/texture/MD360BitmapTexture.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public boolean texture(MD360Program program) {
int textureId = getCurrentTextureId();
if (asyncCallback != null && asyncCallback.hasBitmap()){
Bitmap bitmap = asyncCallback.getBitmap();
textureInThread(textureId,program,bitmap);
textureInThread(textureId, program, bitmap);
asyncCallback.releaseBitmap();
mIsReady = true;
}
Expand All @@ -82,8 +82,13 @@ private void loadTexture(){
mTmpAsyncCallback = null;
}

// get texture max size.
int[] maxSize = new int[1];
GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_SIZE, maxSize, 0);

// create a new one
mTmpAsyncCallback = new AsyncCallback();
mTmpAsyncCallback = new AsyncCallback(maxSize[0]);

MDMainHandler.sharedHandler().post(new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -136,14 +141,25 @@ private void textureInThread(int textureId, MD360Program program, Bitmap bitmap)
glCheck("MD360BitmapTexture textureInThread");
}

private static class AsyncCallback implements Callback{
private static class AsyncCallback implements Callback {
private SoftReference<Bitmap> bitmapRef;

private int maxSize;

public AsyncCallback(int maxSize) {
this.maxSize = maxSize;
}

@Override
public void texture(Bitmap bitmap) {
this.bitmapRef = new SoftReference<>(bitmap);
}

@Override
public int getMaxTextureSize() {
return maxSize;
}

public Bitmap getBitmap(){
return bitmapRef != null ? bitmapRef.get() : null;
}
Expand All @@ -162,5 +178,6 @@ public void releaseBitmap(){

public interface Callback {
void texture(Bitmap bitmap);
int getMaxTextureSize();
}
}

0 comments on commit e0cd48f

Please sign in to comment.