示例#1
0
        protected internal virtual bool copyStencilToTextureAlpha(IRenderingEngine re, int texWidth, int texHeight)
        {
            re.checkAndLogErrors(null);

            if (stencilFboId == -1)
            {
                // Create a FBO
                stencilFboId = re.genFramebuffer();
                re.bindFramebuffer(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_DRAW_FRAMEBUFFER, stencilFboId);

                // Create stencil texture and attach it to the FBO
                stencilTextureId = re.genTexture();
                re.bindTexture(stencilTextureId);
                re.checkAndLogErrors("bindTexture");
                re.setTexImage(0, stencilPixelFormat, TexImageWidth, TexImageHeight, stencilPixelFormat, stencilPixelFormat, 0, null);
                if (re.checkAndLogErrors("setTexImage"))
                {
                    return(false);
                }
                re.TextureMipmapMinFilter = TFLT_NEAREST;
                re.TextureMipmapMagFilter = TFLT_NEAREST;
                re.TextureMipmapMinLevel  = 0;
                re.TextureMipmapMaxLevel  = 0;
                re.setTextureWrapMode(TWRAP_WRAP_MODE_CLAMP, TWRAP_WRAP_MODE_CLAMP);
                re.setFramebufferTexture(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_DRAW_FRAMEBUFFER, pspsharp.graphics.RE.IRenderingEngine_Fields.RE_DEPTH_STENCIL_ATTACHMENT, stencilTextureId, 0);
                if (re.checkAndLogErrors("setFramebufferTexture RE_STENCIL_ATTACHMENT"))
                {
                    return(false);
                }

                // Attach the GE texture to the FBO as well
                re.setFramebufferTexture(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_DRAW_FRAMEBUFFER, pspsharp.graphics.RE.IRenderingEngine_Fields.RE_COLOR_ATTACHMENT0, textureId, 0);
                if (re.checkAndLogErrors("setFramebufferTexture RE_COLOR_ATTACHMENT0"))
                {
                    return(false);
                }
            }
            else
            {
                re.bindFramebuffer(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_DRAW_FRAMEBUFFER, stencilFboId);
            }

            // Copy screen stencil buffer to stencil texture:
            // - read framebuffer is screen (0)
            // - draw/write framebuffer is our stencil FBO (stencilFboId)
            re.blitFramebuffer(0, 0, texWidth, texHeight, 0, 0, texWidth, texHeight, pspsharp.graphics.RE.IRenderingEngine_Fields.RE_STENCIL_BUFFER_BIT, GeCommands.TFLT_NEAREST);
            if (re.checkAndLogErrors("blitFramebuffer"))
            {
                return(false);
            }

            re.bindTexture(stencilTextureId);

            if (!re.setCopyRedToAlpha(true))
            {
                return(false);
            }

            // Draw the stencil texture and update only the alpha channel of the GE texture
            drawTexture(re, 0, 0, width, height, true, false, false, false, true);
            re.checkAndLogErrors("drawTexture");

            // Reset the framebuffer to the default one
            re.bindFramebuffer(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_DRAW_FRAMEBUFFER, 0);

            re.CopyRedToAlpha = false;

            // Success
            return(true);
        }
示例#2
0
        public virtual void bind(IRenderingEngine re, bool forDrawing)
        {
            float viewportResizeScaleFactor = ViewportResizeScaleFactor;

            // Create the texture if not yet created or
            // re-create it if the viewport resize factor has been changed dynamically.
            if (textureId == -1 || viewportResizeScaleFactor != resizeScale)
            {
                // The pspsharp window has been resized. Recreate all the textures using the new size.
                if (textureId != -1)
                {
                    re.deleteTexture(textureId);
                    textureId = -1;
                }
                if (stencilTextureId != -1)
                {
                    re.deleteTexture(stencilTextureId);
                    stencilTextureId = -1;
                }
                if (stencilFboId != -1)
                {
                    re.deleteFramebuffer(stencilFboId);
                    stencilFboId = -1;
                }

                resizeScale = viewportResizeScaleFactor;

                if (useViewportResize)
                {
                    texS = sceDisplay.getResizedWidth(width) / (float)TexImageWidth;
                    texT = sceDisplay.getResizedHeight(height) / (float)TexImageHeight;
                }
                else
                {
                    texS = width / (float)bufferWidth;
                    texT = height / (float)heightPow2;
                }

                textureId = re.genTexture();
                re.bindTexture(textureId);
                re.setTexImage(0, pixelFormat, TexImageWidth, TexImageHeight, pixelFormat, pixelFormat, 0, null);
                re.TextureMipmapMinFilter = TFLT_NEAREST;
                re.TextureMipmapMagFilter = TFLT_NEAREST;
                re.TextureMipmapMinLevel  = 0;
                re.TextureMipmapMaxLevel  = 0;
                re.setTextureWrapMode(TWRAP_WRAP_MODE_CLAMP, TWRAP_WRAP_MODE_CLAMP);
                if (drawBufferId == -1)
                {
                    drawBufferId = re.BufferManager.genBuffer(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_ARRAY_BUFFER, pspsharp.graphics.RE.IRenderingEngine_Fields.RE_FLOAT, 16, pspsharp.graphics.RE.IRenderingEngine_Fields.RE_DYNAMIC_DRAW);
                }
            }
            else
            {
                re.bindTexture(textureId);
            }

            if (forDrawing)
            {
                re.setTextureFormat(pixelFormat, false);
            }
        }