Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ogl: use texture_2d instead of renderbuffer for realxfb + efb2ram fbo
It should do the same on gpu, but textures are more flexible.
eg we could copy and sample them directly without blitting.
  • Loading branch information
degasus committed Aug 20, 2013
1 parent 9dfb127 commit 64bd6a4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
20 changes: 11 additions & 9 deletions Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp
Expand Up @@ -412,15 +412,15 @@ void FramebufferManager::ReinterpretPixelData(unsigned int convtype)

XFBSource::~XFBSource()
{
glDeleteRenderbuffers(1, &renderbuf);
glDeleteTextures(1, &texture);
}


void XFBSource::Draw(const MathUtil::Rectangle<float> &sourcerc,
const MathUtil::Rectangle<float> &drawrc, int width, int height) const
{
// Texture map xfbSource->texture onto the main buffer
glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuf);
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
glBlitFramebuffer(sourcerc.left, sourcerc.bottom, sourcerc.right, sourcerc.top,
drawrc.left, drawrc.bottom, drawrc.right, drawrc.top,
GL_COLOR_BUFFER_BIT, GL_LINEAR);
Expand All @@ -430,7 +430,7 @@ void XFBSource::Draw(const MathUtil::Rectangle<float> &sourcerc,

void XFBSource::DecodeToTexture(u32 xfbAddr, u32 fbWidth, u32 fbHeight)
{
TextureConverter::DecodeToTexture(xfbAddr, fbWidth, fbHeight, renderbuf);
TextureConverter::DecodeToTexture(xfbAddr, fbWidth, fbHeight, texture);
}

void XFBSource::CopyEFB(float Gamma)
Expand All @@ -440,7 +440,7 @@ void XFBSource::CopyEFB(float Gamma)
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferManager::GetXFBFramebuffer());

// Bind texture.
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuf);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
GL_REPORT_FBO_ERROR();

glBlitFramebuffer(
Expand All @@ -456,14 +456,16 @@ void XFBSource::CopyEFB(float Gamma)

XFBSourceBase* FramebufferManager::CreateXFBSource(unsigned int target_width, unsigned int target_height)
{
GLuint renderbuf;
GLuint texture;

glGenRenderbuffers(1, &renderbuf);
glGenTextures(1, &texture);

glBindRenderbuffer(GL_RENDERBUFFER, renderbuf);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, target_width, target_height);
glActiveTexture(GL_TEXTURE0 + 9);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, target_width, target_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

return new XFBSource(renderbuf);
return new XFBSource(texture);
}

void FramebufferManager::GetTargetSize(unsigned int *width, unsigned int *height, const EFBRectangle& sourceRc)
Expand Down
4 changes: 2 additions & 2 deletions Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.h
Expand Up @@ -46,15 +46,15 @@ namespace OGL {

struct XFBSource : public XFBSourceBase
{
XFBSource(GLuint rbuf) : renderbuf(rbuf) {}
XFBSource(GLuint tex) : texture(tex) {}
~XFBSource();

void CopyEFB(float Gamma);
void DecodeToTexture(u32 xfbAddr, u32 fbWidth, u32 fbHeight);
void Draw(const MathUtil::Rectangle<float> &sourcerc,
const MathUtil::Rectangle<float> &drawrc, int width, int height) const;

const GLuint renderbuf;
const GLuint texture;
};

inline GLenum getFbType()
Expand Down
2 changes: 0 additions & 2 deletions Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h
Expand Up @@ -32,14 +32,12 @@
#define GL_BGRA GL_RGBA
#define glDrawElementsBaseVertex
#define glDrawRangeElementsBaseVertex
#define GLRENDERBUFFERFORMAT 0x8058 /* RGBA8_OES */
#endif
#else
#define TEX2D GL_TEXTURE_RECTANGLE_ARB
#define PREC
#define TEXTYPE "sampler2DRect"
#define TEXFUNC "texture2DRect"
#define GLRENDERBUFFERFORMAT GL_RGBA
#endif


Expand Down
23 changes: 11 additions & 12 deletions Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp
Expand Up @@ -32,7 +32,7 @@ static GLuint s_texConvFrameBuffer = 0;
static GLuint s_srcTexture = 0; // for decoding from RAM
static GLuint s_srcTextureWidth = 0;
static GLuint s_srcTextureHeight = 0;
static GLuint s_dstRenderBuffer = 0; // for encoding to RAM
static GLuint s_dstTexture = 0; // for encoding to RAM

const int renderBufferWidth = 1024;
const int renderBufferHeight = 1024;
Expand Down Expand Up @@ -159,26 +159,26 @@ void Init()
glEnableVertexAttribArray(SHADER_TEXTURE0_ATTRIB);
glVertexAttribPointer(SHADER_TEXTURE0_ATTRIB, 2, GL_FLOAT, 0, sizeof(GLfloat)*4, (GLfloat*)NULL+2);

glGenRenderbuffers(1, &s_dstRenderBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, s_dstRenderBuffer);

glRenderbufferStorage(GL_RENDERBUFFER, GLRENDERBUFFERFORMAT, renderBufferWidth, renderBufferHeight);

s_srcTextureWidth = 0;
s_srcTextureHeight = 0;

glActiveTexture(GL_TEXTURE0 + 9);
glGenTextures(1, &s_srcTexture);
glBindTexture(getFbType(), s_srcTexture);
glTexParameteri(getFbType(), GL_TEXTURE_MAX_LEVEL, 0);

glGenTextures(1, &s_dstTexture);
glBindTexture(GL_TEXTURE_2D, s_dstTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, renderBufferWidth, renderBufferHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

CreatePrograms();
}

void Shutdown()
{
glDeleteTextures(1, &s_srcTexture);
glDeleteRenderbuffers(1, &s_dstRenderBuffer);
glDeleteTextures(1, &s_dstTexture);
glDeleteFramebuffers(1, &s_texConvFrameBuffer);
glDeleteBuffers(1, &s_encode_VBO );
glDeleteVertexArrays(1, &s_encode_VAO );
Expand All @@ -192,7 +192,7 @@ void Shutdown()
s_encodingPrograms[i].Destroy();

s_srcTexture = 0;
s_dstRenderBuffer = 0;
s_dstTexture = 0;
s_texConvFrameBuffer = 0;
}

Expand All @@ -206,8 +206,7 @@ void EncodeToRamUsingShader(GLuint srcTexture, const TargetRectangle& sourceRc,
// attach render buffer as color destination
FramebufferManager::SetFramebuffer(s_texConvFrameBuffer);

glBindRenderbuffer(GL_RENDERBUFFER, s_dstRenderBuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, s_dstRenderBuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, s_dstTexture, 0);
GL_REPORT_ERRORD();

// set source texture
Expand Down Expand Up @@ -360,7 +359,7 @@ void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc, u8* des


// Should be scale free.
void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destRenderbuf)
void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTexture)
{
u8* srcAddr = Memory::GetPointer(xfbAddr);
if (!srcAddr)
Expand All @@ -376,7 +375,7 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destRender
// switch to texture converter frame buffer
// attach destTexture as color destination
FramebufferManager::SetFramebuffer(s_texConvFrameBuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, destRenderbuf);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, destTexture, 0);

GL_REPORT_FBO_ERROR();

Expand Down
2 changes: 1 addition & 1 deletion Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.h
Expand Up @@ -22,7 +22,7 @@ void Shutdown();
void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc,
u8* destAddr, int dstWidth, int dstHeight);

void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destRenderbuf);
void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTexture);

// 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);
Expand Down

0 comments on commit 64bd6a4

Please sign in to comment.