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

The following examples show how to use android.opengl.GLES20#glGetIntegerv() . 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: MD360BitmapTexture.java    From MD360Player4Android with Apache License 2.0 6 votes vote down vote up
private void loadTexture(){
    // release the ref before
    if (mTmpAsyncCallback != null){
        mTmpAsyncCallback.releaseBitmap();
        mTmpAsyncCallback = null;
    }

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

    final AsyncCallback finalCallback = new AsyncCallback(maxSize[0]);

    // create a new one
    mTmpAsyncCallback = finalCallback;

    MDMainHandler.sharedHandler().post(new Runnable() {
        @Override
        public void run() {
            mBitmapProvider.onProvideBitmap(finalCallback);
        }
    });
}
 
Example 2
Source File: MediaVideoEncoder.java    From PLDroidShortVideo with Apache License 2.0 6 votes vote down vote up
public boolean frameAvailableSoon(int texId, final float[] texMatrix, float[] mvpMatrix) {
    GLES20.glGetIntegerv(GLES20.GL_VIEWPORT, mViewPort, 0);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFBOId[0]);
    GLES20.glViewport(0, 0, mWidth, mHeight);
    program.drawFrame(texId, texMatrix, mvpMatrix);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    GLES20.glViewport(mViewPort[0], mViewPort[1], mViewPort[2], mViewPort[3]);
    // 先绘制三次,不进行编码,解决黑屏问题
    if (mFrameCount++ < 3) {
        return true;
    }
    boolean result;
    if (result = super.frameAvailableSoon()) {
        mRenderHandler.draw(mTextureId[0], GlUtil.IDENTITY_MATRIX, mvpMatrix);
    }
    return result;
}
 
Example 3
Source File: YuvOutputFilter.java    From AAVT with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(int texture) {
    onTaskExec();
    boolean isBlend= GLES20.glIsEnabled(GLES20.GL_BLEND);
    GLES20.glDisable(GLES20.GL_BLEND);
    GLES20.glGetIntegerv(GLES20.GL_VIEWPORT,lastViewPort,0);
    GLES20.glViewport(0,0,mWidth,mHeight);
    if(mScaleFilter!=null){
        mExportFilter.draw(mScaleFilter.drawToTexture(texture));
    }else{
        mExportFilter.draw(texture);
    }
    GLES20.glReadPixels(0,0,mWidth,mHeight*3/8,GLES20.GL_RGBA,GLES20.GL_UNSIGNED_BYTE,mTempBuffer);
    GLES20.glViewport(lastViewPort[0],lastViewPort[1],lastViewPort[2],lastViewPort[3]);
    if(isBlend){
        GLES20.glEnable(GLES20.GL_BLEND);
    }
}
 
Example 4
Source File: BaseMovieFilter.java    From PhotoMovie with Apache License 2.0 6 votes vote down vote up
@Override
public void doFilter(PhotoMovie photoMovie, int elapsedTime, FboTexture inputTexture, FboTexture outputTexture) {
    textureRect.set(0, 0, inputTexture.getTextureWidth(), inputTexture.getTextureHeight());
    dstRect.set(0, 0, outputTexture.getWidth(), outputTexture.getHeight());
    if (!mIsInitialized) {
        setViewport(0, 0, outputTexture.getWidth(), outputTexture.getHeight());
        init();
    }
    int[] curFb = new int[1];
    GLES20.glGetIntegerv(GLES20.GL_FRAMEBUFFER_BINDING, curFb, 0);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, outputTexture.getFrameBuffer());
    GlUtil.checkGlError("glBindFramebuffer");
    drawFrame(photoMovie,
            elapsedTime,
            inputTexture);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, curFb[0]);
    GlUtil.checkGlError("glBindFramebuffer");
}
 
