com.android.grafika.gles.Texture2dProgram Java Examples

The following examples show how to use com.android.grafika.gles.Texture2dProgram. 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: ContinuousCaptureActivity.java    From grafika with Apache License 2.0 6 votes vote down vote up
@Override   // SurfaceHolder.Callback
public void surfaceCreated(SurfaceHolder holder) {
    Log.d(TAG, "surfaceCreated holder=" + holder);

    // Set up everything that requires an EGL context.
    //
    // We had to wait until we had a surface because you can't make an EGL context current
    // without one, and creating a temporary 1x1 pbuffer is a waste of time.
    //
    // The display surface that we use for the SurfaceView, and the encoder surface we
    // use for video, use the same EGL context.
    mEglCore = new EglCore(null, EglCore.FLAG_RECORDABLE);
    mDisplaySurface = new WindowSurface(mEglCore, holder.getSurface(), false);
    mDisplaySurface.makeCurrent();

    mFullFrameBlit = new FullFrameRect(
            new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT));
    mTextureId = mFullFrameBlit.createTextureObject();
    mCameraTexture = new SurfaceTexture(mTextureId);
    mCameraTexture.setOnFrameAvailableListener(this);

    startPreview();
}
 
Example #2
Source File: TextureFromCameraActivity.java    From grafika with Apache License 2.0 6 votes vote down vote up
/**
 * Handles the surface-created callback from SurfaceView.  Prepares GLES and the Surface.
 */
private void surfaceAvailable(SurfaceHolder holder, boolean newSurface) {
    Surface surface = holder.getSurface();
    mWindowSurface = new WindowSurface(mEglCore, surface, false);
    mWindowSurface.makeCurrent();

    // Create and configure the SurfaceTexture, which will receive frames from the
    // camera.  We set the textured rect's program to render from it.
    mTexProgram = new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT);
    int textureId = mTexProgram.createTextureObject();
    mCameraTexture = new SurfaceTexture(textureId);
    mRect.setTexture(textureId);

    if (!newSurface) {
        // This Surface was established on a previous run, so no surfaceChanged()
        // message is forthcoming.  Finish the surface setup now.
        //
        // We could also just call this unconditionally, and perhaps do an unnecessary
        // bit of reallocating if a surface-changed message arrives.
        mWindowSurfaceWidth = mWindowSurface.getWidth();
        mWindowSurfaceHeight = mWindowSurface.getHeight();
        finishSurfaceSetup();
    }

    mCameraTexture.setOnFrameAvailableListener(this);
}
 
Example #3
Source File: RecordFBOActivity.java    From grafika with Apache License 2.0 6 votes vote down vote up
/**
 * Prepares window surface and GL state.
 */
private void prepareGl(Surface surface) {
    Log.d(TAG, "prepareGl");

    mWindowSurface = new WindowSurface(mEglCore, surface, false);
    mWindowSurface.makeCurrent();

    // Used for blitting texture to FBO.
    mFullScreen = new FullFrameRect(
            new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_2D));

    // Program used for drawing onto the screen.
    mProgram = new FlatShadedProgram();

    // Set the background color.
    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

    // Disable depth testing -- we're 2D only.
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);

    // Don't need backface culling.  (If you're feeling pedantic, you can turn it on to
    // make sure we're defining our shapes correctly.)
    GLES20.glDisable(GLES20.GL_CULL_FACE);

    mActivityHandler.sendGlesVersion(mEglCore.getGlVersion());
}
 
Example #4
Source File: HardwareScalerActivity.java    From grafika with Apache License 2.0 6 votes vote down vote up
/**
 * Prepares window surface and GL state.
 */
