use renderbuf fo xfb

This commit is contained in:
degasus 2013-01-16 01:37:00 +01:00
parent bb200acdd8
commit 681272d65d
4 changed files with 22 additions and 24 deletions

View File

@ -297,11 +297,17 @@ GLuint FramebufferManager::ResolveAndGetDepthTarget(const EFBRectangle &source_r
return GetEFBDepthTexture(source_rect); return GetEFBDepthTexture(source_rect);
} }
XFBSource::~XFBSource()
{
glDeleteRenderbuffers(1, &renderbuf);
}
void XFBSource::Draw(const MathUtil::Rectangle<float> &sourcerc, void XFBSource::Draw(const MathUtil::Rectangle<float> &sourcerc,
const MathUtil::Rectangle<float> &drawrc, int width, int height) const const MathUtil::Rectangle<float> &drawrc, int width, int height) const
{ {
// Texture map xfbSource->texture onto the main buffer // Texture map xfbSource->texture onto the main buffer
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, texture, 0); glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuf);
glBlitFramebuffer(sourcerc.left, sourcerc.bottom, sourcerc.right, sourcerc.top, glBlitFramebuffer(sourcerc.left, sourcerc.bottom, sourcerc.right, sourcerc.top,
drawrc.left, drawrc.bottom, drawrc.right, drawrc.top, drawrc.left, drawrc.bottom, drawrc.right, drawrc.top,
GL_COLOR_BUFFER_BIT, GL_LINEAR); GL_COLOR_BUFFER_BIT, GL_LINEAR);
@ -311,7 +317,7 @@ void XFBSource::Draw(const MathUtil::Rectangle<float> &sourcerc,
void XFBSource::DecodeToTexture(u32 xfbAddr, u32 fbWidth, u32 fbHeight) void XFBSource::DecodeToTexture(u32 xfbAddr, u32 fbWidth, u32 fbHeight)
{ {
TextureConverter::DecodeToTexture(xfbAddr, fbWidth, fbHeight, texture); TextureConverter::DecodeToTexture(xfbAddr, fbWidth, fbHeight, renderbuf);
} }
void XFBSource::CopyEFB(float Gamma) void XFBSource::CopyEFB(float Gamma)
@ -321,7 +327,7 @@ void XFBSource::CopyEFB(float Gamma)
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferManager::GetXFBFramebuffer()); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferManager::GetXFBFramebuffer());
// Bind texture. // Bind texture.
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, texture, 0); glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuf);
GL_REPORT_FBO_ERROR(); GL_REPORT_FBO_ERROR();
glBlitFramebuffer( glBlitFramebuffer(
@ -330,26 +336,21 @@ void XFBSource::CopyEFB(float Gamma)
GL_COLOR_BUFFER_BIT, GL_NEAREST GL_COLOR_BUFFER_BIT, GL_NEAREST
); );
// Unbind texture.
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, 0, 0);
// Return to EFB. // Return to EFB.
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferManager::GetEFBFramebuffer()); FramebufferManager::SetFramebuffer(0);
} }
XFBSourceBase* FramebufferManager::CreateXFBSource(unsigned int target_width, unsigned int target_height) XFBSourceBase* FramebufferManager::CreateXFBSource(unsigned int target_width, unsigned int target_height)
{ {
GLuint texture; GLuint renderbuf;
glGenTextures(1, &texture); glGenRenderbuffers(1, &renderbuf);
glBindTexture(GL_TEXTURE_RECTANGLE, texture); glBindRenderbuffer(GL_RENDERBUFFER, renderbuf);
glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA, target_width, target_height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, target_width, target_height);
glBindTexture(GL_TEXTURE_RECTANGLE, 0); return new XFBSource(renderbuf);
return new XFBSource(texture);
} }
void FramebufferManager::GetTargetSize(unsigned int *width, unsigned int *height, const EFBRectangle& sourceRc) void FramebufferManager::GetTargetSize(unsigned int *width, unsigned int *height, const EFBRectangle& sourceRc)

View File

@ -57,15 +57,15 @@ namespace OGL {
struct XFBSource : public XFBSourceBase struct XFBSource : public XFBSourceBase
{ {
XFBSource(GLuint tex) : texture(tex) {} XFBSource(GLuint rbuf) : renderbuf(rbuf) {}
~XFBSource() { glDeleteTextures(1, &texture); } ~XFBSource();
void CopyEFB(float Gamma); void CopyEFB(float Gamma);
void DecodeToTexture(u32 xfbAddr, u32 fbWidth, u32 fbHeight); void DecodeToTexture(u32 xfbAddr, u32 fbWidth, u32 fbHeight);
void Draw(const MathUtil::Rectangle<float> &sourcerc, void Draw(const MathUtil::Rectangle<float> &sourcerc,
const MathUtil::Rectangle<float> &drawrc, int width, int height) const; const MathUtil::Rectangle<float> &drawrc, int width, int height) const;
const GLuint texture; const GLuint renderbuf;
}; };
class FramebufferManager : public FramebufferManagerBase class FramebufferManager : public FramebufferManagerBase

View File

@ -395,7 +395,7 @@ void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc, u8* des
// Should be scale free. // Should be scale free.
void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTexture) void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destRenderbuf)
{ {
u8* srcAddr = Memory::GetPointer(xfbAddr); u8* srcAddr = Memory::GetPointer(xfbAddr);
if (!srcAddr) if (!srcAddr)
@ -411,9 +411,7 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur
// switch to texture converter frame buffer // switch to texture converter frame buffer
// attach destTexture as color destination // attach destTexture as color destination
FramebufferManager::SetFramebuffer(s_texConvFrameBuffer); FramebufferManager::SetFramebuffer(s_texConvFrameBuffer);
glBindTexture(GL_TEXTURE_2D, 0); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, destRenderbuf);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, destTexture);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, destTexture, 0);
GL_REPORT_FBO_ERROR(); GL_REPORT_FBO_ERROR();
@ -471,7 +469,6 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur
// reset state // reset state
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, 0, 0);
TextureCache::DisableStage(0); TextureCache::DisableStage(0);
VertexShaderManager::SetViewportChanged(); VertexShaderManager::SetViewportChanged();

View File

@ -35,7 +35,7 @@ void Shutdown();
void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc, void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc,
u8* destAddr, int dstWidth, int dstHeight); u8* destAddr, int dstWidth, int dstHeight);
void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTexture); void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destRenderbuf);
// returns size of the encoded data (in bytes) // returns size of the encoded data (in bytes)
int EncodeToRamFromTexture(u32 address, GLuint source_texture, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source); int EncodeToRamFromTexture(u32 address, GLuint source_texture, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source);