Example 5
Source File: RenderTexture.java    From tilt-game-android with MIT License 5 votes vote down vote up
protected void savePreviousViewport() {
	GLES20.glGetIntegerv(GLES20.GL_VIEWPORT, RenderTexture.VIEWPORT_CONTAINER, 0);

	this.mPreviousViewPortX = RenderTexture.VIEWPORT_CONTAINER[RenderTexture.VIEWPORT_CONTAINER_X_INDEX];
	this.mPreviousViewPortY = RenderTexture.VIEWPORT_CONTAINER[RenderTexture.VIEWPORT_CONTAINER_Y_INDEX];
	this.mPreviousViewPortWidth = RenderTexture.VIEWPORT_CONTAINER[RenderTexture.VIEWPORT_CONTAINER_WIDTH_INDEX];
	this.mPreviousViewPortHeight = RenderTexture.VIEWPORT_CONTAINER[RenderTexture.VIEWPORT_CONTAINER_HEIGHT_INDEX];
}
 
Example 6
Source File: GLHelper.java    From libcommon with Apache License 2.0 5 votes vote down vote up
/**
 * テクスチャ名配列を生成(前から順にGL_TEXTURE0, GL_TEXTURE1, ...)
 * @param texIds テクスチャ名配列, 最大で32個(GL_MAX_TEXTURE_IMAGE_UNITS以下)
 * @param texTarget テクスチャのタイプ, GL_TEXTURE_EXTERNAL_OESかGL_TEXTURE_2D
 * @param minFilter テクスチャの補間方法を指定, GL_LINEARとかGL_NEAREST
 * @param magFilter テクスチャの補間方法を指定, GL_LINEARとかGL_NEAREST
 * @param wrap テクスチャのクランプ方法, GL_CLAMP_TO_EDGE等
 * @return
 */
public static int[] initTexes(@NonNull final int[] texIds,
	final int texTarget, final int minFilter, final int magFilter, final int wrap) {

	int[] textureUnits = new int[1];
	GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_IMAGE_UNITS, textureUnits, 0);
	Log.v(TAG, "GL_MAX_TEXTURE_IMAGE_UNITS=" + textureUnits[0]);
	final int n = texIds.length > textureUnits[0]
		? textureUnits[0] : texIds.length;
	for (int i = 0; i < n; i++) {
		texIds[i] = GLHelper.initTex(texTarget, ShaderConst.TEX_NUMBERS_ES2[i],
			minFilter, magFilter, wrap);
	}
	return texIds;
}
 
Example 7
Source File: FrameBuffer.java    From AAVT with Apache License 2.0 5 votes vote down vote up
/**
 * 绑定FrameBuffer,只有之前创建过FrameBuffer,才能调用此方法进行绑定
 * @return 绑定结果
 */
public int bindFrameBuffer(){
    if(mFrameTemp==null){
        return -1;
    }
    GLES20.glGetIntegerv(GLES20.GL_FRAMEBUFFER_BINDING,mFrameTemp,3);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER,mFrameTemp[0]);
    return GLES20.glGetError();
}
 
Example 8
Source File: FrameBufferObjectRenderer.java    From SimpleVideoEdit with Apache License 2.0 5 votes vote down vote up
public void onSurfaceCreated() {
    // Set the background frame color, these params are red, green, blue and alpha
    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

    final int[] args = new int[1];

    GLES20.glGenTextures(args.length, args, 0);
    texName = args[0];

    GLES20.glBindTexture(GlPreviewFilter.GL_TEXTURE_EXTERNAL_OES, texName);
    // GL_TEXTURE_EXTERNAL_OES
    EglUtil.setupSampler(GlPreviewFilter.GL_TEXTURE_EXTERNAL_OES, GL_LINEAR, GL_NEAREST);
    GLES20.glBindTexture(GL_TEXTURE_2D, 0);

    filterFramebufferObject = new EFramebufferObject();
    // GL_TEXTURE_EXTERNAL_OES
    previewFilter = new GlPreviewFilter(GlPreviewFilter.GL_TEXTURE_EXTERNAL_OES);
    //initialize shapes
    previewFilter.setup();

    /*
    * Projection and camera view in OpenGL ES 2.0: Second Step:
    * First Step is in GlPreviewFilter.java where we declare the vertex shader with uMVPMatrix
    * Create a camera view matrix
    * */
    Matrix.setLookAtM(VMatrix, 0,
            0.0f, 0.0f, 5.0f,
            0.0f, 0.0f, 0.0f,
            0.0f, 1.0f, 0.0f
    );

    if (glFilter != null) {
        isNewFilter = true;
    }

    GLES20.glGetIntegerv(GL_MAX_TEXTURE_SIZE, args, 0);
}
 
