Ejemplo n.º 1
0
        //
        // FNA3D_ResolveTarget
        //

        public static void FNA3D_ResolveTarget(IntPtr device,
                                               ref FNA3D_RenderTargetBinding renderTarget)
        {
            if (renderTarget.multiSampleCount > 0)
            {
                // no support for multisampling; see FNA3D_SetRenderTargets
                throw new PlatformNotSupportedException();
            }

            if (renderTarget.levelCount > 1)
            {
                int attachmentType = GLES20.GL_TEXTURE_2D;
                if (renderTarget.type != /* FNA3D_RENDERTARGET_TYPE_2D */ 0)
                {
                    attachmentType = GLES20.GL_TEXTURE_CUBE_MAP_POSITIVE_X
                                     + renderTarget.data2;
                }
                int texture = (int)renderTarget.texture;

                var renderer = Renderer.Get(device);
                renderer.Send(false, () =>
                {
                    int textureUnit = GLES20.GL_TEXTURE0 + renderer.TextureUnits - 1;
                    GLES20.glActiveTexture(textureUnit);

                    GLES20.glBindTexture(attachmentType, texture);
                    GLES20.glGenerateMipmap(attachmentType);

                    var state = (State)renderer.UserData;
                    if (state.TextureOnLastUnit != 0)
                    {
                        GLES20.glBindTexture(attachmentType, state.TextureOnLastUnit);
                    }
                });
            }
        }
Ejemplo n.º 2
0
 public static extern void FNA3D_ResolveTarget(
     IntPtr device,
     ref FNA3D_RenderTargetBinding target
     );
Ejemplo n.º 3
0
        //
        // FNA3D_SetRenderTargets
        //

        public static unsafe void FNA3D_SetRenderTargets(IntPtr device,
                                                         FNA3D_RenderTargetBinding *renderTargets,
                                                         int numRenderTargets,
                                                         IntPtr depthStencilBuffer,
                                                         DepthFormat depthFormat,
                                                         byte preserveContents)
        {
            var renderTargetsCopy = new FNA3D_RenderTargetBinding[numRenderTargets];

            for (int i = 0; i < numRenderTargets; i++)
            {
                renderTargetsCopy[i] = renderTargets[i];
            }

            var renderer = Renderer.Get(device);

            renderer.Send(false, () =>
            {
                var state = (State)renderer.UserData;
                if (state.TargetFramebuffer == 0)
                {
                    var id = new int[1];
                    GLES20.glGenFramebuffers(1, id, 0);
                    if ((state.TargetFramebuffer = id[0]) == 0)
                    {
                        return;
                    }
                }
                GLES20.glBindFramebuffer(GLES30.GL_DRAW_FRAMEBUFFER,
                                         state.TargetFramebuffer);

                int attachmentIndex = GLES20.GL_COLOR_ATTACHMENT0;
                foreach (var renderTarget in renderTargetsCopy)
                {
                    if (renderTarget.colorBuffer != IntPtr.Zero)
                    {
                        // a color buffer is only created if a non-zero result
                        // from FNA3D_GetMaxMultiSampleCount, which we never do
                        throw new PlatformNotSupportedException();

                        /*GLES20.glFramebufferRenderbuffer(
                         *  GLES20.GL_DRAW_FRAMEBUFFER, attachmentIndex,
                         *  GLES20.GL_RENDERBUFFER, (int) renderTarget.colorBuffer);*/
                    }
                    else
                    {
                        int attachmentType = GLES20.GL_TEXTURE_2D;
                        if (renderTarget.type != /* FNA3D_RENDERTARGET_TYPE_2D */ 0)
                        {
                            attachmentType = GLES20.GL_TEXTURE_CUBE_MAP_POSITIVE_X
                                             + renderTarget.data2;
                        }
                        GLES20.glFramebufferTexture2D(
                            GLES30.GL_DRAW_FRAMEBUFFER, attachmentIndex,
                            attachmentType, (int)renderTarget.texture, 0);
                    }
                    attachmentIndex++;
                }

                int lastAttachmentPlusOne = state.ActiveAttachments;
                state.ActiveAttachments   = attachmentIndex;
                while (attachmentIndex < lastAttachmentPlusOne)
                {
                    GLES20.glFramebufferRenderbuffer(
                        GLES30.GL_DRAW_FRAMEBUFFER, attachmentIndex++,
                        GLES20.GL_RENDERBUFFER, 0);
                }

                GLES20.glFramebufferRenderbuffer(
                    GLES30.GL_DRAW_FRAMEBUFFER, GLES30.GL_DEPTH_STENCIL_ATTACHMENT,
                    GLES20.GL_RENDERBUFFER, (int)depthStencilBuffer);

                state.RenderToTexture = true;
            });
        }