Skip to content

Commit 39d41cf

Browse files
committed
Fix viewport w and h error.
1 parent 8b5c297 commit 39d41cf

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

canvasgl/src/main/java/com/chillingvan/canvasgl/ICanvasGL.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
import android.graphics.SurfaceTexture;
2727
import android.opengl.GLES20;
2828
import android.opengl.Matrix;
29-
import androidx.annotation.IntRange;
30-
import androidx.annotation.NonNull;
31-
import androidx.annotation.Nullable;
3229

3330
import com.chillingvan.canvasgl.glcanvas.BasicTexture;
3431
import com.chillingvan.canvasgl.glcanvas.BitmapTexture;
@@ -40,6 +37,10 @@
4037
import com.chillingvan.canvasgl.matrix.IBitmapMatrix;
4138
import com.chillingvan.canvasgl.textureFilter.TextureFilter;
4239

40+
import androidx.annotation.IntRange;
41+
import androidx.annotation.NonNull;
42+
import androidx.annotation.Nullable;
43+
4344
/**
4445
* Created by Matthew on 2016/9/26.
4546
*/
@@ -197,7 +198,7 @@ public float[] obtainResultMatrix(int viewportW, int viewportH, float x, float y
197198
final float absTransY = Math.abs(transform[TRANSLATE_Y]); // Make sure realViewportH - viewportY includes viewportH
198199
int realViewportW = (int) (viewPortRatio * viewportW + 2*absTransX);
199200
int realViewportH = (int) (viewPortRatio * viewportH + 2*absTransY);
200-
realViewportW = Math.max(realViewportW, maxViewPortInt);
201+
realViewportW = Math.min(realViewportW, maxViewPortInt);
201202
realViewportH = Math.min(realViewportH, maxViewPortInt);
202203
int viewportX = (int) (drawW / 2 - realViewportW / 2 + transform[TRANSLATE_X]);
203204
int viewportY = (int) (-drawH / 2 - transform[TRANSLATE_Y] - realViewportH / 2 + viewportH);

canvasgl/src/main/java/com/chillingvan/canvasgl/glcanvas/GLES20Canvas.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,11 +555,11 @@ private void draw(ShaderParameter[] params, int type, int count, float x, float
555555

556556
private void setMatrix(ShaderParameter[] params, float x, float y, float width, float height, ICustomMVPMatrix customMVPMatrix) {
557557
if (customMVPMatrix != null) {
558-
GLES20.glUniformMatrix4fv(params[INDEX_MATRIX].handle, 1, false, customMVPMatrix.getMVPMatrix(mScreenWidth, mScreenHeight, x, y, width, height), 0);
558+
GLES20.glUniformMatrix4fv(params[INDEX_MATRIX].handle, 1, false, customMVPMatrix.getMVPMatrix(mWidth, mHeight, x, y, width, height), 0);
559559
checkError();
560560
return;
561561
}
562-
GLES20.glViewport(0, 0, mScreenWidth, mScreenHeight);
562+
GLES20.glViewport(0, 0, mWidth, mHeight);
563563
Matrix.translateM(mTempMatrix, 0, mMatrices, mCurrentMatrixIndex, x, y, 0f);
564564
Matrix.scaleM(mTempMatrix, 0, width, height, 1f);
565565
Matrix.multiplyMM(mTempMatrix, MATRIX_SIZE, mProjectionMatrix, 0, mTempMatrix, 0);

0 commit comments

Comments
 (0)