Example 9
Source File: Program.java    From PLDroidShortVideo with Apache License 2.0 5 votes vote down vote up
public void drawFrame(int textureId, float[] texMatrix, float[] mvpMatrix, int x, int y, int width, int height) {
    int[] originalViewport = new int[4];
    GLES20.glGetIntegerv(GLES20.GL_VIEWPORT, originalViewport, 0);
    GLES20.glViewport(x, y, width, height);
    drawFrame(textureId, texMatrix, mvpMatrix);
    GLES20.glViewport(originalViewport[0], originalViewport[1], originalViewport[2], originalViewport[3]);
}
 
Example 10
Source File: FrameBuffer.java    From AAVT with Apache License 2.0 5 votes vote down vote up
/**
 * 创建FrameBuffer
 * @param hasRenderBuffer 是否启用RenderBuffer
 * @param width 宽度
 * @param height 高度
 * @param texType 类型,一般为{@link GLES20#GL_TEXTURE_2D}
 * @param texFormat 纹理格式,一般为{@link GLES20#GL_RGBA}、{@link GLES20#GL_RGB}等
 * @param minParams 纹理的缩小过滤参数
 * @param maxParams 纹理的放大过滤参数
 * @param wrapS 纹理的S环绕参数
 * @param wrapT 纹理的W环绕参数
 * @return 创建结果,0表示成功,其他值为GL错误
 */
public int createFrameBuffer(boolean hasRenderBuffer,int width,int height,int texType,int texFormat,
                             int minParams,int maxParams,int wrapS,int wrapT){
    mFrameTemp=new int[4];
    GLES20.glGenFramebuffers(1,mFrameTemp,0);
    GLES20.glGenTextures(1,mFrameTemp,1);
    GLES20.glBindTexture(texType,mFrameTemp[1]);
    GLES20.glTexImage2D(texType, 0,texFormat, width, height,
            0, texFormat, GLES20.GL_UNSIGNED_BYTE, null);
    //设置缩小过滤为使用纹理中坐标最接近的一个像素的颜色作为需要绘制的像素颜色
    GLES20.glTexParameteri(texType, GLES20.GL_TEXTURE_MIN_FILTER,minParams);
    //设置放大过滤为使用纹理中坐标最接近的若干个颜色,通过加权平均算法得到需要绘制的像素颜色
    GLES20.glTexParameteri(texType, GLES20.GL_TEXTURE_MAG_FILTER,maxParams);
    //设置环绕方向S,截取纹理坐标到[1/2n,1-1/2n]。将导致永远不会与border融合
    GLES20.glTexParameteri(texType, GLES20.GL_TEXTURE_WRAP_S,wrapS);
    //设置环绕方向T,截取纹理坐标到[1/2n,1-1/2n]。将导致永远不会与border融合
    GLES20.glTexParameteri(texType, GLES20.GL_TEXTURE_WRAP_T,wrapT);

    GLES20.glGetIntegerv(GLES20.GL_FRAMEBUFFER_BINDING,mFrameTemp,3);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER,mFrameTemp[0]);
    GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0,
            texType, mFrameTemp[1], 0);
    if(hasRenderBuffer){
        GLES20.glGenRenderbuffers(1,mFrameTemp,2);
        GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER,mFrameTemp[2]);
        GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER,GLES20.GL_DEPTH_COMPONENT16,width,height);
        GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER,GLES20.GL_DEPTH_ATTACHMENT,GLES20.GL_RENDERBUFFER,mFrameTemp[2]);
    }
    return GLES20.glGetError();
}
 
Example 11
Source File: FrameBufferFactory.java    From HokoBlur with Apache License 2.0 4 votes vote down vote up
public static IFrameBuffer getDisplayFrameBuffer() {
    // Get the bound FBO (On Screen)
    final int[] displayFbo = new int[1];
    GLES20.glGetIntegerv(GLES20.GL_FRAMEBUFFER_BINDING, displayFbo, 0);
    return create(displayFbo[0]);
}
 
