Exemple #1
0
        public override void bind(IRenderingEngine re, bool forDrawing)
        {
            base.bind(re, forDrawing);

            if (isUpdateRequired(re))
            {
                // Update the texture each time the GETexture has changed
                if (fboId == -1)
                {
                    fboId = re.genFramebuffer();
                    re.bindFramebuffer(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_FRAMEBUFFER, fboId);
                    re.setFramebufferTexture(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_FRAMEBUFFER, pspsharp.graphics.RE.IRenderingEngine_Fields.RE_COLOR_ATTACHMENT0, textureId, 0);
                }
                else
                {
                    re.bindFramebuffer(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_FRAMEBUFFER, fboId);
                }

                updateTexture(re);

                re.bindFramebuffer(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_FRAMEBUFFER, 0);
                re.bindTexture(textureId);
                if (forDrawing)
                {
                    re.setTextureFormat(pixelFormat, false);
                }

                geTexture.Changed = false;
            }
        }
Exemple #2
0
        public virtual void capture(IRenderingEngine re)
        {
            if (textureId == -1)
            {
                // Texture not yet created... nothing to capture
                return;
            }

            //if (log.DebugEnabled)
            {
                Console.WriteLine(string.Format("GETexture.capture {0}", ToString()));
            }

            prepareBuffer();
            re.bindTexture(textureId);
            re.setTextureFormat(pixelFormat, false);
            re.setPixelStore(bufferWidth, sceDisplay.getPixelFormatBytes(pixelFormat));
            re.getTexImage(0, pixelFormat, pixelFormat, buffer);

            CaptureManager.captureImage(address, 0, buffer, width, height, bufferWidth, pixelFormat, false, 0, true, false);
        }
Exemple #3
0
 protected internal override void updateTexture(IRenderingEngine re)
 {
     re.setTextureFormat(pixelFormat, false);
     base.updateTexture(re);
 }
Exemple #4
0
        public virtual void copyTextureToMemory(IRenderingEngine re)
        {
            if (textureId == -1)
            {
                // Texture not yet created... nothing to copy
                return;
            }

            if (!hasChanged())
            {
                // Texture unchanged... don't copy again
                return;
            }

            //if (log.DebugEnabled)
            {
                Console.WriteLine(string.Format("GETexture.copyTextureToMemory {0}", ToString()));
            }

            Buffer memoryBuffer = Memory.Instance.getBuffer(address, Length);

            prepareBuffer();
            re.bindTexture(textureId);
            re.setTextureFormat(pixelFormat, false);
            re.setPixelStore(bufferWidth, sceDisplay.getPixelFormatBytes(pixelFormat));
            re.getTexImage(0, pixelFormat, pixelFormat, buffer);

            buffer.clear();
            if (buffer is IntBuffer)
            {
                IntBuffer src = (IntBuffer)buffer;
                IntBuffer dst = (IntBuffer)memoryBuffer;
                int       pixelsPerElement = 4 / bytesPerPixel;
                int       copyWidth        = System.Math.Min(width, bufferWidth);
                int       widthLimit       = (copyWidth + pixelsPerElement - 1) / pixelsPerElement;
                int       step             = bufferWidth / pixelsPerElement;
                int       srcOffset        = 0;
                int       dstOffset        = (height - 1) * step;
                // We have received the texture data upside-down, invert it
                for (int y = 0; y < height; y++, srcOffset += step, dstOffset -= step)
                {
                    src.limit(srcOffset + widthLimit);
                    src.position(srcOffset);
                    dst.position(dstOffset);
                    dst.put(src);
                }
            }
            else
            {
                ByteBuffer src        = (ByteBuffer)buffer;
                ByteBuffer dst        = (ByteBuffer)memoryBuffer;
                int        copyWidth  = System.Math.Min(width, bufferWidth);
                int        widthLimit = copyWidth * bytesPerPixel;
                int        step       = bufferWidth * bytesPerPixel;
                int        srcOffset  = 0;
                int        dstOffset  = (height - 1) * step;
                // We have received the texture data upside-down, invert it
                for (int y = 0; y < height; y++, srcOffset += step, dstOffset -= step)
                {
                    src.limit(srcOffset + widthLimit);
                    src.position(srcOffset);
                    dst.position(dstOffset);
                    dst.put(src);
                }
            }

            Changed = false;
        }
Exemple #5
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);
            }
        }