private int setupRenderTextureAndRenderbuffer(int width, int height)
        {
            if (mTextureId != -1)
            {
                GLES20.GlDeleteTextures(1, new int[] { mTextureId }, 0);
            }
            if (mRenderbufferId != -1)
            {
                GLES20.GlDeleteRenderbuffers(1, new int[] { mRenderbufferId }, 0);
            }
            if (mFramebufferId != -1)
            {
                GLES20.GlDeleteFramebuffers(1, new int[] { mFramebufferId }, 0);
            }

            mTextureId = createTexture(width, height);
            checkGlError("setupRenderTextureAndRenderbuffer: create texture");

            int[] renderbufferIds = new int[1];
            GLES20.GlGenRenderbuffers(1, renderbufferIds, 0);
            GLES20.GlBindRenderbuffer(36161, renderbufferIds[0]);
            GLES20.GlRenderbufferStorage(36161, 33189, width, height);

            mRenderbufferId = renderbufferIds[0];
            checkGlError("setupRenderTextureAndRenderbuffer: create renderbuffer");

            int[] framebufferIds = new int[1];
            GLES20.GlGenFramebuffers(1, framebufferIds, 0);
            GLES20.GlBindFramebuffer(36160, framebufferIds[0]);
            mFramebufferId = framebufferIds[0];

            GLES20.GlFramebufferTexture2D(36160, 36064, 3553, mTextureId, 0);

            GLES20.GlFramebufferRenderbuffer(36160, 36096, 36161, renderbufferIds[0]);

            int status = GLES20.GlCheckFramebufferStatus(36160);

            if (status != 36053)
            {
                throw new Java.Lang.RuntimeException("Framebuffer is not complete: " + Java.Lang.Integer.ToHexString(status));
            }

            GLES20.GlBindFramebuffer(36160, 0);

            return(framebufferIds[0]);
        }
        /**
         * Initializes FBO with given parameters. Width and height are used to
         * generate textures out of which all are sized same to this FBO. If you
         * give genRenderBuffer a value 'true', depth buffer will be generated also.
         *
         * @param width
         *            FBO width in pixels
         * @param height
         *            FBO height in pixels
         * @param textureCount
         *            Number of textures to generate
         * @param genDepthBuffer
         *            If true, depth buffer is allocated for this FBO @ param
         *            genStencilBuffer If true, stencil buffer is allocated for this
         *            FBO
         */
        public void init(int width, int height, int textureCount,
                         bool textureExternalOES)
        {
            // Just in case.
            Reset();

            // Store FBO size.
            _width  = width;
            _height = height;

            // Genereta FBO.
            var handle = new int[] { 0 };

            GLES20.GlGenFramebuffers(1, handle, 0);
            _frameBufferHandle = handle[0];
            GLES20.GlBindFramebuffer(GLES20.GlFramebuffer, _frameBufferHandle);

            // Generate textures.
            _textureHandles = new int[textureCount];
            GLES20.GlGenTextures(textureCount, _textureHandles, 0);
            var target = textureExternalOES ? GLES11Ext.GlTextureExternalOes
                                : GLES20.GlTexture2d;

            foreach (var texture in _textureHandles)
            {
                GLES20.GlBindTexture(target, texture);
                GLES20.GlTexParameteri(GLES20.GlTexture2d,
                                       GLES20.GlTextureWrapS, GLES20.GlClampToEdge);
                GLES20.GlTexParameteri(target, GLES20.GlTextureWrapT,
                                       GLES20.GlClampToEdge);
                GLES20.GlTexParameteri(target, GLES20.GlTextureMinFilter,
                                       GLES20.GlNearest);
                GLES20.GlTexParameteri(target, GLES20.GlTextureMagFilter,
                                       GLES20.GlLinear);
                if (target == GLES20.GlTexture2d)
                {
                    GLES20.GlTexImage2D(GLES20.GlTexture2d, 0, GLES20.GlRgba,
                                        _width, _height, 0, GLES20.GlRgba,
                                        GLES20.GlUnsignedByte, null);
                }
            }
        }