Example 12
Source File: GLMovieRenderer.java    From PhotoMovie with Apache License 2.0 4 votes vote down vote up
@Override
public void drawMovieFrame(int elapsedTime) {
    synchronized (mPrepareLock) {
        mPrepared = true;
        if (mOnGLPrepareListener != null) {
            final OnGLPrepareListener listener = mOnGLPrepareListener;
            mOnGLPrepareListener = null;
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    listener.onGLPrepared();
                }
            });
        }
    }
    if(mReleaseMovieSegments!=null){
        releaseSegments(mReleaseMovieSegments);
        mReleaseMovieSegments = null;
    }
    if (mMovieFilter == null) {
        super.drawMovieFrame(elapsedTime);
        return;
    }

    if (mFboTexture == null || mFilterTexture == null) {
        initTexture(mViewportRect.width(), mViewportRect.height());
    }
    int[] curFb = new int[1];
    GLES20.glGetIntegerv(GLES20.GL_FRAMEBUFFER_BINDING, curFb, 0);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFboTexture.getFrameBuffer());
    super.drawMovieFrame(elapsedTime);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, curFb[0]);

    mPainter.unbindArrayBuffer();
    synchronized (mSetFilterLock) {
        if (mMovieFilter != null) {
            mMovieFilter.doFilter(mPhotoMovie, elapsedTime, mFboTexture, mFilterTexture);
        }
    }
    mPainter.rebindArrayBuffer();

    mPainter.drawTexture(mFilterTexture, 0, 0, mViewportRect.width(), mViewportRect.height());
}
 
Example 13
Source File: GlFramebufferObject.java    From Mp4Composer-android with MIT License 4 votes vote down vote up
public void setup(final int width, final int height) {
    final int[] args = new int[1];

    GLES20.glGetIntegerv(GL_MAX_TEXTURE_SIZE, args, 0);
    if (width > args[0] || height > args[0]) {
        throw new IllegalArgumentException("GL_MAX_TEXTURE_SIZE " + args[0]);
    }

    GLES20.glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, args, 0);
    if (width > args[0] || height > args[0]) {
        throw new IllegalArgumentException("GL_MAX_RENDERBUFFER_SIZE " + args[0]);
    }

    GLES20.glGetIntegerv(GL_FRAMEBUFFER_BINDING, args, 0);
    final int saveFramebuffer = args[0];
    GLES20.glGetIntegerv(GL_RENDERBUFFER_BINDING, args, 0);
    final int saveRenderbuffer = args[0];
    GLES20.glGetIntegerv(GL_TEXTURE_BINDING_2D, args, 0);
    final int saveTexName = args[0];

    release();

    try {
        this.width = width;
        this.height = height;

        GLES20.glGenFramebuffers(args.length, args, 0);
        framebufferName = args[0];
        GLES20.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName);

        GLES20.glGenRenderbuffers(args.length, args, 0);
        renderBufferName = args[0];
        GLES20.glBindRenderbuffer(GL_RENDERBUFFER, renderBufferName);
        GLES20.glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
        GLES20.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderBufferName);

        GLES20.glGenTextures(args.length, args, 0);
        texName = args[0];
        GLES20.glBindTexture(GL_TEXTURE_2D, texName);

        EglUtil.setupSampler(GL_TEXTURE_2D, GL_LINEAR, GL_NEAREST);

        GLES20.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, null);
        GLES20.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texName, 0);

        final int status = GLES20.glCheckFramebufferStatus(GL_FRAMEBUFFER);
        if (status != GL_FRAMEBUFFER_COMPLETE) {
            throw new RuntimeException("Failed to initialize framebuffer object " + status);
        }
    } catch (final RuntimeException e) {
        release();
        throw e;
    }

    GLES20.glBindFramebuffer(GL_FRAMEBUFFER, saveFramebuffer);
    GLES20.glBindRenderbuffer(GL_RENDERBUFFER, saveRenderbuffer);
    GLES20.glBindTexture(GL_TEXTURE_2D, saveTexName);
}
 