private void prepareGl(Surface surface) {
    Log.d(TAG, "prepareGl");

    mWindowSurface = new WindowSurface(mEglCore, surface, false);
    mWindowSurface.makeCurrent();

    // Programs used for drawing onto the screen.
    mFlatProgram = new FlatShadedProgram();
    mTexProgram = new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_2D);
    mCoarseTexture = GeneratedTexture.createTestTexture(GeneratedTexture.Image.COARSE);
    mFineTexture = GeneratedTexture.createTestTexture(GeneratedTexture.Image.FINE);

    // Set the background color.
    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

    // Disable depth testing -- we're 2D only.
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);

    // Don't need backface culling.  (If you're feeling pedantic, you can turn it on to
    // make sure we're defining our shapes correctly.)
    GLES20.glDisable(GLES20.GL_CULL_FACE);
}
 
Example #5
Source File: TextureFromCameraActivity.java    From pause-resume-video-recording with Apache License 2.0 6 votes vote down vote up
/**
 * Handles the surface-created callback from SurfaceView.  Prepares GLES and the Surface.
 */
private void surfaceAvailable(SurfaceHolder holder, boolean newSurface) {
    Surface surface = holder.getSurface();
    mWindowSurface = new WindowSurface(mEglCore, surface, false);
    mWindowSurface.makeCurrent();

    // Create and configure the SurfaceTexture, which will receive frames from the
    // camera.  We set the textured rect's program to render from it.
    mTexProgram = new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT);
    int textureId = mTexProgram.createTextureObject();
    mCameraTexture = new SurfaceTexture(textureId);
    mRect.setTexture(textureId);

    if (!newSurface) {
        // This Surface was established on a previous run, so no surfaceChanged()
        // message is forthcoming.  Finish the surface setup now.
        //
        // We could also just call this unconditionally, and perhaps do an unnecessary
        // bit of reallocating if a surface-changed message arrives.
        mWindowSurfaceWidth = mWindowSurface.getWidth();
        mWindowSurfaceHeight = mWindowSurface.getHeight();
        finishSurfaceSetup();
    }

    mCameraTexture.setOnFrameAvailableListener(this);
}
 
Example #6
Source File: RecordFBOActivity.java    From pause-resume-video-recording with Apache License 2.0 6 votes vote down vote up
/**
 * Prepares window surface and GL state.
 */
private void prepareGl(Surface surface) {
    Log.d(TAG, "prepareGl");

    mWindowSurface = new WindowSurface(mEglCore, surface, false);
    mWindowSurface.makeCurrent();

    // Used for blitting texture to FBO.
    mFullScreen = new FullFrameRect(
            new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_2D));

    // Program used for drawing onto the screen.
    mProgram = new FlatShadedProgram();

    // Set the background color.
    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

    // Disable depth testing -- we're 2D only.
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);

    // Don't need backface culling.  (If you're feeling pedantic, you can turn it on to
    // make sure we're defining our shapes correctly.)
    GLES20.glDisable(GLES20.GL_CULL_FACE);

    mActivityHandler.sendGlesVersion(mEglCore.getGlVersion());
}
 
Example #7
Source File: CameraCaptureActivity.java    From pause-resume-video-recording with Apache License 2.0 5 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 unused, EGLConfig config) {
    Log.d(TAG, "onSurfaceCreated");

    // We're starting up or coming back.  Either way we've got a new EGLContext that will
    // need to be shared with the video encoder, so figure out if a recording is already
    // in progress.
    mRecordingEnabled = mVideoEncoder.isRecording();
    if (mRecordingEnabled) {
        mRecordingStatus = RECORDING_RESUMED;
    } else {
        mRecordingStatus = RECORDING_OFF;
    }

    // Set up the texture blitter that will be used for on-screen display.  This
    // is *not* applied to the recording, because that uses a separate shader.
    mFullScreen = new FullFrameRect(
            new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT));

    mTextureId = mFullScreen.createTextureObject();

    // Create a SurfaceTexture, with an external texture, in this EGL context.  We don't
    // have a Looper in this thread -- GLSurfaceView doesn't create one -- so the frame
    // available messages will arrive on the main thread.
    mSurfaceTexture = new SurfaceTexture(mTextureId);

    // Tell the UI thread to enable the camera preview.
    mCameraHandler.sendMessage(mCameraHandler.obtainMessage(
            CameraCaptureActivity.CameraHandler.MSG_SET_SURFACE_TEXTURE, mSurfaceTexture));
}
 
