1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-02 09:03:37 +00:00

Fix GL errors when using EGL image to read pixel from texture

This commit is contained in:
fzurita 2019-11-03 12:01:11 -05:00 committed by Sergey Lipskiy
parent 9059bb38d3
commit e333dea890
2 changed files with 12 additions and 7 deletions

View File

@ -81,12 +81,17 @@ void ColorBufferToRDRAM::_initFBTexture(void)
m_pTexture->height = VI_GetMaxBufferHeight(m_lastBufferWidth);
m_pTexture->textureBytes = m_pTexture->width * m_pTexture->height * fbTexFormat.colorFormatBytes;
TextureTargetParam target = Context::EglImage ? textureTarget::TEXTURE_EXTERNAL : textureTarget::TEXTURE_2D;
m_bufferReader.reset(gfxContext.createColorBufferReader(m_pTexture));
TextureTargetParam target = Context::EglImage ? textureTarget::TEXTURE_EXTERNAL : textureTarget::TEXTURE_2D;
// Skip this since texture is initialized in the EGL color buffer reader
if (!Context::EglImage)
{
Context::InitTextureParams params;
params.handle = m_pTexture->name;
params.target = target;
params.target = textureTarget::TEXTURE_2D;
params.width = m_pTexture->width;
params.height = m_pTexture->height;
params.internalFormat = fbTexFormat.colorInternalFormat;
@ -94,6 +99,7 @@ void ColorBufferToRDRAM::_initFBTexture(void)
params.dataType = fbTexFormat.colorType;
gfxContext.init2DTexture(params);
}
{
Context::TexParameters params;
params.handle = m_pTexture->name;
@ -117,8 +123,6 @@ void ColorBufferToRDRAM::_initFBTexture(void)
assert(!gfxContext.isFramebufferError());
gfxContext.bindFramebuffer(graphics::bufferTarget::DRAW_FRAMEBUFFER, graphics::ObjectHandle::defaultFramebuffer);
m_bufferReader.reset(gfxContext.createColorBufferReader(m_pTexture));
}
void ColorBufferToRDRAM::_destroyFBTexure(void)

View File

@ -35,6 +35,10 @@ void ColorBufferReaderWithEGLImage::_initBuffers()
EGLint eglImgAttrs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE, EGL_NONE };
m_image = eglCreateImageKHR(eglGetDisplay(EGL_DEFAULT_DISPLAY), EGL_NO_CONTEXT,
EGL_NATIVE_BUFFER_ANDROID, m_hardwareBuffer.getClientBuffer(), eglImgAttrs);
m_bindTexture->bind(graphics::Parameter(0), graphics::Parameter(GL_TEXTURE_EXTERNAL_OES), m_pTexture->name);
glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, m_image);
m_bindTexture->bind(graphics::Parameter(0), graphics::Parameter(GL_TEXTURE_EXTERNAL_OES), ObjectHandle());
}
}
@ -48,9 +52,6 @@ const u8 * ColorBufferReaderWithEGLImage::_readPixels(const ReadColorBufferParam
void* gpuData = nullptr;
if (!_params.sync) {
m_bindTexture->bind(graphics::Parameter(0), graphics::Parameter(GL_TEXTURE_EXTERNAL_OES), m_pTexture->name);
glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, m_image);
m_bindTexture->bind(graphics::Parameter(0), graphics::Parameter(GL_TEXTURE_EXTERNAL_OES), ObjectHandle());
m_hardwareBuffer.lock(AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN, &gpuData);
m_bufferLocked = true;
_heightOffset = static_cast<u32>(_params.y0);