From 3abd9f21e80c35f5185b4a830e03b679a7d6a798 Mon Sep 17 00:00:00 2001 From: Sam Cake Date: Mon, 1 May 2017 13:50:19 -0700 Subject: [PATCH] Debugging without understanding... --- libraries/gl/src/gl/Context.cpp | 4 +- .../src/gpu/gl41/GL41BackendTexture.cpp | 47 ++++++++++++++++--- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/libraries/gl/src/gl/Context.cpp b/libraries/gl/src/gl/Context.cpp index f7e08e607b..64d7dd635b 100644 --- a/libraries/gl/src/gl/Context.cpp +++ b/libraries/gl/src/gl/Context.cpp @@ -307,12 +307,12 @@ void Context::create() { qApp->setProperty(hifi::properties::gl::PRIMARY_CONTEXT, QVariant::fromValue((void*)PRIMARY)); } - if (enableDebugLogger) { + // if (enableDebugLogger) { makeCurrent(); glDebugMessageCallback(debugMessageCallback, NULL); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB); doneCurrent(); - } + // } } #endif diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index 8c249fc652..31fcf5b2d1 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -309,6 +309,30 @@ void GL41VariableAllocationTexture::syncSampler() const { } +void copyUncompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLuint srcId, GLuint destId, uint16_t numMips, uint16_t srcAllocatedMip, uint16_t destAllocatedMip, uint16_t populatedMips) { + GLuint fbo { 0 }; + glGenFramebuffers(1, &fbo); + glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); + + uint16_t mips = numMips; + // copy pre-existing mips + for (uint16_t mip = populatedMips; mip < mips; ++mip) { + auto mipDimensions = texture.evalMipDimensions(mip); + uint16_t targetMip = mip - destAllocatedMip; + uint16_t sourceMip = mip - srcAllocatedMip; + for (GLenum target : GLTexture::getFaceTargets(texTarget)) { + glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, srcId, sourceMip); + (void)CHECK_GL_ERROR(); + glCopyTexSubImage2D(target, targetMip, 0, 0, 0, 0, mipDimensions.x, mipDimensions.y); + (void)CHECK_GL_ERROR(); + } + } + + // destroy the transfer framebuffer + glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); + glDeleteFramebuffers(1, &fbo); +} + void copyCompressedTexGPUMem(GLenum texTarget, GLuint srcId, GLuint destId, uint16_t numMips, uint16_t srcAllocatedMip, uint16_t destAllocatedMip, uint16_t populatedMips) { GLuint pbo { 0 }; glGenBuffers(1, &pbo); @@ -347,12 +371,14 @@ void copyCompressedTexGPUMem(GLenum texTarget, GLuint srcId, GLuint destId, uint sourceMip._size = (GLint)faceTargets.size() * sourceMip._faceSize; sourceMip._offset = bufferOffset; bufferOffset += sourceMip._size; + gpu::gl::checkGLError(); } (void)CHECK_GL_ERROR(); // Allocate the PBO to accomodate for all the mips to copy glBufferData(GL_PIXEL_PACK_BUFFER, bufferOffset, nullptr, GL_STREAM_COPY); (void)CHECK_GL_ERROR(); + gpu::gl::checkGLError(); // Transfer from source texture to pbo for (uint16_t mip = populatedMips; mip < numMips; ++mip) { @@ -364,6 +390,7 @@ void copyCompressedTexGPUMem(GLenum texTarget, GLuint srcId, GLuint destId, uint glGetCompressedTexImage(faceTargets[f], sourceLevel, (void*)(sourceMip._offset + f * sourceMip._faceSize)); } (void)CHECK_GL_ERROR(); + gpu::gl::checkGLError(); } // Now populate the new texture from the pbo @@ -380,8 +407,9 @@ void copyCompressedTexGPUMem(GLenum texTarget, GLuint srcId, GLuint destId, uint uint16_t destLevel = mip - destAllocatedMip; for (GLint f = 0; f < faceTargets.size(); f++) { - glCompressedTexImage2D(faceTargets[f], destLevel, internalFormat, sourceMip._width, sourceMip._height, 0, + glCompressedTexSubImage2D(faceTargets[f], destLevel,0, 0, sourceMip._width, sourceMip._height, internalFormat, sourceMip._faceSize, (void*)(sourceMip._offset + f * sourceMip._faceSize)); + gpu::gl::checkGLError(); } } @@ -405,6 +433,8 @@ void GL41VariableAllocationTexture::promote() { // allocate storage for new level allocateStorage(targetAllocatedMip); + uint16_t numMips = _gpuObject.getNumMips(); + if (_texelFormat.isCompressed()) { #if defined(USE_45IMAGECOPY_PROMOTE) withPreservedTexture([&] { @@ -427,7 +457,6 @@ void GL41VariableAllocationTexture::promote() { syncSampler(); }); #else - uint16_t numMips = _gpuObject.getNumMips(); withPreservedTexture([&] { copyCompressedTexGPUMem(_target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); syncSampler(); @@ -435,7 +464,8 @@ void GL41VariableAllocationTexture::promote() { #endif } else { withPreservedTexture([&] { - GLuint fbo { 0 }; + copyUncompressedTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); + /* GLuint fbo { 0 }; glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); @@ -456,7 +486,7 @@ void GL41VariableAllocationTexture::promote() { // destroy the transfer framebuffer glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); glDeleteFramebuffers(1, &fbo); - + */ syncSampler(); }); } @@ -478,6 +508,8 @@ void GL41VariableAllocationTexture::demote() { allocateStorage(_allocatedMip + 1); _populatedMip = std::max(_populatedMip, _allocatedMip); + uint16_t numMips = _gpuObject.getNumMips(); + if (_texelFormat.isCompressed()) { #if defined(USE_45IMAGECOPY_DEMOTE) withPreservedTexture([&] { @@ -500,7 +532,6 @@ void GL41VariableAllocationTexture::demote() { syncSampler(); }); #else - uint16_t numMips = _gpuObject.getNumMips(); withPreservedTexture([&] { copyCompressedTexGPUMem(_target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); syncSampler(); @@ -508,7 +539,9 @@ void GL41VariableAllocationTexture::demote() { #endif } else { withPreservedTexture([&] { - GLuint fbo { 0 }; + copyUncompressedTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); + + /* GLuint fbo { 0 }; glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); @@ -529,7 +562,7 @@ void GL41VariableAllocationTexture::demote() { // destroy the transfer framebuffer glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); glDeleteFramebuffers(1, &fbo); - +*/ syncSampler(); }); }