Example 14
Source File: EglUtils.java    From PictureSelector with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static int getMaxTextureEgl14() {
    EGLDisplay dpy = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
    int[] vers = new int[2];
    EGL14.eglInitialize(dpy, vers, 0, vers, 1);

    int[] configAttr = {
            EGL14.EGL_COLOR_BUFFER_TYPE, EGL14.EGL_RGB_BUFFER,
            EGL14.EGL_LEVEL, 0,
            EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT,
            EGL14.EGL_SURFACE_TYPE, EGL14.EGL_PBUFFER_BIT,
            EGL14.EGL_NONE
    };
    EGLConfig[] configs = new EGLConfig[1];
    int[] numConfig = new int[1];
    EGL14.eglChooseConfig(dpy, configAttr, 0,
            configs, 0, 1, numConfig, 0);
    if (numConfig[0] == 0) {
        return 0;
    }
    EGLConfig config = configs[0];

    int[] surfAttr = {
            EGL14.EGL_WIDTH, 64,
            EGL14.EGL_HEIGHT, 64,
            EGL14.EGL_NONE
    };
    EGLSurface surf = EGL14.eglCreatePbufferSurface(dpy, config, surfAttr, 0);

    int[] ctxAttrib = {
            EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
            EGL14.EGL_NONE
    };
    EGLContext ctx = EGL14.eglCreateContext(dpy, config, EGL14.EGL_NO_CONTEXT, ctxAttrib, 0);

    EGL14.eglMakeCurrent(dpy, surf, surf, ctx);

    int[] maxSize = new int[1];
    GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_SIZE, maxSize, 0);

    EGL14.eglMakeCurrent(dpy, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE,
            EGL14.EGL_NO_CONTEXT);
    EGL14.eglDestroySurface(dpy, surf);
    EGL14.eglDestroyContext(dpy, ctx);
    EGL14.eglTerminate(dpy);

    return maxSize[0];
}
 
Example 15
Source File: SketchUtils.java    From sketch with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static int getOpenGLMaxTextureSizeJB1() {
    // Then get a hold of the default display, and initialize.
    // This could get more complex if you have to deal with devices that could have multiple displays,
    // but will be sufficient for a typical phone/tablet:
    android.opengl.EGLDisplay dpy = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
    int[] vers = new int[2];
    EGL14.eglInitialize(dpy, vers, 0, vers, 1);

    // Next, we need to find a config. Since we won't use this context for rendering,
    // the exact attributes aren't very critical:
    int[] configAttr = {
            EGL14.EGL_COLOR_BUFFER_TYPE, EGL14.EGL_RGB_BUFFER,
            EGL14.EGL_LEVEL, 0,
            EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT,
            EGL14.EGL_SURFACE_TYPE, EGL14.EGL_PBUFFER_BIT,
            EGL14.EGL_NONE
    };
    android.opengl.EGLConfig[] configs = new android.opengl.EGLConfig[1];
    int[] numConfig = new int[1];
    EGL14.eglChooseConfig(dpy, configAttr, 0,
            configs, 0, 1, numConfig, 0);
    //noinspection StatementWithEmptyBody
    if (numConfig[0] == 0) {
        // TROUBLE! No config found.
    }
    android.opengl.EGLConfig config = configs[0];

    // To make a context current, which we will need later,
    // you need a rendering surface, even if you don't actually plan to render.
    // To satisfy this requirement, create a small offscreen (Pbuffer) surface:
    int[] surfAttr = {
            EGL14.EGL_WIDTH, 64,
            EGL14.EGL_HEIGHT, 64,
            EGL14.EGL_NONE
    };
    android.opengl.EGLSurface surf = EGL14.eglCreatePbufferSurface(dpy, config, surfAttr, 0);

    // Next, create the context:
    int[] ctxAttrib = {
            EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
            EGL14.EGL_NONE
    };
    android.opengl.EGLContext ctx = EGL14.eglCreateContext(dpy, config, EGL14.EGL_NO_CONTEXT, ctxAttrib, 0);

    // Ready to make the context current now:
    EGL14.eglMakeCurrent(dpy, surf, surf, ctx);

    // If all of the above succeeded (error checking was omitted), you can make your OpenGL calls now:
    int[] maxSize = new int[1];
    GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_SIZE, maxSize, 0);

    // Once you're all done, you can tear down everything:
    EGL14.eglMakeCurrent(dpy, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE,
            EGL14.EGL_NO_CONTEXT);
    EGL14.eglDestroySurface(dpy, surf);
    EGL14.eglDestroyContext(dpy, ctx);
    EGL14.eglTerminate(dpy);

    return maxSize[0];
}
 