Example #8
Source File: TextureMovieEncoder.java    From grafika with Apache License 2.0 5 votes vote down vote up
private void prepareEncoder(EGLContext sharedContext, int width, int height, int bitRate,
        File outputFile) {
    try {
        mVideoEncoder = new VideoEncoderCore(width, height, bitRate, outputFile);
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
    mEglCore = new EglCore(sharedContext, EglCore.FLAG_RECORDABLE);
    mInputWindowSurface = new WindowSurface(mEglCore, mVideoEncoder.getInputSurface(), true);
    mInputWindowSurface.makeCurrent();

    mFullScreen = new FullFrameRect(
            new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT));
}
 
Example #9
Source File: CameraCaptureActivity.java    From grafika with Apache License 2.0 5 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 unused, EGLConfig config) {
    Log.d(TAG, "onSurfaceCreated");

    // We're starting up or coming back.  Either way we've got a new EGLContext that will
    // need to be shared with the video encoder, so figure out if a recording is already
    // in progress.
    mRecordingEnabled = mVideoEncoder.isRecording();
    if (mRecordingEnabled) {
        mRecordingStatus = RECORDING_RESUMED;
    } else {
        mRecordingStatus = RECORDING_OFF;
    }

    // Set up the texture blitter that will be used for on-screen display.  This
    // is *not* applied to the recording, because that uses a separate shader.
    mFullScreen = new FullFrameRect(
            new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT));

    mTextureId = mFullScreen.createTextureObject();

    // Create a SurfaceTexture, with an external texture, in this EGL context.  We don't
    // have a Looper in this thread -- GLSurfaceView doesn't create one -- so the frame
    // available messages will arrive on the main thread.
    mSurfaceTexture = new SurfaceTexture(mTextureId);

    // Tell the UI thread to enable the camera preview.
    mCameraHandler.sendMessage(mCameraHandler.obtainMessage(
            CameraCaptureActivity.CameraHandler.MSG_SET_SURFACE_TEXTURE, mSurfaceTexture));
}
 
Example #10
Source File: TextureMovieEncoder.java    From pause-resume-video-recording with Apache License 2.0 5 votes vote down vote up
private void prepareEncoder(EGLContext sharedContext, int width, int height, int bitRate,
        File outputFile) {
    try {
        mVideoEncoder = new VideoEncoderCore(width, height, bitRate, outputFile);
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
    mEglCore = new EglCore(sharedContext, EglCore.FLAG_RECORDABLE);
    mInputWindowSurface = new WindowSurface(mEglCore, mVideoEncoder.getInputSurface(), true);
    mInputWindowSurface.makeCurrent();

    mFullScreen = new FullFrameRect(
            new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT));
}
 
Example #11
Source File: Square.java    From IjkVRPlayer with Apache License 2.0 5 votes vote down vote up
/**
 * Changes the program.  The previous program will be released.
 * <p>
 * The appropriate EGL context must be current.
 */
public void changeProgram(Texture2dProgram program, boolean cleanUp) {
    if (mProgram != null && cleanUp) {
        mProgram.release();
    }
    mProgram = program;
}
 
Example #12
Source File: Right.java    From IjkVRPlayer with Apache License 2.0 4 votes vote down vote up
public Right(Texture2dProgram program) {
    super(program);
    Matrix.setIdentityM(mModelMatrix, 0);
    Matrix.scaleM(mModelMatrix, 0, 0.5f, 0.5f, 0.5f);
    Matrix.translateM(mModelMatrix, 0, 1f, 0, 0); // translation to the right
}
 
