From 25edb44b75b8ce03fc8094a429d3eac6b272416f Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 30 Mar 2017 15:15:14 -0700 Subject: [PATCH] Fix the problem with the cursor and scattering, --- .../src/gpu/gl41/GL41BackendTexture.cpp | 28 +++++++++++++++++-- libraries/gpu/src/gpu/Context.cpp | 8 +++--- .../surfaceGeometry_downsampleDepthNormal.slf | 8 +++--- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index 5aa0c42ee4..61db54bf7b 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -45,11 +45,22 @@ GLTexture* GL41Backend::syncGPUObject(const TexturePointer& texturePointer) { // If the object hasn't been created, or the object definition is out of date, drop and re-create GL41Texture* object = Backend::getGPUObject(texture); + if (!object || object->_storageStamp < texture.getStamp()) { // This automatically any previous texture object = new GL41Texture(shared_from_this(), texture); - } + object->withPreservedTexture([&] { + if (object->_contentStamp <= texture.getDataStamp()) { + // FIXME implement synchronous texture transfer here + object->syncContent(); + } + if (object->_samplerStamp <= texture.getSamplerStamp()) { + object->syncSampler(); + } + }); + } + /* // FIXME internalize to GL41Texture 'sync' function if (object->isOutdated()) { object->withPreservedTexture([&] { @@ -62,7 +73,7 @@ GLTexture* GL41Backend::syncGPUObject(const TexturePointer& texturePointer) { object->syncSampler(); } }); - } + }*/ return object; } @@ -93,6 +104,13 @@ GL41Texture::GL41Texture(const std::weak_ptr& backend, const Texture& ++face; } } + glTexParameteri(_target, GL_TEXTURE_BASE_LEVEL, 0); + glTexParameteri(_target, GL_TEXTURE_MAX_LEVEL, numMips - 1); + + if (texture.isAutogenerateMips()) { + glGenerateMipmap(_target); + (void)CHECK_GL_ERROR(); + } }); } @@ -111,6 +129,7 @@ bool GL41Texture::isOutdated() const { } void GL41Texture::withPreservedTexture(std::function f) const { + GLint transferUnit = 32; GLint boundTex = -1; switch (_target) { case GL_TEXTURE_2D: @@ -126,9 +145,12 @@ void GL41Texture::withPreservedTexture(std::function f) const { } (void)CHECK_GL_ERROR(); + glActiveTexture(GL_TEXTURE0 + transferUnit); + (void)CHECK_GL_ERROR(); + glBindTexture(_target, _texture); f(); - glBindTexture(_target, boundTex); + glBindTexture(_target, 0); (void)CHECK_GL_ERROR(); } diff --git a/libraries/gpu/src/gpu/Context.cpp b/libraries/gpu/src/gpu/Context.cpp index cc570f696f..0030b2fa88 100644 --- a/libraries/gpu/src/gpu/Context.cpp +++ b/libraries/gpu/src/gpu/Context.cpp @@ -265,7 +265,7 @@ void Context::incrementBufferGPUCount() { auto total = ++_bufferGPUCount; if (total > max.load()) { max = total; - qCDebug(gpulogging) << "New max GPU buffers " << total; + // qCDebug(gpulogging) << "New max GPU buffers " << total; } } void Context::decrementBufferGPUCount() { @@ -299,7 +299,7 @@ void Context::incrementTextureGPUCount() { auto total = ++_textureGPUCount; if (total > max.load()) { max = total; - qCDebug(gpulogging) << "New max GPU textures " << total; + // qCDebug(gpulogging) << "New max GPU textures " << total; } } void Context::decrementTextureGPUCount() { @@ -311,7 +311,7 @@ void Context::incrementTextureGPUSparseCount() { auto total = ++_textureGPUSparseCount; if (total > max.load()) { max = total; - qCDebug(gpulogging) << "New max GPU textures " << total; + // qCDebug(gpulogging) << "New max GPU textures " << total; } } void Context::decrementTextureGPUSparseCount() { @@ -378,7 +378,7 @@ void Context::incrementTextureGPUTransferCount() { auto total = ++_textureGPUTransferCount; if (total > max.load()) { max = total; - qCDebug(gpulogging) << "New max GPU textures transfers" << total; + // qCDebug(gpulogging) << "New max GPU textures transfers" << total; } } diff --git a/libraries/render-utils/src/surfaceGeometry_downsampleDepthNormal.slf b/libraries/render-utils/src/surfaceGeometry_downsampleDepthNormal.slf index 46554dd7f8..205dad124e 100644 --- a/libraries/render-utils/src/surfaceGeometry_downsampleDepthNormal.slf +++ b/libraries/render-utils/src/surfaceGeometry_downsampleDepthNormal.slf @@ -21,17 +21,17 @@ out vec4 outLinearDepth; out vec4 outNormal; void main(void) { - // Gather 2 by 2 quads from texture + // Gather 2 by 2 quads from texture and downsample // Try different filters for Z - //vec4 Zeyes = textureGather(linearDepthMap, varTexCoord0, 0); - //float Zeye = min(min(Zeyes.x, Zeyes.y), min(Zeyes.z, Zeyes.w)); - float Zeye = texture(linearDepthMap, varTexCoord0).x; + vec4 Zeyes = textureGather(linearDepthMap, varTexCoord0, 0); + // float Zeye = texture(linearDepthMap, varTexCoord0).x; vec4 rawNormalsX = textureGather(normalMap, varTexCoord0, 0); vec4 rawNormalsY = textureGather(normalMap, varTexCoord0, 1); vec4 rawNormalsZ = textureGather(normalMap, varTexCoord0, 2); + float Zeye = min(min(Zeyes.x, Zeyes.y), min(Zeyes.z, Zeyes.w)); vec3 normal = vec3(0.0); normal += unpackNormal(vec3(rawNormalsX[0], rawNormalsY[0], rawNormalsZ[0]));