Example 16
Source File: EglUtils.java    From EasyPhotos with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static int getMaxTextureEgl14() {
    EGLDisplay dpy = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
    int[] vers = new int[2];
    EGL14.eglInitialize(dpy, vers, 0, vers, 1);

    int[] configAttr = {
            EGL14.EGL_COLOR_BUFFER_TYPE, EGL14.EGL_RGB_BUFFER,
            EGL14.EGL_LEVEL, 0,
            EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT,
            EGL14.EGL_SURFACE_TYPE, EGL14.EGL_PBUFFER_BIT,
            EGL14.EGL_NONE
    };
    EGLConfig[] configs = new EGLConfig[1];
    int[] numConfig = new int[1];
    EGL14.eglChooseConfig(dpy, configAttr, 0,
            configs, 0, 1, numConfig, 0);
    if (numConfig[0] == 0) {
        return 0;
    }
    EGLConfig config = configs[0];

    int[] surfAttr = {
            EGL14.EGL_WIDTH, 64,
            EGL14.EGL_HEIGHT, 64,
            EGL14.EGL_NONE
    };
    EGLSurface surf = EGL14.eglCreatePbufferSurface(dpy, config, surfAttr, 0);

    int[] ctxAttrib = {
            EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
            EGL14.EGL_NONE
    };
    EGLContext ctx = EGL14.eglCreateContext(dpy, config, EGL14.EGL_NO_CONTEXT, ctxAttrib, 0);

    EGL14.eglMakeCurrent(dpy, surf, surf, ctx);

    int[] maxSize = new int[1];
    GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_SIZE, maxSize, 0);

    EGL14.eglMakeCurrent(dpy, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE,
            EGL14.EGL_NO_CONTEXT);
    EGL14.eglDestroySurface(dpy, surf);
    EGL14.eglDestroyContext(dpy, ctx);
    EGL14.eglTerminate(dpy);

    return maxSize[0];
}
 
Example 17
Source File: GlFramebufferObject.java    From GPUVideo-android with MIT License 4 votes vote down vote up
public void setup(final int width, final int height) {
    final int[] args = new int[1];

    GLES20.glGetIntegerv(GL_MAX_TEXTURE_SIZE, args, 0);
    if (width > args[0] || height > args[0]) {
        throw new IllegalArgumentException("GL_MAX_TEXTURE_SIZE " + args[0]);
    }

    GLES20.glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, args, 0);
    if (width > args[0] || height > args[0]) {
        throw new IllegalArgumentException("GL_MAX_RENDERBUFFER_SIZE " + args[0]);
    }

    GLES20.glGetIntegerv(GL_FRAMEBUFFER_BINDING, args, 0);
    final int saveFramebuffer = args[0];
    GLES20.glGetIntegerv(GL_RENDERBUFFER_BINDING, args, 0);
    final int saveRenderbuffer = args[0];
    GLES20.glGetIntegerv(GL_TEXTURE_BINDING_2D, args, 0);
    final int saveTexName = args[0];

    release();

    try {
        this.width = width;
        this.height = height;

        GLES20.glGenFramebuffers(args.length, args, 0);
        framebufferName = args[0];
        GLES20.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName);

        GLES20.glGenRenderbuffers(args.length, args, 0);
        renderBufferName = args[0];
        GLES20.glBindRenderbuffer(GL_RENDERBUFFER, renderBufferName);
        GLES20.glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
        GLES20.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderBufferName);

        GLES20.glGenTextures(args.length, args, 0);
        texName = args[0];
        GLES20.glBindTexture(GL_TEXTURE_2D, texName);

        EglUtil.setupSampler(GL_TEXTURE_2D, GL_LINEAR, GL_NEAREST);

        GLES20.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, null);
        GLES20.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texName, 0);

        final int status = GLES20.glCheckFramebufferStatus(GL_FRAMEBUFFER);
        if (status != GL_FRAMEBUFFER_COMPLETE) {
            throw new RuntimeException("Failed to initialize framebuffer object " + status);
        }
    } catch (final RuntimeException e) {
        release();
        throw e;
    }

    GLES20.glBindFramebuffer(GL_FRAMEBUFFER, saveFramebuffer);
    GLES20.glBindRenderbuffer(GL_RENDERBUFFER, saveRenderbuffer);
    GLES20.glBindTexture(GL_TEXTURE_2D, saveTexName);
}
 
