diff --git a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp index 1210112a78..c5c9b90eb2 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp @@ -48,7 +48,7 @@ BackendPointer GLBackend::createBackend() { // Where the gpuContext is initialized and where the TRUE Backend is created and assigned auto version = QOpenGLContextWrapper::currentContextVersion(); std::shared_ptr result; - if (!disableOpenGL45 && version >= 0x0405) { + if (false && !disableOpenGL45 && version >= 0x0405) { qCDebug(gpugllogging) << "Using OpenGL 4.5 backend"; result = std::make_shared(); } else { diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index bff5bf3f2c..54d3c87194 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -300,7 +300,7 @@ void GL41VariableAllocationTexture::promote() { // allocate storage for new level allocateStorage(_allocatedMip - std::min(_allocatedMip, 2)); - + /* withPreservedTexture([&] { GLuint fbo { 0 }; glGenFramebuffers(1, &fbo); @@ -325,7 +325,24 @@ void GL41VariableAllocationTexture::promote() { glDeleteFramebuffers(1, &fbo); syncSampler(); - }); + });*/ + + uint16_t mips = _gpuObject.getNumMips(); + // copy pre-existing mips + for (uint16_t mip = _populatedMip; mip < mips; ++mip) { + auto mipDimensions = _gpuObject.evalMipDimensions(mip); + uint16_t targetMip = mip - _allocatedMip; + uint16_t sourceMip = mip - oldAllocatedMip; + auto faces = getFaceCount(_target); + for (uint8_t face = 0; face < faces; ++face) { + glCopyImageSubData( + oldId, _target, sourceMip, 0, 0, face, + _id, _target, targetMip, 0, 0, face, + mipDimensions.x, mipDimensions.y, 1 + ); + (void)CHECK_GL_ERROR(); + } + } // destroy the old texture glDeleteTextures(1, &oldId); @@ -343,7 +360,7 @@ void GL41VariableAllocationTexture::demote() { uint16_t oldAllocatedMip = _allocatedMip; allocateStorage(_allocatedMip + 1); _populatedMip = std::max(_populatedMip, _allocatedMip); - + /* withPreservedTexture([&] { GLuint fbo { 0 }; glCreateFramebuffers(1, &fbo); @@ -368,7 +385,24 @@ void GL41VariableAllocationTexture::demote() { glDeleteFramebuffers(1, &fbo); syncSampler(); - }); + });*/ + + // copy pre-existing mips + uint16_t mips = _gpuObject.getNumMips(); + for (uint16_t mip = _populatedMip; mip < mips; ++mip) { + auto mipDimensions = _gpuObject.evalMipDimensions(mip); + uint16_t targetMip = mip - _allocatedMip; + uint16_t sourceMip = targetMip + 1; + auto faces = getFaceCount(_target); + for (uint8_t face = 0; face < faces; ++face) { + glCopyImageSubData( + oldId, _target, sourceMip, 0, 0, face, + _id, _target, targetMip, 0, 0, face, + mipDimensions.x, mipDimensions.y, 1 + ); + (void)CHECK_GL_ERROR(); + } + } // destroy the old texture diff --git a/libraries/image/src/image/Image.cpp b/libraries/image/src/image/Image.cpp index 707a2e4496..e60187d230 100644 --- a/libraries/image/src/image/Image.cpp +++ b/libraries/image/src/image/Image.cpp @@ -28,9 +28,9 @@ using namespace gpu; #define CPU_MIPMAPS 1 -#define COMPRESS_COLOR_TEXTURES 0 +#define COMPRESS_COLOR_TEXTURES 1 #define COMPRESS_NORMALMAP_TEXTURES 0 // Disable Normalmap compression for now -#define COMPRESS_GRAYSCALE_TEXTURES 0 +#define COMPRESS_GRAYSCALE_TEXTURES 1 #define COMPRESS_CUBEMAP_TEXTURES 0 // Disable Cubemap compression for now static const glm::uvec2 SPARSE_PAGE_SIZE(128);