mirror of
https://github.com/minetest/minetest.git
synced 2025-01-10 23:37:29 +01:00
Revive texture download code and fix it on GLES
This commit is contained in:
parent
11837d4623
commit
3c42cc8684
@ -74,9 +74,7 @@ enum E_TEXTURE_CREATION_FLAG
|
|||||||
|
|
||||||
//! Allow the driver to keep a copy of the texture in memory
|
//! 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.
|
/** Enabling this makes calls to ITexture::lock a lot faster, but costs main memory.
|
||||||
Currently only used in combination with OpenGL drivers.
|
This is enabled by default.
|
||||||
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).
|
|
||||||
*/
|
*/
|
||||||
ETCF_ALLOW_MEMORY_COPY = 0x00000080,
|
ETCF_ALLOW_MEMORY_COPY = 0x00000080,
|
||||||
|
|
||||||
|
@ -261,7 +261,14 @@ public:
|
|||||||
if (LockImage && mode != ETLM_WRITE_ONLY) {
|
if (LockImage && mode != ETLM_WRITE_ONLY) {
|
||||||
bool passed = true;
|
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.
|
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);
|
Driver->getCacheHandler()->getTextureCache().set(0, this);
|
||||||
@ -296,38 +303,26 @@ public:
|
|||||||
|
|
||||||
delete[] tmpBuffer;
|
delete[] tmpBuffer;
|
||||||
}
|
}
|
||||||
#elif defined(IRR_COMPILE_GLES2_COMMON)
|
|
||||||
// TODO: revive this code
|
} else {
|
||||||
COpenGLCoreTexture *tmpTexture = new COpenGLCoreTexture("OGL_CORE_LOCK_TEXTURE", Size, ETT_2D, ColorFormat, Driver);
|
|
||||||
|
|
||||||
GLuint tmpFBO = 0;
|
GLuint tmpFBO = 0;
|
||||||
Driver->irrGlGenFramebuffers(1, &tmpFBO);
|
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;
|
GLuint prevFBO = 0;
|
||||||
Driver->getCacheHandler()->getFBO(prevFBO);
|
Driver->getCacheHandler()->getFBO(prevFBO);
|
||||||
Driver->getCacheHandler()->setFBO(tmpFBO);
|
Driver->getCacheHandler()->setFBO(tmpFBO);
|
||||||
|
|
||||||
Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tmpTexture->getOpenGLTextureName(), 0);
|
Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, getOpenGLTextureName(), 0);
|
||||||
|
|
||||||
GL.Clear(GL_COLOR_BUFFER_BIT);
|
|
||||||
|
|
||||||
Driver->draw2DImage(this, layer, true);
|
|
||||||
|
|
||||||
IImage *tmpImage = Driver->createImage(ECF_A8R8G8B8, Size);
|
IImage *tmpImage = Driver->createImage(ECF_A8R8G8B8, Size);
|
||||||
GL.ReadPixels(0, 0, Size.Width, Size.Height, GL_RGBA, GL_UNSIGNED_BYTE, tmpImage->getData());
|
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()->setFBO(prevFBO);
|
||||||
Driver->getCacheHandler()->setViewport(prevViewportX, prevViewportY, prevViewportWidth, prevViewportHeight);
|
|
||||||
|
|
||||||
Driver->irrGlDeleteFramebuffers(1, &tmpFBO);
|
Driver->irrGlDeleteFramebuffers(1, &tmpFBO);
|
||||||
delete tmpTexture;
|
|
||||||
|
|
||||||
void *src = tmpImage->getData();
|
void *src = tmpImage->getData();
|
||||||
void *dest = LockImage->getData();
|
void *dest = LockImage->getData();
|
||||||
@ -350,7 +345,8 @@ public:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
tmpImage->drop();
|
tmpImage->drop();
|
||||||
#endif
|
|
||||||
|
}
|
||||||
|
|
||||||
if (!passed) {
|
if (!passed) {
|
||||||
LockImage->drop();
|
LockImage->drop();
|
||||||
|
Loading…
Reference in New Issue
Block a user