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.
This commit is contained in:
parent
9dfb127923
commit
64bd6a44d4
|
@ -412,7 +412,7 @@ void FramebufferManager::ReinterpretPixelData(unsigned int convtype)
|
||||||
|
|
||||||
XFBSource::~XFBSource()
|
XFBSource::~XFBSource()
|
||||||
{
|
{
|
||||||
glDeleteRenderbuffers(1, &renderbuf);
|
glDeleteTextures(1, &texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -420,7 +420,7 @@ 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
|
||||||
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,
|
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);
|
||||||
|
@ -430,7 +430,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, renderbuf);
|
TextureConverter::DecodeToTexture(xfbAddr, fbWidth, fbHeight, texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XFBSource::CopyEFB(float Gamma)
|
void XFBSource::CopyEFB(float Gamma)
|
||||||
|
@ -440,7 +440,7 @@ void XFBSource::CopyEFB(float Gamma)
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferManager::GetXFBFramebuffer());
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferManager::GetXFBFramebuffer());
|
||||||
|
|
||||||
// Bind texture.
|
// 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();
|
GL_REPORT_FBO_ERROR();
|
||||||
|
|
||||||
glBlitFramebuffer(
|
glBlitFramebuffer(
|
||||||
|
@ -456,14 +456,16 @@ void XFBSource::CopyEFB(float Gamma)
|
||||||
|
|
||||||
XFBSourceBase* FramebufferManager::CreateXFBSource(unsigned int target_width, unsigned int target_height)
|
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);
|
glActiveTexture(GL_TEXTURE0 + 9);
|
||||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, target_width, target_height);
|
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)
|
void FramebufferManager::GetTargetSize(unsigned int *width, unsigned int *height, const EFBRectangle& sourceRc)
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace OGL {
|
||||||
|
|
||||||
struct XFBSource : public XFBSourceBase
|
struct XFBSource : public XFBSourceBase
|
||||||
{
|
{
|
||||||
XFBSource(GLuint rbuf) : renderbuf(rbuf) {}
|
XFBSource(GLuint tex) : texture(tex) {}
|
||||||
~XFBSource();
|
~XFBSource();
|
||||||
|
|
||||||
void CopyEFB(float Gamma);
|
void CopyEFB(float Gamma);
|
||||||
|
@ -54,7 +54,7 @@ struct XFBSource : public XFBSourceBase
|
||||||
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 renderbuf;
|
const GLuint texture;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline GLenum getFbType()
|
inline GLenum getFbType()
|
||||||
|
|
|
@ -32,14 +32,12 @@
|
||||||
#define GL_BGRA GL_RGBA
|
#define GL_BGRA GL_RGBA
|
||||||
#define glDrawElementsBaseVertex
|
#define glDrawElementsBaseVertex
|
||||||
#define glDrawRangeElementsBaseVertex
|
#define glDrawRangeElementsBaseVertex
|
||||||
#define GLRENDERBUFFERFORMAT 0x8058 /* RGBA8_OES */
|
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#define TEX2D GL_TEXTURE_RECTANGLE_ARB
|
#define TEX2D GL_TEXTURE_RECTANGLE_ARB
|
||||||
#define PREC
|
#define PREC
|
||||||
#define TEXTYPE "sampler2DRect"
|
#define TEXTYPE "sampler2DRect"
|
||||||
#define TEXFUNC "texture2DRect"
|
#define TEXFUNC "texture2DRect"
|
||||||
#define GLRENDERBUFFERFORMAT GL_RGBA
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ static GLuint s_texConvFrameBuffer = 0;
|
||||||
static GLuint s_srcTexture = 0; // for decoding from RAM
|
static GLuint s_srcTexture = 0; // for decoding from RAM
|
||||||
static GLuint s_srcTextureWidth = 0;
|
static GLuint s_srcTextureWidth = 0;
|
||||||
static GLuint s_srcTextureHeight = 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 renderBufferWidth = 1024;
|
||||||
const int renderBufferHeight = 1024;
|
const int renderBufferHeight = 1024;
|
||||||
|
@ -159,11 +159,6 @@ void Init()
|
||||||
glEnableVertexAttribArray(SHADER_TEXTURE0_ATTRIB);
|
glEnableVertexAttribArray(SHADER_TEXTURE0_ATTRIB);
|
||||||
glVertexAttribPointer(SHADER_TEXTURE0_ATTRIB, 2, GL_FLOAT, 0, sizeof(GLfloat)*4, (GLfloat*)NULL+2);
|
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_srcTextureWidth = 0;
|
||||||
s_srcTextureHeight = 0;
|
s_srcTextureHeight = 0;
|
||||||
|
|
||||||
|
@ -171,6 +166,11 @@ void Init()
|
||||||
glGenTextures(1, &s_srcTexture);
|
glGenTextures(1, &s_srcTexture);
|
||||||
glBindTexture(getFbType(), s_srcTexture);
|
glBindTexture(getFbType(), s_srcTexture);
|
||||||
glTexParameteri(getFbType(), GL_TEXTURE_MAX_LEVEL, 0);
|
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();
|
CreatePrograms();
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ void Init()
|
||||||
void Shutdown()
|
void Shutdown()
|
||||||
{
|
{
|
||||||
glDeleteTextures(1, &s_srcTexture);
|
glDeleteTextures(1, &s_srcTexture);
|
||||||
glDeleteRenderbuffers(1, &s_dstRenderBuffer);
|
glDeleteTextures(1, &s_dstTexture);
|
||||||
glDeleteFramebuffers(1, &s_texConvFrameBuffer);
|
glDeleteFramebuffers(1, &s_texConvFrameBuffer);
|
||||||
glDeleteBuffers(1, &s_encode_VBO );
|
glDeleteBuffers(1, &s_encode_VBO );
|
||||||
glDeleteVertexArrays(1, &s_encode_VAO );
|
glDeleteVertexArrays(1, &s_encode_VAO );
|
||||||
|
@ -192,7 +192,7 @@ void Shutdown()
|
||||||
s_encodingPrograms[i].Destroy();
|
s_encodingPrograms[i].Destroy();
|
||||||
|
|
||||||
s_srcTexture = 0;
|
s_srcTexture = 0;
|
||||||
s_dstRenderBuffer = 0;
|
s_dstTexture = 0;
|
||||||
s_texConvFrameBuffer = 0;
|
s_texConvFrameBuffer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,8 +206,7 @@ void EncodeToRamUsingShader(GLuint srcTexture, const TargetRectangle& sourceRc,
|
||||||
// attach render buffer as color destination
|
// attach render buffer as color destination
|
||||||
FramebufferManager::SetFramebuffer(s_texConvFrameBuffer);
|
FramebufferManager::SetFramebuffer(s_texConvFrameBuffer);
|
||||||
|
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, s_dstRenderBuffer);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, s_dstTexture, 0);
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, s_dstRenderBuffer);
|
|
||||||
GL_REPORT_ERRORD();
|
GL_REPORT_ERRORD();
|
||||||
|
|
||||||
// set source texture
|
// set source texture
|
||||||
|
@ -360,7 +359,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 destRenderbuf)
|
void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTexture)
|
||||||
{
|
{
|
||||||
u8* srcAddr = Memory::GetPointer(xfbAddr);
|
u8* srcAddr = Memory::GetPointer(xfbAddr);
|
||||||
if (!srcAddr)
|
if (!srcAddr)
|
||||||
|
@ -376,7 +375,7 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destRender
|
||||||
// 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);
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, destRenderbuf);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, destTexture, 0);
|
||||||
|
|
||||||
GL_REPORT_FBO_ERROR();
|
GL_REPORT_FBO_ERROR();
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,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 destRenderbuf);
|
void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTexture);
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
Loading…
Reference in New Issue