From 32d675c82bee798b8d8e25ed9c98c19ddd2d19d1 Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 2 May 2017 11:46:51 -0700 Subject: [PATCH] Clean up the new code and adress review comments --- libraries/gl/src/gl/Context.cpp | 4 +-- libraries/gpu-gl/src/gpu/gl41/GL41Backend.cpp | 2 ++ libraries/gpu-gl/src/gpu/gl41/GL41Backend.h | 3 +++ .../src/gpu/gl41/GL41BackendTexture.cpp | 26 +++++-------------- libraries/gpu-gl/src/gpu/gl45/GL45Backend.cpp | 2 ++ libraries/gpu-gl/src/gpu/gl45/GL45Backend.h | 3 +++ .../gpu/gl45/GL45BackendVariableTexture.cpp | 4 +-- libraries/gpu/src/gpu/Context.cpp | 4 +++ libraries/gpu/src/gpu/Context.h | 5 ++++ libraries/gpu/src/gpu/Texture.cpp | 2 +- libraries/gpu/src/gpu/Texture.h | 6 ++--- 11 files changed, 33 insertions(+), 28 deletions(-) diff --git a/libraries/gl/src/gl/Context.cpp b/libraries/gl/src/gl/Context.cpp index 64d7dd635b..f7e08e607b 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/GL41Backend.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.cpp index a87d0ad6b8..32bfb777a8 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41Backend.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.cpp @@ -18,6 +18,8 @@ Q_LOGGING_CATEGORY(gpugl41logging, "hifi.gpu.gl41") using namespace gpu; using namespace gpu::gl41; +const std::string GL41Backend::GL41_VERSION { "GL41" }; + void GL41Backend::do_draw(const Batch& batch, size_t paramOffset) { Primitive primitiveType = (Primitive)batch._params[paramOffset + 2]._uint; GLenum mode = gl::PRIMITIVE_TO_GL[primitiveType]; diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h index 3662253a66..4caa29574c 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h +++ b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h @@ -44,6 +44,9 @@ public: explicit GL41Backend(bool syncCache) : Parent(syncCache) {} GL41Backend() : Parent() {} + static const std::string GL41_VERSION; + const std::string& getVersion() const override { return GL41_VERSION; } + class GL41Texture : public GLTexture { using Parent = GLTexture; friend class GL41Backend; diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index 114f61dfc9..87df109d16 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -310,6 +310,8 @@ 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) { + // DestID must be bound to the GL41Backend::RESOURCE_TRANSFER_TEX_UNIT + GLuint fbo { 0 }; glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); @@ -334,22 +336,8 @@ void copyUncompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GL } void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLuint srcId, GLuint destId, uint16_t numMips, uint16_t srcAllocatedMip, uint16_t destAllocatedMip, uint16_t populatedMips) { -#ifdef USE_GL45_COPYIMAGE - for (uint16_t mip = populatedMips; mip < numMips; ++mip) { - auto mipDimensions = texture.evalMipDimensions(mip); - uint16_t targetMip = mip - destAllocatedMip; - uint16_t sourceMip = mip - srcAllocatedMip; - auto faces = GLTexture::getFaceCount(texTarget); - for (uint8_t face = 0; face < faces; ++face) { - glCopyImageSubData( - srcId, texTarget, sourceMip, 0, 0, face, - destId, texTarget, targetMip, 0, 0, face, - mipDimensions.x, mipDimensions.y, 1 - ); - (void)CHECK_GL_ERROR(); - } - } -#else + // DestID must be bound to the GL41Backend::RESOURCE_TRANSFER_TEX_UNIT + struct MipDesc { GLint _faceSize; GLint _size; @@ -361,7 +349,7 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui std::vector bytes; - glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_TEX_UNIT); + glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_EXTRA_TEX_UNIT); glBindTexture(texTarget, srcId); const auto& faceTargets = GLTexture::getFaceTargets(texTarget); GLint internalFormat { 0 }; @@ -399,7 +387,7 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui GLuint pbo { 0 }; glGenBuffers(1, &pbo); glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); - glBufferData(GL_PIXEL_PACK_BUFFER, bufferOffset, nullptr, GL_STREAM_COPY); + glBufferData(GL_PIXEL_PACK_BUFFER, bufferOffset, nullptr, GL_STATIC_COPY); (void)CHECK_GL_ERROR(); // Transfer from source texture to pbo @@ -420,7 +408,6 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_TEX_UNIT); - glBindTexture(texTarget, destId); // Transfer from pbo to new texture for (uint16_t mip = populatedMips; mip < numMips; ++mip) { @@ -443,7 +430,6 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); glDeleteBuffers(1, &pbo); -#endif } void GL41VariableAllocationTexture::promote() { diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.cpp index c9d1fb1b2f..c119e27d5b 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.cpp @@ -18,6 +18,8 @@ Q_LOGGING_CATEGORY(gpugl45logging, "hifi.gpu.gl45") using namespace gpu; using namespace gpu::gl45; +const std::string GL45Backend::GL45_VERSION { "GL45" }; + void GL45Backend::recycle() const { Parent::recycle(); } diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h index dbedd81c76..8319e61382 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h +++ b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h @@ -41,6 +41,9 @@ public: explicit GL45Backend(bool syncCache) : Parent(syncCache) {} GL45Backend() : Parent() {} + static const std::string GL45_VERSION; + const std::string& getVersion() const override { return GL45_VERSION; } + class GL45Texture : public GLTexture { using Parent = GLTexture; friend class GL45Backend; diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp index 3381fa8cce..6ea8d15704 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp @@ -134,7 +134,7 @@ void GL45ResourceTexture::promote() { // copy pre-existing mips uint16_t numMips = _gpuObject.getNumMips(); - copyTexGPUMem(_gpuObject, _target, _id, oldId, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); + copyTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); // destroy the old texture glDeleteTextures(1, &oldId); @@ -158,7 +158,7 @@ void GL45ResourceTexture::demote() { // copy pre-existing mips uint16_t numMips = _gpuObject.getNumMips(); - copyTexGPUMem(_gpuObject, _target, _id, oldId, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); + copyTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); // destroy the old texture glDeleteTextures(1, &oldId); diff --git a/libraries/gpu/src/gpu/Context.cpp b/libraries/gpu/src/gpu/Context.cpp index 0030b2fa88..78fef0af59 100644 --- a/libraries/gpu/src/gpu/Context.cpp +++ b/libraries/gpu/src/gpu/Context.cpp @@ -50,6 +50,10 @@ Context::Context(const Context& context) { Context::~Context() { } +const std::string& Context::getBackendVersion() const { + return _backend->getVersion(); +} + void Context::beginFrame(const glm::mat4& renderPose) { assert(!_frameActive); _frameActive = true; diff --git a/libraries/gpu/src/gpu/Context.h b/libraries/gpu/src/gpu/Context.h index b56255f862..c4b9453df3 100644 --- a/libraries/gpu/src/gpu/Context.h +++ b/libraries/gpu/src/gpu/Context.h @@ -54,6 +54,9 @@ class Backend { public: virtual~ Backend() {}; + + virtual const std::string& getVersion() const = 0; + void setStereoState(const StereoState& stereo) { _stereo = stereo; } virtual void render(const Batch& batch) = 0; @@ -153,6 +156,8 @@ public: Context(); ~Context(); + const std::string& getBackendVersion() const; + void beginFrame(const glm::mat4& renderPose = glm::mat4()); void appendFrameBatch(Batch& batch); FramePointer endFrame(); diff --git a/libraries/gpu/src/gpu/Texture.cpp b/libraries/gpu/src/gpu/Texture.cpp index b12ae5bc97..0f84d2a3c9 100755 --- a/libraries/gpu/src/gpu/Texture.cpp +++ b/libraries/gpu/src/gpu/Texture.cpp @@ -408,7 +408,7 @@ void Texture::setStoredMipFormat(const Element& format) { _storage->setFormat(format); } -const Element Texture::getStoredMipFormat() const { +Element Texture::getStoredMipFormat() const { if (_storage) { return _storage->getFormat(); } else { diff --git a/libraries/gpu/src/gpu/Texture.h b/libraries/gpu/src/gpu/Texture.h index 21a1b0ec57..924c1ee148 100755 --- a/libraries/gpu/src/gpu/Texture.h +++ b/libraries/gpu/src/gpu/Texture.h @@ -285,7 +285,7 @@ public: Stamp bumpStamp() { return ++_stamp; } void setFormat(const Element& format) { _format = format; } - const Element& getFormat() const { return _format; } + Element getFormat() const { return _format; } private: Stamp _stamp { 0 }; @@ -372,7 +372,7 @@ public: bool isColorRenderTarget() const; bool isDepthStencilRenderTarget() const; - const Element getTexelFormat() const { return _texelFormat; } + Element getTexelFormat() const { return _texelFormat; } Vec3u getDimensions() const { return Vec3u(_width, _height, _depth); } uint16 getWidth() const { return _width; } @@ -468,7 +468,7 @@ public: // Mip storage format is constant across all mips void setStoredMipFormat(const Element& format); - const Element getStoredMipFormat() const; + Element getStoredMipFormat() const; // Manually allocate the mips down until the specified maxMip // this is just allocating the sysmem version of it