mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-07 03:13:49 +00:00
Add ColorBufferReaderWithEGLImage for GLES2
This commit is contained in:
parent
ff0d0d59b4
commit
acec086c38
|
@ -0,0 +1,82 @@
|
|||
#ifdef EGL
|
||||
|
||||
#include <GBI.h>
|
||||
#include <Graphics/Context.h>
|
||||
#include "opengl_ColorBufferReaderWithEGLImage.h"
|
||||
|
||||
using namespace opengl;
|
||||
using namespace graphics;
|
||||
|
||||
ColorBufferReaderWithEGLImage::ColorBufferReaderWithEGLImage(CachedTexture *_pTexture, CachedBindTexture *_bindTexture)
|
||||
: graphics::ColorBufferReader(_pTexture)
|
||||
, m_bindTexture(_bindTexture)
|
||||
{
|
||||
m_glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES");
|
||||
m_window = new GraphicBuffer();
|
||||
_initBuffers();
|
||||
}
|
||||
|
||||
|
||||
ColorBufferReaderWithEGLImage::~ColorBufferReaderWithEGLImage()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ColorBufferReaderWithEGLImage::_initBuffers()
|
||||
{
|
||||
m_window->reallocate(m_pTexture->realWidth, m_pTexture->realHeight,
|
||||
PIXEL_FORMAT_RGBA_8888, GraphicBuffer::USAGE_SW_READ_OFTEN | GraphicBuffer::USAGE_HW_TEXTURE);
|
||||
EGLint eglImgAttrs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE, EGL_NONE };
|
||||
|
||||
if(m_image == 0)
|
||||
{
|
||||
m_image = eglCreateImageKHR(eglGetDisplay(EGL_DEFAULT_DISPLAY), EGL_NO_CONTEXT,
|
||||
EGL_NATIVE_BUFFER_ANDROID, (EGLClientBuffer)m_window->getNativeBuffer(), eglImgAttrs);
|
||||
}
|
||||
}
|
||||
|
||||
u8 * ColorBufferReaderWithEGLImage::readPixels(s32 _x0, s32 _y0, u32 _width, u32 _height, u32 _size, bool _sync)
|
||||
{
|
||||
const graphics::FramebufferTextureFormats & fbTexFormat = gfxContext.getFramebufferTextureFormats();
|
||||
GLenum colorFormat, colorType, colorFormatBytes;
|
||||
if (_size > G_IM_SIZ_8b) {
|
||||
colorFormat = GLenum(fbTexFormat.colorFormat);
|
||||
colorType = GLenum(fbTexFormat.colorType);
|
||||
colorFormatBytes = GLenum(fbTexFormat.colorFormatBytes);
|
||||
}
|
||||
else {
|
||||
colorFormat = GLenum(fbTexFormat.monochromeFormat);
|
||||
colorType = GLenum(fbTexFormat.monochromeType);
|
||||
colorFormatBytes = GLenum(fbTexFormat.monochromeFormatBytes);
|
||||
}
|
||||
|
||||
u8* pixelData = m_pixelData.data();
|
||||
|
||||
if (!_sync) {
|
||||
void* ptr;
|
||||
|
||||
m_bindTexture->bind(Parameter(GL_TEXTURE_2D), m_pTexture->name);
|
||||
m_glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, m_image);
|
||||
m_bindTexture->bind(Parameter(GL_TEXTURE_2D), ObjectHandle());
|
||||
int widthBytes = _width*colorFormatBytes;
|
||||
int strideBytes = m_pTexture->realWidth * colorFormatBytes;
|
||||
|
||||
m_window->lock(GraphicBuffer::USAGE_SW_READ_OFTEN, &ptr);
|
||||
|
||||
for (unsigned int lnIndex = 0; lnIndex < _height; ++lnIndex) {
|
||||
memcpy(pixelData + lnIndex*widthBytes, reinterpret_cast<char*>(ptr) + ((lnIndex + _y0)*strideBytes), widthBytes);
|
||||
}
|
||||
|
||||
m_window->unlock();
|
||||
} else {
|
||||
glReadPixels(_x0, _y0, _width, _height, colorFormat, colorType, pixelData);
|
||||
}
|
||||
|
||||
return pixelData;
|
||||
}
|
||||
|
||||
void ColorBufferReaderWithEGLImage::cleanUp()
|
||||
{
|
||||
}
|
||||
|
||||
#endif // EGL
|
|
@ -0,0 +1,39 @@
|
|||
#pragma once
|
||||
#ifdef EGL
|
||||
#include <Graphics/ColorBufferReader.h>
|
||||
#include "opengl_CachedFunctions.h"
|
||||
|
||||
#include <ui/GraphicBuffer.h>
|
||||
#include <android/native_window.h>
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
typedef void (GL_APIENTRY* PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, EGLImageKHR image);
|
||||
typedef void (GL_APIENTRY* PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC) (GLenum target, EGLImageKHR image);
|
||||
|
||||
using namespace android;
|
||||
|
||||
namespace opengl {
|
||||
|
||||
class ColorBufferReaderWithEGLImage : public graphics::ColorBufferReader
|
||||
{
|
||||
public:
|
||||
ColorBufferReaderWithEGLImage(CachedTexture * _pTexture,
|
||||
CachedBindTexture * _bindTexture);
|
||||
~ColorBufferReaderWithEGLImage();
|
||||
|
||||
u8 * readPixels(s32 _x0, s32 _y0, u32 _width, u32 _height, u32 _size, bool _sync) override;
|
||||
void cleanUp() override;
|
||||
|
||||
private:
|
||||
void _initBuffers();
|
||||
|
||||
CachedBindTexture * m_bindTexture;
|
||||
GraphicBuffer* m_window;
|
||||
EGLImageKHR m_image;
|
||||
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC m_glEGLImageTargetTexture2DOES;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //EGL
|
|
@ -6,6 +6,7 @@
|
|||
#include "opengl_DummyTextDrawer.h"
|
||||
#include "opengl_ColorBufferReaderWithPixelBuffer.h"
|
||||
#include "opengl_ColorBufferReaderWithBufferStorage.h"
|
||||
#include "opengl_ColorBufferReaderWithEGLImage.h"
|
||||
#include "opengl_Utils.h"
|
||||
#include "GLSL/glsl_CombinerProgramBuilder.h"
|
||||
#include "GLSL/glsl_SpecialShadersFactory.h"
|
||||
|
@ -267,6 +268,10 @@ graphics::PixelReadBuffer * ContextImpl::createPixelReadBuffer(size_t _sizeInByt
|
|||
|
||||
graphics::ColorBufferReader * ContextImpl::createColorBufferReader(CachedTexture * _pTexture)
|
||||
{
|
||||
#ifdef EGL
|
||||
return new ColorBufferReaderWithEGLImage(_pTexture, m_cachedFunctions->getCachedBindTexture());
|
||||
#endif
|
||||
|
||||
if (glBufferStorage != nullptr && glMemoryBarrier != nullptr)
|
||||
return new ColorBufferReaderWithBufferStorage(_pTexture, m_cachedFunctions->getCachedBindBuffer());
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user