Revive texture download code and fix it on GLES

This commit is contained in:
sfan5 2024-11-08 12:08:48 +01:00
parent 11837d4623
commit 3c42cc8684
2 changed files with 16 additions and 22 deletions

@ -74,9 +74,7 @@ enum E_TEXTURE_CREATION_FLAG
//! Allow the driver to keep a copy of the texture in memory
/** Enabling this makes calls to ITexture::lock a lot faster, but costs main memory.
Currently only used in combination with OpenGL drivers.
NOTE: Disabling this does not yet work correctly with alpha-textures.
So the default is on for now (but might change with Irrlicht 1.9 if we get the alpha-troubles fixed).
This is enabled by default.
*/
ETCF_ALLOW_MEMORY_COPY = 0x00000080,

@ -261,7 +261,14 @@ public:
if (LockImage && mode != ETLM_WRITE_ONLY) {
bool passed = true;
#ifdef IRR_COMPILE_GL_COMMON
#ifdef IRR_COMPILE_GL_COMMON // legacy driver
constexpr bool use_gl_impl = true;
#else
const bool use_gl_impl = Driver->Version.Spec != OpenGLSpec::ES;
#endif
if (use_gl_impl) {
IImage *tmpImage = LockImage; // not sure yet if the size required by glGetTexImage is always correct, if not we might have to allocate a different tmpImage and convert colors later on.
Driver->getCacheHandler()->getTextureCache().set(0, this);
@ -296,38 +303,26 @@ public:
delete[] tmpBuffer;
}
#elif defined(IRR_COMPILE_GLES2_COMMON)
// TODO: revive this code
COpenGLCoreTexture *tmpTexture = new COpenGLCoreTexture("OGL_CORE_LOCK_TEXTURE", Size, ETT_2D, ColorFormat, Driver);
} else {
GLuint tmpFBO = 0;
Driver->irrGlGenFramebuffers(1, &tmpFBO);
GLint prevViewportX = 0;
GLint prevViewportY = 0;
GLsizei prevViewportWidth = 0;
GLsizei prevViewportHeight = 0;
Driver->getCacheHandler()->getViewport(prevViewportX, prevViewportY, prevViewportWidth, prevViewportHeight);
Driver->getCacheHandler()->setViewport(0, 0, Size.Width, Size.Height);
GLuint prevFBO = 0;
Driver->getCacheHandler()->getFBO(prevFBO);
Driver->getCacheHandler()->setFBO(tmpFBO);
Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tmpTexture->getOpenGLTextureName(), 0);
GL.Clear(GL_COLOR_BUFFER_BIT);
Driver->draw2DImage(this, layer, true);
Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, getOpenGLTextureName(), 0);
IImage *tmpImage = Driver->createImage(ECF_A8R8G8B8, Size);
GL.ReadPixels(0, 0, Size.Width, Size.Height, GL_RGBA, GL_UNSIGNED_BYTE, tmpImage->getData());
Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
Driver->getCacheHandler()->setFBO(prevFBO);
Driver->getCacheHandler()->setViewport(prevViewportX, prevViewportY, prevViewportWidth, prevViewportHeight);
Driver->irrGlDeleteFramebuffers(1, &tmpFBO);
delete tmpTexture;
void *src = tmpImage->getData();
void *dest = LockImage->getData();
@ -350,7 +345,8 @@ public:
break;
}
tmpImage->drop();
#endif
}
if (!passed) {
LockImage->drop();