Java Code Examples for android.opengl.GLES20#glScissor()

The following examples show how to use android.opengl.GLES20#glScissor() . 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: ScheduledSwapActivity.java    From grafika with Apache License 2.0 6 votes vote down vote up
/**
 * Draws the scene.
 */
private void draw() {
    GlUtil.checkGlError("draw start");

    GLES20.glClearColor(0f, 0f, 0f, 1f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
    GLES20.glScissor(mPosition, mHeight * 2 / 8, mBlockWidth, mHeight / 8);
    GLES20.glClearColor(1f, 1f * (mDroppedFrames & 0x01),
            1f * (mChoreographerSkips & 0x01), 1f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glDisable(GLES20.GL_SCISSOR_TEST);

    GlUtil.checkGlError("draw done");
}
 
Example 2
Source File: MovieEightRects.java    From pause-resume-video-recording with Apache License 2.0 6 votes vote down vote up
/**
 * Generates a frame of data using GL commands.  We have an 8-frame animation
 * sequence that wraps around.  It looks like this:
 * <pre>
 *   0 1 2 3
 *   7 6 5 4
 * </pre>
 * We draw one of the eight rectangles and leave the rest set to the clear color.
 */
private void generateFrame(int frameIndex) {
    frameIndex %= 8;

    int startX, startY;
    if (frameIndex < 4) {
        // (0,0) is bottom-left in GL
        startX = frameIndex * (WIDTH / 4);
        startY = HEIGHT / 2;
    } else {
        startX = (7 - frameIndex) * (WIDTH / 4);
        startY = 0;
    }

    GLES20.glClearColor(TEST_R0 / 255.0f, TEST_G0 / 255.0f, TEST_B0 / 255.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
    GLES20.glScissor(startX, startY, WIDTH / 4, HEIGHT / 2);
    GLES20.glClearColor(TEST_R1 / 255.0f, TEST_G1 / 255.0f, TEST_B1 / 255.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
}
 
Example 3
Source File: MDBarrelDistortionLinePipe.java    From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void commit(int totalWidth, int totalHeight, int size){
    if (!mEnabled){
        return;
    }
    mDrawingCache.unbind();

    int width = totalWidth / size;
    for (int i = 0; i < size; i++){
        GLES20.glViewport(width * i, 0, width, totalHeight);
        GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
        GLES20.glScissor(width * i, 0, width, totalHeight);
        draw(i);
        GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
    }
}
 
Example 4
Source File: MovieEightRects.java    From grafika with Apache License 2.0 6 votes vote down vote up
/**
 * Generates a frame of data using GL commands.  We have an 8-frame animation
 * sequence that wraps around.  It looks like this:
 * <pre>
 *   0 1 2 3
 *   7 6 5 4
 * </pre>
 * We draw one of the eight rectangles and leave the rest set to the clear color.
 */
private void generateFrame(int frameIndex) {
    frameIndex %= 8;

    int startX, startY;
    if (frameIndex < 4) {
        // (0,0) is bottom-left in GL
        startX = frameIndex * (WIDTH / 4);
        startY = HEIGHT / 2;
    } else {
        startX = (7 - frameIndex) * (WIDTH / 4);
        startY = 0;
    }

    GLES20.glClearColor(TEST_R0 / 255.0f, TEST_G0 / 255.0f, TEST_B0 / 255.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
    GLES20.glScissor(startX, startY, WIDTH / 4, HEIGHT / 2);
    GLES20.glClearColor(TEST_R1 / 255.0f, TEST_G1 / 255.0f, TEST_B1 / 255.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
}
 
Example 5
Source File: DecodeEditEncodeTest.java    From Android-MediaCodec-Examples with Apache License 2.0 6 votes vote down vote up
/**
 * Generates a frame of data using GL commands.
 * <p>
 * We have an 8-frame animation sequence that wraps around.  It looks like this:
 * <pre>
 *   0 1 2 3
 *   7 6 5 4
 * </pre>
 * We draw one of the eight rectangles and leave the rest set to the zero-fill color.     */
private void generateSurfaceFrame(int frameIndex) {
    frameIndex %= 8;
    int startX, startY;
    if (frameIndex < 4) {
        // (0,0) is bottom-left in GL
        startX = frameIndex * (mWidth / 4);
        startY = mHeight / 2;
    } else {
        startX = (7 - frameIndex) * (mWidth / 4);
        startY = 0;
    }
    GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
    GLES20.glClearColor(TEST_R0 / 255.0f, TEST_G0 / 255.0f, TEST_B0 / 255.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
    GLES20.glScissor(startX, startY, mWidth / 4, mHeight / 2);
    GLES20.glClearColor(TEST_R1 / 255.0f, TEST_G1 / 255.0f, TEST_B1 / 255.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
}
 
Example 6
Source File: EncodeAndMuxTest.java    From Android-MediaCodec-Examples with Apache License 2.0 6 votes vote down vote up
/**
 * Generates a frame of data using GL commands.  We have an 8-frame animation
 * sequence that wraps around.  It looks like this:
 * <pre>
 *   0 1 2 3
 *   7 6 5 4
 * </pre>
 * We draw one of the eight rectangles and leave the rest set to the clear color.
 */
private void generateSurfaceFrame(int frameIndex) {
    frameIndex %= 8;

    int startX, startY;
    if (frameIndex < 4) {
        // (0,0) is bottom-left in GL
        startX = frameIndex * (mWidth / 4);
        startY = mHeight / 2;
    } else {
        startX = (7 - frameIndex) * (mWidth / 4);
        startY = 0;
    }

    GLES20.glClearColor(TEST_R0 / 255.0f, TEST_G0 / 255.0f, TEST_B0 / 255.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
    GLES20.glScissor(startX, startY, mWidth / 4, mHeight / 2);
    GLES20.glClearColor(TEST_R1 / 255.0f, TEST_G1 / 255.0f, TEST_B1 / 255.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
}
 
Example 7
Source File: MDBarrelDistortionLinePipe.java    From MD360Player4Android with Apache License 2.0 6 votes vote down vote up
@Override
public void commit(int totalWidth, int totalHeight, int size){
    if (!mEnabled){
        return;
    }
    mDrawingCache.unbind();

    int width = totalWidth / size;
    for (int i = 0; i < size; i++){
        GLES20.glViewport(width * i, 0, width, totalHeight);
        GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
        GLES20.glScissor(width * i, 0, width, totalHeight);
        draw(i);
        GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
    }
}
 
Example 8
Source File: EncodeAndMuxTest.java    From AndroidPlayground with MIT License 6 votes vote down vote up
/**
 * Generates a frame of data using GL commands.  We have an 8-frame animation
 * sequence that wraps around.  It looks like this:
 * <pre>
 *   0 1 2 3
 *   7 6 5 4
 * </pre>
 * We draw one of the eight rectangles and leave the rest set to the clear color.
 */
private void generateSurfaceFrame(int frameIndex) {
    frameIndex %= 8;

    int startX, startY;
    if (frameIndex < 4) {
        // (0,0) is bottom-left in GL
        startX = frameIndex * (mWidth / 4);
        startY = mHeight / 2;
    } else {
        startX = (7 - frameIndex) * (mWidth / 4);
        startY = 0;
    }

    GLES20.glClearColor(TEST_R0 / 255.0f, TEST_G0 / 255.0f, TEST_B0 / 255.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
    GLES20.glScissor(startX, startY, mWidth / 4, mHeight / 2);
    GLES20.glClearColor(TEST_R1 / 255.0f, TEST_G1 / 255.0f, TEST_B1 / 255.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
}
 
Example 9
Source File: CameraSurfaceRenderer.java    From AndroidPlayground with MIT License 5 votes vote down vote up
/**
 * Draws a red box in the corner.
 */
private void drawBox() {
    GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
    GLES20.glScissor(0, 0, 100, 100);
    GLES20.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
}
 
Example 10
Source File: CameraCaptureActivity.java    From pause-resume-video-recording with Apache License 2.0 5 votes vote down vote up
/**
 * Draws a red box in the corner.
 */
private void drawBox() {
    GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
    GLES20.glScissor(0, 0, 100, 100);
    GLES20.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
}
 
Example 11
Source File: TextureMovieEncoder.java    From AndroidPlayground with MIT License 5 votes vote down vote up
/**
 * Draws a box, with position offset.
 */
private void drawBox(int posn) {
    final int width = mInputWindowSurface.getWidth();
    int xpos = (posn * 4) % (width - 50);
    GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
    GLES20.glScissor(xpos, 0, 100, 100);
    GLES20.glClearColor(1.0f, 0.0f, 1.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
}
 
Example 12
Source File: GLScissorStack.java    From tilt-game-android with MIT License 5 votes vote down vote up
public void glPopScissor() {
	if (this.mScissorStackOffset - GLScissorStack.GLSCISSOR_SIZE <= GLScissorStack.GLSCISSORSTACKOFFSET_UNDERFLOW) {
		throw new GLScissorStackUnderflowException();
	}

	this.mScissorStackOffset -= GLScissorStack.GLSCISSOR_SIZE;

	final int x = this.mScissorStack[this.mScissorStackOffset + GLSCISSOR_X_INDEX];
	final int y = this.mScissorStack[this.mScissorStackOffset + GLSCISSOR_Y_INDEX];
	final int width = this.mScissorStack[this.mScissorStackOffset + GLSCISSOR_WIDTH_INDEX];
	final int height = this.mScissorStack[this.mScissorStackOffset + GLSCISSOR_HEIGHT_INDEX];

	GLES20.glScissor(x, y, width, height);
}
 
Example 13
Source File: DoubleSceneSplitScreenEngine.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
protected void onDrawScene(final GLState pGLState, final Camera pFirstCamera) {
	final Camera secondCamera = this.getSecondCamera();

	final int surfaceWidth = this.mSurfaceWidth;
	final int surfaceWidthHalf = surfaceWidth >> 1;

	final int surfaceHeight = this.mSurfaceHeight;

	pGLState.enableScissorTest();

	/* First Screen. With first camera, on the left half of the screens width. */
	if (super.mScene != null) {
		GLES20.glScissor(0, 0, surfaceWidthHalf, surfaceHeight);
		GLES20.glViewport(0, 0, surfaceWidthHalf, surfaceHeight);

		super.mScene.onDraw(pGLState, pFirstCamera);
		pFirstCamera.onDrawHUD(pGLState);
	}

	/* Second Screen. With second camera, on the right half of the screens width. */
	if (this.mSecondScene != null) {
		GLES20.glScissor(surfaceWidthHalf, 0, surfaceWidthHalf, surfaceHeight);
		GLES20.glViewport(surfaceWidthHalf, 0, surfaceWidthHalf, surfaceHeight);

		this.mSecondScene.onDraw(pGLState, secondCamera);
		secondCamera.onDrawHUD(pGLState);
	}

	pGLState.disableScissorTest();
}
 
Example 14
Source File: SingleSceneSplitScreenEngine.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
protected void onDrawScene(final GLState pGLState, final Camera pFirstCamera) {
	if (super.mScene != null) {
		final Camera secondCamera = this.getSecondCamera();

		final int surfaceWidth = this.mSurfaceWidth;
		final int surfaceWidthHalf = surfaceWidth >> 1;

		final int surfaceHeight = this.mSurfaceHeight;

		pGLState.enableScissorTest();

		/* First Screen. With first camera, on the left half of the screens width. */
		{
			GLES20.glScissor(0, 0, surfaceWidthHalf, surfaceHeight);
			GLES20.glViewport(0, 0, surfaceWidthHalf, surfaceHeight);

			super.mScene.onDraw(pGLState, pFirstCamera);
			pFirstCamera.onDrawHUD(pGLState);
		}

		/* Second Screen. With second camera, on the right half of the screens width. */
		{
			GLES20.glScissor(surfaceWidthHalf, 0, surfaceWidthHalf, surfaceHeight);
			GLES20.glViewport(surfaceWidthHalf, 0, surfaceWidthHalf, surfaceHeight);

			super.mScene.onDraw(pGLState, secondCamera);
			secondCamera.onDrawHUD(pGLState);
		}

		pGLState.disableScissorTest();
	}
}
 
Example 15
Source File: TextureMovieEncoder.java    From LiveVideoBroadcaster with Apache License 2.0 5 votes vote down vote up
/**
 * Draws a box, with position offset.
 */
private void drawBox(int posn) {
    final int width = mInputWindowSurface.getWidth();
    int xpos = (posn * 4) % (width - 50);
    GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
    GLES20.glScissor(xpos, 0, 100, 100);
    GLES20.glClearColor(1.0f, 0.0f, 1.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
}
 
Example 16
Source File: CameraSurfaceRenderer.java    From LiveVideoBroadcaster with Apache License 2.0 5 votes vote down vote up
/**
 * Draws a red box in the corner.
 */
private void drawBox() {
    GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
    GLES20.glScissor(0, 0, 100, 100);
    GLES20.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
}
 
Example 17
Source File: CameraCaptureActivity.java    From grafika with Apache License 2.0 5 votes vote down vote up
/**
 * Draws a red box in the corner.
 */
private void drawBox() {
    GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
    GLES20.glScissor(0, 0, 100, 100);
    GLES20.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
}
 
Example 18
Source File: MultiSurfaceActivity.java    From grafika with Apache License 2.0 4 votes vote down vote up
/**
 * Clears the surface, then draws some alpha-blended rectangles with GL.
 * <p>
 * Creates a temporary EGL context just for the duration of the call.
 */
private void drawRectSurface(Surface surface, int left, int top, int width, int height) {
    EglCore eglCore = new EglCore();
    WindowSurface win = new WindowSurface(eglCore, surface, false);
    win.makeCurrent();
    GLES20.glClearColor(0, 0, 0, 0);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
    for (int i = 0; i < 4; i++) {
        int x, y, w, h;
        if (width < height) {
            // vertical
            w = width / 4;
            h = height;
            x = left + w * i;
            y = top;
        } else {
            // horizontal
            w = width;
            h = height / 4;
            x = left;
            y = top + h * i;
        }
        GLES20.glScissor(x, y, w, h);
        switch (i) {
            case 0:     // 50% blue at 25% alpha, pre-multiplied
                GLES20.glClearColor(0.0f, 0.0f, 0.125f, 0.25f);
                break;
            case 1:     // 100% blue at 25% alpha, pre-multiplied
                GLES20.glClearColor(0.0f, 0.0f, 0.25f, 0.25f);
                break;
            case 2:     // 200% blue at 25% alpha, pre-multiplied (should get clipped)
                GLES20.glClearColor(0.0f, 0.0f, 0.5f, 0.25f);
                break;
            case 3:     // 100% white at 25% alpha, pre-multiplied
                GLES20.glClearColor(0.25f, 0.25f, 0.25f, 0.25f);
                break;
        }
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    }
    GLES20.glDisable(GLES20.GL_SCISSOR_TEST);

    win.swapBuffers();
    win.release();
    eglCore.release();
}
 
Example 19
Source File: GLScissorStack.java    From tilt-game-android with MIT License 4 votes vote down vote up
public void glPushScissor(final int pX, final int pY, final int pWidth, final int pHeight) {
	if (this.mScissorStackOffset + GLScissorStack.GLSCISSOR_SIZE >= GLScissorStack.GLSCISSORSTACKOFFSET_OVERFLOW) {
		throw new GLScissorStackOverflowException();
	}

	final int x;
	final int y;
	final int width;
	final int height;
	if (this.mScissorStackOffset == 0) {
		x = pX;
		y = pY;
		width = pWidth;
		height = pHeight;
	} else {
		/* Take the intersection between the current and the new scissor: */
		final int currentX = this.mScissorStack[this.mScissorStackOffset - (GLSCISSOR_SIZE - GLSCISSOR_X_INDEX)];
		final int currentY = this.mScissorStack[this.mScissorStackOffset - (GLSCISSOR_SIZE - GLSCISSOR_Y_INDEX)];
		final int currentWidth = this.mScissorStack[this.mScissorStackOffset - (GLSCISSOR_SIZE - GLSCISSOR_WIDTH_INDEX)];
		final int currentHeight = this.mScissorStack[this.mScissorStackOffset - (GLSCISSOR_SIZE - GLSCISSOR_HEIGHT_INDEX)];

		final float xMin = Math.max(currentX, pX);
		final float xMax = Math.min(currentX + currentWidth, pX + pWidth);

		final float yMin = Math.max(currentY, pY);
		final float yMax = Math.min(currentY + currentHeight, pY + pHeight);

		x = (int) xMin;
		y = (int) yMin;
		width = (int) (xMax - xMin);
		height = (int) (yMax - yMin);
	}

	this.mScissorStack[this.mScissorStackOffset + GLSCISSOR_X_INDEX] = pX;
	this.mScissorStack[this.mScissorStackOffset + GLSCISSOR_Y_INDEX] = pY;
	this.mScissorStack[this.mScissorStackOffset + GLSCISSOR_WIDTH_INDEX] = pWidth;
	this.mScissorStack[this.mScissorStackOffset + GLSCISSOR_HEIGHT_INDEX] = pHeight;

	GLES20.glScissor(x, y, width, height);

	this.mScissorStackOffset += GLScissorStack.GLSCISSOR_SIZE;
}
 
Example 20
Source File: AndroidGL.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void scissor(int x, int y, int width, int height) {
    GLES20.glScissor(x, y, width, height);
}