Example 18
Source File: GLState.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public int getInteger(final int pAttribute) {
	GLES20.glGetIntegerv(pAttribute, this.mHardwareIDContainer, 0);
	return this.mHardwareIDContainer[0];
}
 
Example 19
Source File: BitmapUtil.java    From sealrtc-android with MIT License 4 votes vote down vote up
/**
 * 读取图片(glReadPixels)
 *
 * @param texId
 * @param texMatrix
 * @param mvpMatrix
 * @param texWidth
 * @param texHeight
 * @param listener
 * @param isOes 是否是OES纹理
 */
public static void glReadBitmap(
        int texId,
        float[] texMatrix,
        float[] mvpMatrix,
        final int texWidth,
        final int texHeight,
        final OnReadBitmapListener listener,
        boolean isOes) {
    int[] textures = new int[1];
    GLES20.glGenTextures(1, textures, 0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glTexImage2D(
            GLES20.GL_TEXTURE_2D,
            0,
            GLES20.GL_RGBA,
            texWidth,
            texHeight,
            0,
            GLES20.GL_RGBA,
            GLES20.GL_UNSIGNED_BYTE,
            null);
    int[] frameBuffers = new int[1];
    GLES20.glGenFramebuffers(1, frameBuffers, 0);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffers[0]);
    GLES20.glFramebufferTexture2D(
            GLES20.GL_FRAMEBUFFER,
            GLES20.GL_COLOR_ATTACHMENT0,
            GLES20.GL_TEXTURE_2D,
            textures[0],
            0);
    int[] viewport = new int[4];
    GLES20.glGetIntegerv(GLES20.GL_VIEWPORT, viewport, 0);
    GLES20.glViewport(0, 0, texWidth, texHeight);
    GLES20.glClearColor(0, 0, 0, 0);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    if (isOes) {
        new ProgramTextureOES().drawFrame(texId, texMatrix, mvpMatrix);
    } else {
        new ProgramTexture2d().drawFrame(texId, texMatrix, mvpMatrix);
    }

    final ByteBuffer buffer = ByteBuffer.allocateDirect(texWidth * texHeight * 4);
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    GLES20.glFinish();
    GLES20.glReadPixels(0, 0, texWidth, texHeight, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, buffer);
    GlUtil.checkGlError("glReadPixels");
    buffer.rewind();
    GLES20.glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    GLES20.glDeleteTextures(1, textures, 0);
    GLES20.glDeleteFramebuffers(1, frameBuffers, 0);

    // ref:
    // https://www.programcreek.com/java-api-examples/?class=android.opengl.GLES20&method=glReadPixels
    AsyncTask.execute(
            new Runnable() {
                @Override
                public void run() {
                    Bitmap bmp =
                            Bitmap.createBitmap(texWidth, texHeight, Bitmap.Config.ARGB_8888);
                    bmp.copyPixelsFromBuffer(buffer);
                    Matrix matrix = new Matrix();
                    matrix.preScale(1f, -1f);
                    Bitmap finalBmp =
                            Bitmap.createBitmap(
                                    bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, false);
                    bmp.recycle();
                    if (listener != null) {
                        listener.onReadBitmapListener(finalBmp);
                    }
                }
            });
}
 