Example #3
0
        private void create(int width, int height)
        {
            // FBO
            int[] ret = new int[1];

            // frame buffer
            GLES20.GlGenFramebuffers(1, ret, 0);
            FBO = ret[0];
            GLES20.GlBindFramebuffer(GLES20.GlFramebuffer, FBO);

            // depth buffer
            GLES20.GlGenRenderbuffers(1, ret, 0);
            RBOD = ret[0];
            GLES20.GlBindRenderbuffer(GLES20.GlFramebuffer, RBOD);
            GLES20.GlRenderbufferStorage(GLES20.GlRenderbuffer, GLES20.GlDepthComponent16, width, height);
            GLES20.GlFramebufferRenderbuffer(GLES20.GlFramebuffer, GLES20.GlDepthAttachment, GLES20.GlRenderbuffer, RBOD);

            // color buffer (is texture)
            GLES20.GlPixelStorei(GLES20.GlUnpackAlignment, 1);
            GLES20.GlGenTextures(1, ret, 0);
            RBOC = ret[0];
            GLES20.GlBindTexture(GLES20.GlTexture2d, RBOC);
            GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureWrapS, GLES20.GlClampToEdge);
            GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureWrapT, GLES20.GlClampToEdge);
            GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMagFilter, GLES20.GlLinear);
            GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMinFilter, GLES20.GlLinear);
            GLES20.GlTexImage2D(GLES20.GlTexture2d, 0, GLES20.GlRgba, width, height, 0, GLES20.GlRgba, GLES20.GlUnsignedByte, null);
            GLES20.GlFramebufferTexture2D(GLES20.GlFramebuffer, GLES20.GlColorAttachment0, GLES20.GlTexture2d, RBOC, 0);

            if (GLES20.GlCheckFramebufferStatus(GLES20.GlFramebuffer) != GLES20.GlFramebufferComplete)
            {
                Log.Debug(TAG, "Fail to create FBO.");
                FBO  = 0;
                RBOD = 0;
                RBOC = 0;
            }
        }
Example #4
0
        public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            GLES20.GlClearColor(0.9f, 0.1f, 0.1f, 1.0f);
            // GLES20.GlViewport(0, 0, glSurfaceView.Width, glSurfaceView.Height);

            textureSize = arSession.CameraConfig.TextureSize;
            arSession.SetDisplayGeometry(1, targetResolution.Width, targetResolution.Height);

            int[] glObjs = new int[1];
            GLES20.GlGenFramebuffers(1, glObjs, 0);
            fboId = glObjs[0];
            GLES20.GlBindFramebuffer(GLES20.GlFramebuffer, fboId);
            GLES20.GlViewport(0, 0, targetResolution.Width, targetResolution.Height);
            GLES20.GlGenTextures(1, glObjs, 0);
            renderTextureId = glObjs[0];;
            GLES20.GlBindTexture(GLES20.GlTexture2d, renderTextureId);
            GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureWrapS, GLES20.GlClampToEdge);
            GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureWrapT, GLES20.GlClampToEdge);
            GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMinFilter, GLES20.GlNearest);
            GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMagFilter, GLES20.GlNearest);
            GLES20.GlTexImage2D(GLES20.GlTexture2d, 0, GLES20.GlRgba, targetResolution.Width, targetResolution.Height, 0, GLES20.GlRgba, GLES20.GlUnsignedByte, null);

            GLES20.GlBindTexture(GLES20.GlTexture2d, 0);
            GLES20.GlFramebufferTexture2D(GLES20.GlFramebuffer, GLES20.GlColorAttachment0, GLES20.GlTexture2d, renderTextureId, 0);
            GLES20.GlBindFramebuffer(GLES20.GlFramebuffer, 0);

            GlUtil.CheckNoGLES2Error("Create render texture.");

            // Create the texture and pass it to ARCore session to be filled during update().
            backgroundRenderer.CreateOnGlThread(/*context=*/ this);
            if (arSession != null)
            {
                arSession.SetCameraTextureName(BackgroundRenderer.TextureId);
            }


            // Prepare the other rendering objects.
            try
            {
                virtualObject.CreateOnGlThread(/*context=*/ this, "andy.obj", "andy.png");
                virtualObject.setMaterialProperties(0.0f, 3.5f, 1.0f, 6.0f);

                virtualObjectShadow.CreateOnGlThread(/*context=*/ this,
                                                     "andy_shadow.obj", "andy_shadow.png");
                virtualObjectShadow.SetBlendMode(ObjectRenderer.BlendMode.Shadow);
                virtualObjectShadow.setMaterialProperties(1.0f, 0.0f, 0.0f, 1.0f);
            }
            catch (Java.IO.IOException e)
            {
                Log.Error(TAG, "Failed to read obj file");
            }

            try
            {
                planeRenderer.CreateOnGlThread(/*context=*/ this, "trigrid.png");
            }
            catch (Java.IO.IOException e)
            {
                Log.Error(TAG, "Failed to read plane texture");
            }
            pointCloudRenderer.CreateOnGlThread(/*context=*/ this);
        }