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; } }
public virtual void copyScreenToTexture(IRenderingEngine re) { //if (log.DebugEnabled) { Console.WriteLine(string.Format("GETexture.copyScreenToTexture {0}", ToString())); } bind(re, false); int texWidth = System.Math.Min(bufferWidth, width); int texHeight = height; if (useViewportResize) { texWidth = sceDisplay.getResizedWidth(texWidth); texHeight = sceDisplay.getResizedHeight(texHeight); } re.copyTexSubImage(0, 0, 0, 0, 0, texWidth, texHeight); if (Modules.sceDisplayModule.SaveStencilToMemory) { if (!copyStencilToTextureAlpha(re, texWidth, texHeight)) { Modules.sceDisplayModule.SaveStencilToMemory = false; } } Changed = true; }
private void drawTexture(IRenderingEngine re, int x, int y, int projectionWidth, int projectionHeight, bool scaleToCanvas, bool redWriteEnabled, bool greenWriteEnabled, bool blueWriteEnabled, bool alphaWriteEnabled) { re.startDirectRendering(true, false, true, true, true, projectionWidth, projectionHeight); re.setColorMask(redWriteEnabled, greenWriteEnabled, blueWriteEnabled, alphaWriteEnabled); if (scaleToCanvas) { re.setViewport(0, 0, Modules.sceDisplayModule.CanvasWidth, Modules.sceDisplayModule.CanvasHeight); } else { re.setViewport(0, 0, projectionWidth, projectionHeight); } IREBufferManager bufferManager = re.BufferManager; ByteBuffer drawByteBuffer = bufferManager.getBuffer(drawBufferId); drawByteBuffer.clear(); FloatBuffer drawFloatBuffer = drawByteBuffer.asFloatBuffer(); drawFloatBuffer.clear(); drawFloatBuffer.put(texS); drawFloatBuffer.put(texT); drawFloatBuffer.put(x + width); drawFloatBuffer.put(y + height); drawFloatBuffer.put(0.0f); drawFloatBuffer.put(texT); drawFloatBuffer.put(x); drawFloatBuffer.put(y + height); drawFloatBuffer.put(0.0f); drawFloatBuffer.put(0.0f); drawFloatBuffer.put(x); drawFloatBuffer.put(y); drawFloatBuffer.put(texS); drawFloatBuffer.put(0.0f); drawFloatBuffer.put(x + width); drawFloatBuffer.put(y); if (re.VertexArrayAvailable) { re.bindVertexArray(0); } re.setVertexInfo(null, false, false, true, -1); re.enableClientState(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_TEXTURE); re.disableClientState(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_COLOR); re.disableClientState(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_NORMAL); re.enableClientState(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_VERTEX); bufferManager.setTexCoordPointer(drawBufferId, 2, pspsharp.graphics.RE.IRenderingEngine_Fields.RE_FLOAT, 4 * SIZEOF_FLOAT, 0); bufferManager.setVertexPointer(drawBufferId, 2, pspsharp.graphics.RE.IRenderingEngine_Fields.RE_FLOAT, 4 * SIZEOF_FLOAT, 2 * SIZEOF_FLOAT); bufferManager.setBufferData(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_ARRAY_BUFFER, drawBufferId, drawFloatBuffer.position() * SIZEOF_FLOAT, drawByteBuffer.rewind(), pspsharp.graphics.RE.IRenderingEngine_Fields.RE_DYNAMIC_DRAW); re.drawArrays(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_QUADS, 0, 4); re.endDirectRendering(); }
protected internal virtual void copyTextureToScreen(IRenderingEngine re, int x, int y, int projectionWidth, int projectionHeight, bool scaleToCanvas, bool redWriteEnabled, bool greenWriteEnabled, bool blueWriteEnabled, bool alphaWriteEnabled) { //if (log.DebugEnabled) { Console.WriteLine(string.Format("GETexture.copyTextureToScreen {0} at {1:D}x{2:D}", ToString(), x, y)); } bind(re, true); drawTexture(re, x, y, projectionWidth, projectionHeight, scaleToCanvas, redWriteEnabled, greenWriteEnabled, blueWriteEnabled, alphaWriteEnabled); }
public virtual void delete(IRenderingEngine re) { if (drawBufferId != -1) { re.BufferManager.deleteBuffer(drawBufferId); drawBufferId = -1; } if (textureId != -1) { re.deleteTexture(textureId); textureId = -1; } }
public override void delete(IRenderingEngine re) { if (fboId != -1) { re.deleteFramebuffer(fboId); fboId = -1; } if (depthRenderBufferId != -1) { re.deleteRenderbuffer(depthRenderBufferId); depthRenderBufferId = -1; } base.delete(re); }
public virtual bool bind(IRenderingEngine re) { bool needSetDataPointers = pendingReload; pendingReload = false; if (id == -1) { id = re.genVertexArray(); needSetDataPointers = true; } re.bindVertexArray(id); return(needSetDataPointers); }
public virtual void blitFrom(IRenderingEngine re, FBTexture src) { if (fboId == -1) { createFBO(re, false); } // Bind the source and destination FBOs re.bindFramebuffer(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_READ_FRAMEBUFFER, src.fboId); re.bindFramebuffer(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_DRAW_FRAMEBUFFER, fboId); // Copy the source FBO to the destination FBO re.blitFramebuffer(0, 0, src.ResizedWidth, src.ResizedHeight, 0, 0, ResizedWidth, ResizedHeight, pspsharp.graphics.RE.IRenderingEngine_Fields.RE_COLOR_BUFFER_BIT, GeCommands.TFLT_NEAREST); // Re-bind the source FBO re.bindFramebuffer(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_FRAMEBUFFER, src.fboId); }
protected internal virtual void createFBO(IRenderingEngine re, bool forDrawing) { // Create the FBO and associate it to the texture fboId = re.genFramebuffer(); re.bindFramebuffer(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_FRAMEBUFFER, fboId); // Create a render buffer for the depth buffer depthRenderBufferId = re.genRenderbuffer(); re.bindRenderbuffer(depthRenderBufferId); re.setRenderbufferStorage(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_DEPTH_COMPONENT, TexImageWidth, TexImageHeight); // Create the texture base.bind(re, forDrawing); // Attach the texture to the FBO re.setFramebufferTexture(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_FRAMEBUFFER, pspsharp.graphics.RE.IRenderingEngine_Fields.RE_COLOR_ATTACHMENT0, textureId, 0); // Attach the depth buffer to the FBO re.setFramebufferRenderbuffer(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_FRAMEBUFFER, pspsharp.graphics.RE.IRenderingEngine_Fields.RE_DEPTH_ATTACHMENT, depthRenderBufferId); }
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); }
public override void bind(IRenderingEngine re, bool forDrawing) { if (forDrawing) { // We are copying the texture back to the main frame buffer, // bind the texture, not the FBO. re.bindFramebuffer(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_FRAMEBUFFER, 0); base.bind(re, forDrawing); } else { if (fboId == -1) { createFBO(re, forDrawing); } else { // Bind the FBO re.bindFramebuffer(pspsharp.graphics.RE.IRenderingEngine_Fields.RE_FRAMEBUFFER, fboId); } } }
protected internal virtual bool isUpdateRequired(IRenderingEngine re) { return(geTexture.hasChanged()); }
public virtual void copyTextureToScreen(IRenderingEngine re) { copyTextureToScreen(re, 0, 0, width, height, true, true, true, true, true); }
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; }
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); }
protected internal abstract void updateTexture(IRenderingEngine re);
public void allocateId(pspsharp.graphics.RE.IRenderingEngine re, int shaderProgram) { uniformId[shaderProgram] = re.getUniformLocation(shaderProgram, uniformString); }
protected internal override void updateTexture(IRenderingEngine re) { // Resize the GETexture to the requested texture size. // This has to be performed each time the base GETexture has changed. geTexture.copyTextureToScreen(re, x, y, Width, Height, false, true, true, true, true); }
public virtual void delete(IRenderingEngine re) { re.deleteVertexArray(id); id = -1; }
protected internal override void updateTexture(IRenderingEngine re) { re.setTextureFormat(pixelFormat, false); base.updateTexture(re); }
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); } }