Example #13
Source File: CameraCaptureActivity.java    From pause-resume-video-recording with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the filter program.
 */
public void updateFilter() {
    Texture2dProgram.ProgramType programType;
    float[] kernel = null;
    float colorAdj = 0.0f;

    Log.d(TAG, "Updating filter to " + mNewFilter);
    switch (mNewFilter) {
        case CameraCaptureActivity.FILTER_NONE:
            programType = Texture2dProgram.ProgramType.TEXTURE_EXT;
            break;
        case CameraCaptureActivity.FILTER_BLACK_WHITE:
            // (In a previous version the TEXTURE_EXT_BW variant was enabled by a flag called
            // ROSE_COLORED_GLASSES, because the shader set the red channel to the B&W color
            // and green/blue to zero.)
            programType = Texture2dProgram.ProgramType.TEXTURE_EXT_BW;
            break;
        case CameraCaptureActivity.FILTER_BLUR:
            programType = Texture2dProgram.ProgramType.TEXTURE_EXT_FILT;
            kernel = new float[] {
                    1f/16f, 2f/16f, 1f/16f,
                    2f/16f, 4f/16f, 2f/16f,
                    1f/16f, 2f/16f, 1f/16f };
            break;
        case CameraCaptureActivity.FILTER_SHARPEN:
            programType = Texture2dProgram.ProgramType.TEXTURE_EXT_FILT;
            kernel = new float[] {
                    0f, -1f, 0f,
                    -1f, 5f, -1f,
                    0f, -1f, 0f };
            break;
        case CameraCaptureActivity.FILTER_EDGE_DETECT:
            programType = Texture2dProgram.ProgramType.TEXTURE_EXT_FILT;
            kernel = new float[] {
                    -1f, -1f, -1f,
                    -1f, 8f, -1f,
                    -1f, -1f, -1f };
            break;
        case CameraCaptureActivity.FILTER_EMBOSS:
            programType = Texture2dProgram.ProgramType.TEXTURE_EXT_FILT;
            kernel = new float[] {
                    2f, 0f, 0f,
                    0f, -1f, 0f,
                    0f, 0f, -1f };
            colorAdj = 0.5f;
            break;
        default:
            throw new RuntimeException("Unknown filter mode " + mNewFilter);
    }

    // Do we need a whole new program?  (We want to avoid doing this if we don't have
    // too -- compiling a program could be expensive.)
    if (programType != mFullScreen.getProgram().getProgramType()) {
        mFullScreen.changeProgram(new Texture2dProgram(programType));
        // If we created a new program, we need to initialize the texture width/height.
        mIncomingSizeUpdated = true;
    }

    // Update the filter kernel (if any).
    if (kernel != null) {
        mFullScreen.getProgram().setKernel(kernel, colorAdj);
    }

    mCurrentFilter = mNewFilter;
}
 
Example #14
Source File: SideBySideFrameRect.java    From IjkVRPlayer with Apache License 2.0 4 votes vote down vote up
@Override
public void changeProgram(Texture2dProgram program) {
    mLeft.changeProgram(program, false);
    mRight.changeProgram(program, false);
    super.changeProgram(program);
}
 
Example #15
Source File: SideBySideFrameRect.java    From IjkVRPlayer with Apache License 2.0 4 votes vote down vote up
public SideBySideFrameRect(Texture2dProgram program) {
    super(program);
    mLeft = new Left(program);
    mRight = new Right(program);
}
 
Example #16
Source File: CameraCaptureActivity.java    From grafika with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the filter program.
 */
