Пример #1
0
        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]);
        }
Пример #2
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;
            }
        }
Пример #3
0
 public virtual void attach(int point, Texture tex)
 {
     bind();
     GLES20.GlFramebufferTexture2D(GLES20.GlFramebuffer, point, GLES20.GlTexture2d, tex.Id, 0);
 }
 /**
  * Bind certain texture into target texture. This method should be called
  * only after call to bind().
  *
  * @param index
  *            Index of texture to bind.
  */
 public void BindTexture(int index)
 {
     GLES20.GlFramebufferTexture2D(GLES20.GlFramebuffer,
                                   GLES20.GlColorAttachment0, GLES20.GlTexture2d,
                                   _textureHandles[index], 0);
 }
Пример #5
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);
        }