Example 20
Source File: CameraRecorder.java    From AAVT with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
    if(mOutputSurface==null){
        AvLog.d("CameraRecorder GLThread exit : outputSurface==null");
        return;
    }
    if(mPreviewWidth<=0||mPreviewHeight<=0){
        AvLog.d("CameraRecorder GLThread exit : Preview Size==0");
        return;
    }
    boolean ret=mShowEGLHelper.createGLESWithSurface(new EGLConfigAttrs(),new EGLContextAttrs(),mOutputSurface);
    if(!ret){
        AvLog.d("CameraRecorder GLThread exit : createGLES failed");
        return;
    }
    if(mRenderer==null){
        mRenderer=new WrapRenderer(null);
    }
    mRenderer.setFlag(WrapRenderer.TYPE_CAMERA);
    mRenderer.create();
    int[] t=new int[1];
    GLES20.glGetIntegerv(GLES20.GL_FRAMEBUFFER_BINDING,t,0);
    mRenderer.sizeChanged(mPreviewWidth,mPreviewHeight);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER,t[0]);

    BaseFilter mShowFilter=new LazyFilter();
    BaseFilter mRecFilter=new LazyFilter();
    MatrixUtils.flip(mShowFilter.getVertexMatrix(),false,true);
    mShowFilter.create();
    mShowFilter.sizeChanged(mPreviewWidth,mPreviewHeight);

    MatrixUtils.getMatrix(mRecFilter.getVertexMatrix(),MatrixUtils.TYPE_CENTERCROP,
            mPreviewWidth,mPreviewHeight,
            mOutputWidth,mOutputHeight);
    MatrixUtils.flip(mRecFilter.getVertexMatrix(),false,true);
    mRecFilter.create();
    mRecFilter.sizeChanged(mOutputWidth,mOutputHeight);

    FrameBuffer mEncodeFrameBuffer=new FrameBuffer();
    while (mGLThreadFlag){
        try {
            mSem.acquire();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if(mGLThreadFlag){
            long time=(System.currentTimeMillis()-BASE_TIME)*1000;
            mInputTexture.updateTexImage();
            mInputTexture.getTransformMatrix(mRenderer.getTextureMatrix());
            synchronized (VIDEO_LOCK){
                if(isRecordVideoStarted){
                    if(mEGLEncodeSurface==null){
                        mEGLEncodeSurface=mShowEGLHelper.createWindowSurface(mEncodeSurface);
                    }
                    mShowEGLHelper.makeCurrent(mEGLEncodeSurface);
                    mEncodeFrameBuffer.bindFrameBuffer(mPreviewWidth,mPreviewHeight);
                    mRenderer.draw(mInputTextureId);
                    mEncodeFrameBuffer.unBindFrameBuffer();
                    GLES20.glViewport(0,0,mConfig.getVideoFormat().getInteger(MediaFormat.KEY_WIDTH),
                            mConfig.getVideoFormat().getInteger(MediaFormat.KEY_HEIGHT));
                    mRecFilter.draw(mEncodeFrameBuffer.getCacheTextureId());
                    mShowEGLHelper.setPresentationTime(mEGLEncodeSurface,time*1000);
                    videoEncodeStep(false);
                    mShowEGLHelper.swapBuffers(mEGLEncodeSurface);

                    mShowEGLHelper.makeCurrent();
                    GLES20.glViewport(0,0,mPreviewWidth,mPreviewHeight);
                    mShowFilter.draw(mEncodeFrameBuffer.getCacheTextureId());
                    mShowEGLHelper.setPresentationTime(mShowEGLHelper.getDefaultSurface(),0);
                    mShowEGLHelper.swapBuffers(mShowEGLHelper.getDefaultSurface());
                }else{
                    GLES20.glViewport(0,0,mPreviewWidth,mPreviewHeight);
                    mRenderer.draw(mInputTextureId);
                    mShowEGLHelper.swapBuffers(mShowEGLHelper.getDefaultSurface());
                }
            }
        }
    }
    mShowEGLHelper.destroyGLES(mShowEGLHelper.getDefaultSurface(),mShowEGLHelper.getDefaultContext());
}