public void updateFilter() {
    Texture2dProgram.ProgramType programType;
    float[] kernel = null;
    float colorAdj = 0.0f;

    Log.d(TAG, "Updating filter to " + mNewFilter);
    switch (mNewFilter) {
        case CameraCaptureActivity.FILTER_NONE:
            programType = Texture2dProgram.ProgramType.TEXTURE_EXT;
            break;
        case CameraCaptureActivity.FILTER_BLACK_WHITE:
            // (In a previous version the TEXTURE_EXT_BW variant was enabled by a flag called
            // ROSE_COLORED_GLASSES, because the shader set the red channel to the B&W color
            // and green/blue to zero.)
            programType = Texture2dProgram.ProgramType.TEXTURE_EXT_BW;
            break;
        case CameraCaptureActivity.FILTER_BLUR:
            programType = Texture2dProgram.ProgramType.TEXTURE_EXT_FILT;
            kernel = new float[] {
                    1f/16f, 2f/16f, 1f/16f,
                    2f/16f, 4f/16f, 2f/16f,
                    1f/16f, 2f/16f, 1f/16f };
            break;
        case CameraCaptureActivity.FILTER_SHARPEN:
            programType = Texture2dProgram.ProgramType.TEXTURE_EXT_FILT;
            kernel = new float[] {
                    0f, -1f, 0f,
                    -1f, 5f, -1f,
                    0f, -1f, 0f };
            break;
        case CameraCaptureActivity.FILTER_EDGE_DETECT:
            programType = Texture2dProgram.ProgramType.TEXTURE_EXT_FILT;
            kernel = new float[] {
                    -1f, -1f, -1f,
                    -1f, 8f, -1f,
                    -1f, -1f, -1f };
            break;
        case CameraCaptureActivity.FILTER_EMBOSS:
            programType = Texture2dProgram.ProgramType.TEXTURE_EXT_FILT;
            kernel = new float[] {
                    2f, 0f, 0f,
                    0f, -1f, 0f,
                    0f, 0f, -1f };
            colorAdj = 0.5f;
            break;
        default:
            throw new RuntimeException("Unknown filter mode " + mNewFilter);
    }

    // Do we need a whole new program?  (We want to avoid doing this if we don't have
    // too -- compiling a program could be expensive.)
    if (programType != mFullScreen.getProgram().getProgramType()) {
        mFullScreen.changeProgram(new Texture2dProgram(programType));
        // If we created a new program, we need to initialize the texture width/height.
        mIncomingSizeUpdated = true;
    }

    // Update the filter kernel (if any).
    if (kernel != null) {
        mFullScreen.getProgram().setKernel(kernel, colorAdj);
    }

    mCurrentFilter = mNewFilter;
}
 
Example #17
Source File: Left.java    From IjkVRPlayer with Apache License 2.0 4 votes vote down vote up
public Left(Texture2dProgram program) {
    super(program);
    Matrix.setIdentityM(mModelMatrix, 0);
    Matrix.scaleM(mModelMatrix, 0, 0.5f, 0.5f, 0.5f);
    Matrix.translateM(mModelMatrix, 0, -1f, 0, 0); // translation to the left
}
 
Example #18
Source File: IjkVRRender.java    From IjkVRPlayer with Apache License 2.0 4 votes vote down vote up
@Override
protected FullFrameRect onCreateFrameRect() {
    return new SideBySideFrameRect(new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT));
}
 
Example #19
Source File: GLTextureRender.java    From IjkVRPlayer with Apache License 2.0 4 votes vote down vote up
protected FullFrameRect onCreateFrameRect() {
    return new FullFrameRect(new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT));
}
 
Example #20
Source File: Square.java    From IjkVRPlayer with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the program currently in use.
 */
public Texture2dProgram getProgram() {
    return mProgram;
}
 
Example #21
Source File: Square.java    From IjkVRPlayer with Apache License 2.0 2 votes vote down vote up
/**
 * Prepares the object.
 *
 * @param program The program to use.  FullFrameRect takes ownership, and will release
 *     the program when no longer needed.
 */
public Square(Texture2dProgram program) {
    mProgram = program;
    mRectDrawable = createDrawable2d();
}