diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 84aa0328b0..4f58cf73db 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -139,7 +139,7 @@ if (WIN32) endif() # link required hifi libraries -link_hifi_libraries(shared octree gpu gl procedural model render +link_hifi_libraries(shared octree gpu gl gpu-gl procedural model render recording fbx networking model-networking entities avatars audio audio-client animation script-engine physics render-utils entities-renderer ui auto-updater diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 10694eb5d4..9465ed1535 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -60,7 +60,7 @@ #include #include #include -#include +#include #include #include #include @@ -1262,8 +1262,7 @@ void Application::initializeGL() { _isGLInitialized = true; } - // Where the gpuContext is initialized and where the TRUE Backend is created and assigned - gpu::Context::init(); + gpu::Context::init(); _gpuContext = std::make_shared(); // The gpu context can make child contexts for transfers, so // we need to restore primary rendering context diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 02b2de8838..2395f62468 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -13,12 +13,12 @@ #include #include -#include #include #include #include #include #include +#include #include "AudioClient.h" #include "audio/AudioScope.h" @@ -55,7 +55,6 @@ ApplicationOverlay::~ApplicationOverlay() { // Renders the overlays either to a texture or to the screen void ApplicationOverlay::renderOverlay(RenderArgs* renderArgs) { PROFILE_RANGE(__FUNCTION__); - CHECK_GL_ERROR(); PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "ApplicationOverlay::displayOverlay()"); buildFramebufferObject(); @@ -89,8 +88,6 @@ void ApplicationOverlay::renderOverlay(RenderArgs* renderArgs) { }); renderArgs->_batch = nullptr; // so future users of renderArgs don't try to use our batch - - CHECK_GL_ERROR(); } void ApplicationOverlay::renderQmlUi(RenderArgs* renderArgs) { @@ -295,10 +292,6 @@ gpu::TexturePointer ApplicationOverlay::acquireOverlay() { return gpu::TexturePointer(); } auto result = _overlayFramebuffer->getRenderBuffer(0); - auto textureId = gpu::GLBackend::getTextureID(result, false); - if (!textureId) { - qDebug() << "Missing texture"; - } _overlayFramebuffer->setRenderBuffer(0, gpu::TexturePointer()); return result; } diff --git a/libraries/display-plugins/CMakeLists.txt b/libraries/display-plugins/CMakeLists.txt index cfa2ac0710..f2d58d825e 100644 --- a/libraries/display-plugins/CMakeLists.txt +++ b/libraries/display-plugins/CMakeLists.txt @@ -1,6 +1,6 @@ set(TARGET_NAME display-plugins) setup_hifi_library(OpenGL) -link_hifi_libraries(shared plugins gl ui) +link_hifi_libraries(shared plugins gl gpu-gl ui) target_opengl() diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index a0b6ae3939..d34b698410 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -17,7 +17,7 @@ #include #include - +#include #include #include #include @@ -26,7 +26,6 @@ #include #include #include -#include #include #include "CompositorHelper.h" @@ -629,14 +628,15 @@ uint32_t OpenGLDisplayPlugin::getSceneTextureId() const { if (!_currentSceneTexture) { return 0; } - return gpu::GLBackend::getTextureID(_currentSceneTexture, false); + + return _currentSceneTexture->getHardwareId(); } uint32_t OpenGLDisplayPlugin::getOverlayTextureId() const { if (!_currentOverlayTexture) { return 0; } - return gpu::GLBackend::getTextureID(_currentOverlayTexture, false); + return _currentOverlayTexture->getHardwareId(); } void OpenGLDisplayPlugin::eyeViewport(Eye eye) const { diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp index 372337ae4d..4e594d89ed 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp @@ -16,7 +16,6 @@ #include #include -#include #include #include #include diff --git a/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.cpp index 66a4ba4835..6c6716c8fa 100644 --- a/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include #include diff --git a/libraries/gl/src/gl/Config.h b/libraries/gl/src/gl/Config.h index 8f7582c271..593537a291 100644 --- a/libraries/gl/src/gl/Config.h +++ b/libraries/gl/src/gl/Config.h @@ -12,47 +12,21 @@ #ifndef hifi_gpu_GPUConfig_h #define hifi_gpu_GPUConfig_h - #define GL_GLEXT_PROTOTYPES 1 -#define GPU_CORE 1 -#define GPU_LEGACY 0 -#define GPU_CORE_41 410 -#define GPU_CORE_43 430 -#define GPU_CORE_MINIMUM GPU_CORE_41 - -#if defined(__APPLE__) - #include -#define GPU_FEATURE_PROFILE GPU_CORE -#define GPU_INPUT_PROFILE GPU_CORE_41 +#if defined(__APPLE__) #include #include -#elif defined(WIN32) -#include +#endif + +#if defined(WIN32) + #include -#define GPU_FEATURE_PROFILE GPU_CORE -#define GPU_INPUT_PROFILE GPU_CORE_43 - -#else - -#include - -#define GPU_FEATURE_PROFILE GPU_CORE -#define GPU_INPUT_PROFILE GPU_CORE_43 - #endif - -#if (GPU_INPUT_PROFILE == GPU_CORE_43) -// Deactivate SSBO for now, we've run into some issues -// on GL 4.3 capable GPUs not behaving as expected -//#define GPU_SSBO_DRAW_CALL_INFO -#endif - - #endif // hifi_gpu_GPUConfig_h diff --git a/libraries/gl/src/gl/OpenGLVersionChecker.cpp b/libraries/gl/src/gl/OpenGLVersionChecker.cpp index 843385f720..ed33dc1ab9 100644 --- a/libraries/gl/src/gl/OpenGLVersionChecker.cpp +++ b/libraries/gl/src/gl/OpenGLVersionChecker.cpp @@ -19,6 +19,8 @@ #include "GLWidget.h" #include "GLHelpers.h" +#define MINIMUM_GL_VERSION 410 + OpenGLVersionChecker::OpenGLVersionChecker(int& argc, char** argv) : QApplication(argc, argv) { @@ -58,8 +60,8 @@ QJsonObject OpenGLVersionChecker::checkVersion(bool& valid, bool& override) { QStringList versionParts = glVersion.split(QRegularExpression("[\\.\\s]")); int majorNumber = versionParts[0].toInt(); int minorNumber = versionParts[1].toInt(); - int minimumMajorNumber = GPU_CORE_MINIMUM / 100; - int minimumMinorNumber = (GPU_CORE_MINIMUM - minimumMajorNumber * 100) / 10; + int minimumMajorNumber = MINIMUM_GL_VERSION / 100; + int minimumMinorNumber = (MINIMUM_GL_VERSION - minimumMajorNumber * 100) / 10; valid = (majorNumber > minimumMajorNumber || (majorNumber == minimumMajorNumber && minorNumber >= minimumMinorNumber)); diff --git a/libraries/gl/src/gl/QOpenGLContextWrapper.cpp b/libraries/gl/src/gl/QOpenGLContextWrapper.cpp index 8c9a1ba113..bc8afc3927 100644 --- a/libraries/gl/src/gl/QOpenGLContextWrapper.cpp +++ b/libraries/gl/src/gl/QOpenGLContextWrapper.cpp @@ -13,6 +13,17 @@ #include +uint32_t QOpenGLContextWrapper::currentContextVersion() { + QOpenGLContext* context = QOpenGLContext::currentContext(); + if (!context) { + return 0; + } + auto format = context->format(); + auto version = (format.majorVersion() << 8) + format.minorVersion(); + return version; +} + + QOpenGLContext* QOpenGLContextWrapper::currentContext() { return QOpenGLContext::currentContext(); } diff --git a/libraries/gl/src/gl/QOpenGLContextWrapper.h b/libraries/gl/src/gl/QOpenGLContextWrapper.h index 33cc0b25e9..d097284e68 100644 --- a/libraries/gl/src/gl/QOpenGLContextWrapper.h +++ b/libraries/gl/src/gl/QOpenGLContextWrapper.h @@ -12,6 +12,8 @@ #ifndef hifi_QOpenGLContextWrapper_h #define hifi_QOpenGLContextWrapper_h +#include + class QOpenGLContext; class QSurface; class QSurfaceFormat; @@ -30,6 +32,7 @@ public: void moveToThread(QThread* thread); static QOpenGLContext* currentContext(); + static uint32_t currentContextVersion(); QOpenGLContext* getContext() { return _context; diff --git a/libraries/gpu-gl/CMakeLists.txt b/libraries/gpu-gl/CMakeLists.txt new file mode 100644 index 0000000000..dfac6dd516 --- /dev/null +++ b/libraries/gpu-gl/CMakeLists.txt @@ -0,0 +1,8 @@ +set(TARGET_NAME gpu-gl) +AUTOSCRIBE_SHADER_LIB(gpu) +setup_hifi_library() +link_hifi_libraries(shared gl gpu) +GroupSources("src") + +target_glew() +target_opengl() \ No newline at end of file diff --git a/libraries/gpu/src/gpu/GLBackend.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp similarity index 83% rename from libraries/gpu/src/gpu/GLBackend.cpp rename to libraries/gpu-gl/src/gpu/gl/GLBackend.cpp index 728d18bd8e..69699e673b 100644 --- a/libraries/gpu/src/gpu/GLBackend.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp @@ -8,112 +8,133 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "GLBackendShared.h" +#include "GLBackend.h" #include #include #include +#include #include -#include -#include #if defined(NSIGHT_FOUND) #include "nvToolsExt.h" #endif +#include +#include +#include "GLBackendShared.h" using namespace gpu; +using namespace gpu::gl; GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] = { - (&::gpu::GLBackend::do_draw), - (&::gpu::GLBackend::do_drawIndexed), - (&::gpu::GLBackend::do_drawInstanced), - (&::gpu::GLBackend::do_drawIndexedInstanced), - (&::gpu::GLBackend::do_multiDrawIndirect), - (&::gpu::GLBackend::do_multiDrawIndexedIndirect), + (&::gpu::gl::GLBackend::do_draw), + (&::gpu::gl::GLBackend::do_drawIndexed), + (&::gpu::gl::GLBackend::do_drawInstanced), + (&::gpu::gl::GLBackend::do_drawIndexedInstanced), + (&::gpu::gl::GLBackend::do_multiDrawIndirect), + (&::gpu::gl::GLBackend::do_multiDrawIndexedIndirect), - (&::gpu::GLBackend::do_setInputFormat), - (&::gpu::GLBackend::do_setInputBuffer), - (&::gpu::GLBackend::do_setIndexBuffer), - (&::gpu::GLBackend::do_setIndirectBuffer), + (&::gpu::gl::GLBackend::do_setInputFormat), + (&::gpu::gl::GLBackend::do_setInputBuffer), + (&::gpu::gl::GLBackend::do_setIndexBuffer), + (&::gpu::gl::GLBackend::do_setIndirectBuffer), - (&::gpu::GLBackend::do_setModelTransform), - (&::gpu::GLBackend::do_setViewTransform), - (&::gpu::GLBackend::do_setProjectionTransform), - (&::gpu::GLBackend::do_setViewportTransform), - (&::gpu::GLBackend::do_setDepthRangeTransform), + (&::gpu::gl::GLBackend::do_setModelTransform), + (&::gpu::gl::GLBackend::do_setViewTransform), + (&::gpu::gl::GLBackend::do_setProjectionTransform), + (&::gpu::gl::GLBackend::do_setViewportTransform), + (&::gpu::gl::GLBackend::do_setDepthRangeTransform), - (&::gpu::GLBackend::do_setPipeline), - (&::gpu::GLBackend::do_setStateBlendFactor), - (&::gpu::GLBackend::do_setStateScissorRect), + (&::gpu::gl::GLBackend::do_setPipeline), + (&::gpu::gl::GLBackend::do_setStateBlendFactor), + (&::gpu::gl::GLBackend::do_setStateScissorRect), - (&::gpu::GLBackend::do_setUniformBuffer), - (&::gpu::GLBackend::do_setResourceTexture), + (&::gpu::gl::GLBackend::do_setUniformBuffer), + (&::gpu::gl::GLBackend::do_setResourceTexture), - (&::gpu::GLBackend::do_setFramebuffer), - (&::gpu::GLBackend::do_clearFramebuffer), - (&::gpu::GLBackend::do_blit), - (&::gpu::GLBackend::do_generateTextureMips), + (&::gpu::gl::GLBackend::do_setFramebuffer), + (&::gpu::gl::GLBackend::do_clearFramebuffer), + (&::gpu::gl::GLBackend::do_blit), + (&::gpu::gl::GLBackend::do_generateTextureMips), - (&::gpu::GLBackend::do_beginQuery), - (&::gpu::GLBackend::do_endQuery), - (&::gpu::GLBackend::do_getQuery), + (&::gpu::gl::GLBackend::do_beginQuery), + (&::gpu::gl::GLBackend::do_endQuery), + (&::gpu::gl::GLBackend::do_getQuery), - (&::gpu::GLBackend::do_resetStages), + (&::gpu::gl::GLBackend::do_resetStages), - (&::gpu::GLBackend::do_runLambda), + (&::gpu::gl::GLBackend::do_runLambda), - (&::gpu::GLBackend::do_startNamedCall), - (&::gpu::GLBackend::do_stopNamedCall), + (&::gpu::gl::GLBackend::do_startNamedCall), + (&::gpu::gl::GLBackend::do_stopNamedCall), - (&::gpu::GLBackend::do_glActiveBindTexture), + (&::gpu::gl::GLBackend::do_glActiveBindTexture), - (&::gpu::GLBackend::do_glUniform1i), - (&::gpu::GLBackend::do_glUniform1f), - (&::gpu::GLBackend::do_glUniform2f), - (&::gpu::GLBackend::do_glUniform3f), - (&::gpu::GLBackend::do_glUniform4f), - (&::gpu::GLBackend::do_glUniform3fv), - (&::gpu::GLBackend::do_glUniform4fv), - (&::gpu::GLBackend::do_glUniform4iv), - (&::gpu::GLBackend::do_glUniformMatrix4fv), + (&::gpu::gl::GLBackend::do_glUniform1i), + (&::gpu::gl::GLBackend::do_glUniform1f), + (&::gpu::gl::GLBackend::do_glUniform2f), + (&::gpu::gl::GLBackend::do_glUniform3f), + (&::gpu::gl::GLBackend::do_glUniform4f), + (&::gpu::gl::GLBackend::do_glUniform3fv), + (&::gpu::gl::GLBackend::do_glUniform4fv), + (&::gpu::gl::GLBackend::do_glUniform4iv), + (&::gpu::gl::GLBackend::do_glUniformMatrix4fv), - (&::gpu::GLBackend::do_glColor4f), + (&::gpu::gl::GLBackend::do_glColor4f), - (&::gpu::GLBackend::do_pushProfileRange), - (&::gpu::GLBackend::do_popProfileRange), + (&::gpu::gl::GLBackend::do_pushProfileRange), + (&::gpu::gl::GLBackend::do_popProfileRange), }; +extern std::function TEXTURE_ID_RESOLVER; + void GLBackend::init() { static std::once_flag once; std::call_once(once, [] { + + TEXTURE_ID_RESOLVER = [](const Texture& texture)->uint32 { + auto object = Backend::getGPUObject(texture); + if (!object) { + return 0; + } + + if (object->getSyncState() != GLTexture::Idle) { + if (object->_downsampleSource) { + return object->_downsampleSource->_texture; + } + return 0; + } + return object->_texture; + }; + QString vendor{ (const char*)glGetString(GL_VENDOR) }; QString renderer{ (const char*)glGetString(GL_RENDERER) }; - qCDebug(gpulogging) << "GL Version: " << QString((const char*) glGetString(GL_VERSION)); - qCDebug(gpulogging) << "GL Shader Language Version: " << QString((const char*) glGetString(GL_SHADING_LANGUAGE_VERSION)); - qCDebug(gpulogging) << "GL Vendor: " << vendor; - qCDebug(gpulogging) << "GL Renderer: " << renderer; + qCDebug(gpugllogging) << "GL Version: " << QString((const char*) glGetString(GL_VERSION)); + qCDebug(gpugllogging) << "GL Shader Language Version: " << QString((const char*) glGetString(GL_SHADING_LANGUAGE_VERSION)); + qCDebug(gpugllogging) << "GL Vendor: " << vendor; + qCDebug(gpugllogging) << "GL Renderer: " << renderer; GPUIdent* gpu = GPUIdent::getInstance(vendor, renderer); // From here on, GPUIdent::getInstance()->getMumble() should efficiently give the same answers. - qCDebug(gpulogging) << "GPU:"; - qCDebug(gpulogging) << "\tcard:" << gpu->getName(); - qCDebug(gpulogging) << "\tdriver:" << gpu->getDriver(); - qCDebug(gpulogging) << "\tdedicated memory:" << gpu->getMemory() << "MB"; + qCDebug(gpugllogging) << "GPU:"; + qCDebug(gpugllogging) << "\tcard:" << gpu->getName(); + qCDebug(gpugllogging) << "\tdriver:" << gpu->getDriver(); + qCDebug(gpugllogging) << "\tdedicated memory:" << gpu->getMemory() << "MB"; glewExperimental = true; GLenum err = glewInit(); glGetError(); // clear the potential error from glewExperimental if (GLEW_OK != err) { // glewInit failed, something is seriously wrong. - qCDebug(gpulogging, "Error: %s\n", glewGetErrorString(err)); + qCDebug(gpugllogging, "Error: %s\n", glewGetErrorString(err)); } - qCDebug(gpulogging, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); + qCDebug(gpugllogging, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); #if defined(Q_OS_WIN) if (wglewGetExtension("WGL_EXT_swap_control")) { int swapInterval = wglGetSwapIntervalEXT(); - qCDebug(gpulogging, "V-Sync is %s\n", (swapInterval > 0 ? "ON" : "OFF")); + qCDebug(gpugllogging, "V-Sync is %s\n", (swapInterval > 0 ? "ON" : "OFF")); } #endif @@ -121,7 +142,7 @@ void GLBackend::init() { // TODO: Write the correct code for Linux... /* if (wglewGetExtension("WGL_EXT_swap_control")) { int swapInterval = wglGetSwapIntervalEXT(); - qCDebug(gpulogging, "V-Sync is %s\n", (swapInterval > 0 ? "ON" : "OFF")); + qCDebug(gpugllogging, "V-Sync is %s\n", (swapInterval > 0 ? "ON" : "OFF")); }*/ #endif }); @@ -316,47 +337,6 @@ void GLBackend::render(Batch& batch) { _stereo._enable = savedStereo; } -bool GLBackend::checkGLError(const char* name) { - GLenum error = glGetError(); - if (!error) { - return false; - } - else { - switch (error) { - case GL_INVALID_ENUM: - qCDebug(gpulogging) << "GLBackend::" << name << ": An unacceptable value is specified for an enumerated argument.The offending command is ignored and has no other side effect than to set the error flag."; - break; - case GL_INVALID_VALUE: - qCDebug(gpulogging) << "GLBackend" << name << ": A numeric argument is out of range.The offending command is ignored and has no other side effect than to set the error flag"; - break; - case GL_INVALID_OPERATION: - qCDebug(gpulogging) << "GLBackend" << name << ": The specified operation is not allowed in the current state.The offending command is ignored and has no other side effect than to set the error flag.."; - break; - case GL_INVALID_FRAMEBUFFER_OPERATION: - qCDebug(gpulogging) << "GLBackend" << name << ": The framebuffer object is not complete.The offending command is ignored and has no other side effect than to set the error flag."; - break; - case GL_OUT_OF_MEMORY: - qCDebug(gpulogging) << "GLBackend" << name << ": There is not enough memory left to execute the command.The state of the GL is undefined, except for the state of the error flags, after this error is recorded."; - break; - case GL_STACK_UNDERFLOW: - qCDebug(gpulogging) << "GLBackend" << name << ": An attempt has been made to perform an operation that would cause an internal stack to underflow."; - break; - case GL_STACK_OVERFLOW: - qCDebug(gpulogging) << "GLBackend" << name << ": An attempt has been made to perform an operation that would cause an internal stack to overflow."; - break; - } - return true; - } -} - -bool GLBackend::checkGLErrorDebug(const char* name) { -#ifdef DEBUG - return checkGLError(name); -#else - Q_UNUSED(name); - return false; -#endif -} void GLBackend::syncCache() { syncTransformStateCache(); diff --git a/libraries/gpu/src/gpu/GLBackend.h b/libraries/gpu-gl/src/gpu/gl/GLBackend.h similarity index 96% rename from libraries/gpu/src/gpu/GLBackend.h rename to libraries/gpu-gl/src/gpu/gl/GLBackend.h index 672a29538b..16bb1cc394 100644 --- a/libraries/gpu/src/gpu/GLBackend.h +++ b/libraries/gpu-gl/src/gpu/gl/GLBackend.h @@ -19,18 +19,46 @@ #include #include +#include + #include -#include "Context.h" +#include +#include -namespace gpu { + +#define GPU_CORE 1 +#define GPU_LEGACY 0 +#define GPU_CORE_41 410 +#define GPU_CORE_43 430 +#define GPU_CORE_MINIMUM GPU_CORE_41 +#define GPU_FEATURE_PROFILE GPU_CORE + +#if defined(__APPLE__) + +#define GPU_INPUT_PROFILE GPU_CORE_41 + +#else + +#define GPU_INPUT_PROFILE GPU_CORE_43 + +#endif + + +#if (GPU_INPUT_PROFILE == GPU_CORE_43) +// Deactivate SSBO for now, we've run into some issues +// on GL 4.3 capable GPUs not behaving as expected +//#define GPU_SSBO_DRAW_CALL_INFO +#endif + +namespace gpu { namespace gl { class GLTextureTransferHelper; class GLBackend : public Backend { // Context Backend static interface required - friend class Context; + friend class gpu::Context; static void init(); static Backend* createBackend(); static bool makeProgram(Shader& shader, const Shader::BindingSet& bindings); @@ -54,11 +82,6 @@ public: // Just avoid using it, it's ugly and will break performances virtual void downloadFramebuffer(const FramebufferPointer& srcFramebuffer, const Vec4i& region, QImage& destImage); - static bool checkGLError(const char* name = nullptr); - - // Only checks in debug builds - static bool checkGLErrorDebug(const char* name = nullptr); - static void checkGLStackStable(std::function f); @@ -72,7 +95,7 @@ public: GLBuffer(const Buffer& buffer, GLBuffer* original = nullptr); ~GLBuffer(); - void transfer(); + virtual void transfer(); private: bool getNextTransferBlock(GLintptr& outOffset, GLsizeiptr& outSize, size_t& currentPage) const; @@ -626,6 +649,9 @@ protected: }; -}; +} } + +Q_DECLARE_LOGGING_CATEGORY(gpugllogging) + #endif diff --git a/libraries/gpu/src/gpu/GLBackendBuffer.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackendBuffer.cpp old mode 100755 new mode 100644 similarity index 98% rename from libraries/gpu/src/gpu/GLBackendBuffer.cpp rename to libraries/gpu-gl/src/gpu/gl/GLBackendBuffer.cpp index 7098fd1feb..0057b3d702 --- a/libraries/gpu/src/gpu/GLBackendBuffer.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackendBuffer.cpp @@ -8,9 +8,11 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include "GLBackend.h" #include "GLBackendShared.h" using namespace gpu; +using namespace gpu::gl; GLuint allocateSingleBuffer() { GLuint result; diff --git a/libraries/gpu/src/gpu/GLBackendInput.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackendInput.cpp old mode 100755 new mode 100644 similarity index 99% rename from libraries/gpu/src/gpu/GLBackendInput.cpp rename to libraries/gpu-gl/src/gpu/gl/GLBackendInput.cpp index 75f4be3cbe..7849da42a0 --- a/libraries/gpu/src/gpu/GLBackendInput.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackendInput.cpp @@ -8,9 +8,11 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include "GLBackend.h" #include "GLBackendShared.h" using namespace gpu; +using namespace gpu::gl; void GLBackend::do_setInputFormat(Batch& batch, size_t paramOffset) { Stream::FormatPointer format = batch._streamFormats.get(batch._params[paramOffset]._uint); diff --git a/libraries/gpu/src/gpu/GLBackendOutput.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackendOutput.cpp old mode 100755 new mode 100644 similarity index 85% rename from libraries/gpu/src/gpu/GLBackendOutput.cpp rename to libraries/gpu-gl/src/gpu/gl/GLBackendOutput.cpp index d40c5f9b97..f0a29a19ba --- a/libraries/gpu/src/gpu/GLBackendOutput.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackendOutput.cpp @@ -8,13 +8,14 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include +#include "GLBackend.h" + +#include -#include "GPULogging.h" #include "GLBackendShared.h" - using namespace gpu; +using namespace gpu::gl; GLBackend::GLFramebuffer::GLFramebuffer() {} @@ -97,19 +98,6 @@ GLBackend::GLFramebuffer* GLBackend::syncGPUObject(const Framebuffer& framebuffe unit++; } } - #if (GPU_FEATURE_PROFILE == GPU_LEGACY) - // for reasons that i don't understand yet, it seems that on mac gl, a fbo must have a color buffer... - else { - GLuint renderBuffer = 0; - glGenRenderbuffers(1, &renderBuffer); - glBindRenderbuffer(GL_RENDERBUFFER, renderBuffer); - glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, framebuffer.getWidth(), framebuffer.getHeight()); - glBindRenderbuffer(GL_RENDERBUFFER, 0); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderBuffer); - (void) CHECK_GL_ERROR(); - } - // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - #endif object->_colorStamps = framebuffer.getColorStamps(); } @@ -157,19 +145,19 @@ GLBackend::GLFramebuffer* GLBackend::syncGPUObject(const Framebuffer& framebuffe result = true; break; case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT : - qCDebug(gpulogging) << "GLFramebuffer::syncGPUObject : Framebuffer not valid, GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT."; + qCDebug(gpugllogging) << "GLFramebuffer::syncGPUObject : Framebuffer not valid, GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT."; break; case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT : - qCDebug(gpulogging) << "GLFramebuffer::syncGPUObject : Framebuffer not valid, GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT."; + qCDebug(gpugllogging) << "GLFramebuffer::syncGPUObject : Framebuffer not valid, GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT."; break; case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER : - qCDebug(gpulogging) << "GLFramebuffer::syncGPUObject : Framebuffer not valid, GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER."; + qCDebug(gpugllogging) << "GLFramebuffer::syncGPUObject : Framebuffer not valid, GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER."; break; case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER : - qCDebug(gpulogging) << "GLFramebuffer::syncGPUObject : Framebuffer not valid, GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER."; + qCDebug(gpugllogging) << "GLFramebuffer::syncGPUObject : Framebuffer not valid, GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER."; break; case GL_FRAMEBUFFER_UNSUPPORTED : - qCDebug(gpulogging) << "GLFramebuffer::syncGPUObject : Framebuffer not valid, GL_FRAMEBUFFER_UNSUPPORTED."; + qCDebug(gpugllogging) << "GLFramebuffer::syncGPUObject : Framebuffer not valid, GL_FRAMEBUFFER_UNSUPPORTED."; break; } if (!result && object->_fbo) { @@ -354,26 +342,26 @@ void GLBackend::do_blit(Batch& batch, size_t paramOffset) { } void GLBackend::downloadFramebuffer(const FramebufferPointer& srcFramebuffer, const Vec4i& region, QImage& destImage) { - auto readFBO = gpu::GLBackend::getFramebufferID(srcFramebuffer); + auto readFBO = getFramebufferID(srcFramebuffer); if (srcFramebuffer && readFBO) { if ((srcFramebuffer->getWidth() < (region.x + region.z)) || (srcFramebuffer->getHeight() < (region.y + region.w))) { - qCDebug(gpulogging) << "GLBackend::downloadFramebuffer : srcFramebuffer is too small to provide the region queried"; + qCDebug(gpugllogging) << "GLBackend::downloadFramebuffer : srcFramebuffer is too small to provide the region queried"; return; } } if ((destImage.width() < region.z) || (destImage.height() < region.w)) { - qCDebug(gpulogging) << "GLBackend::downloadFramebuffer : destImage is too small to receive the region of the framebuffer"; + qCDebug(gpugllogging) << "GLBackend::downloadFramebuffer : destImage is too small to receive the region of the framebuffer"; return; } GLenum format = GL_BGRA; if (destImage.format() != QImage::Format_ARGB32) { - qCDebug(gpulogging) << "GLBackend::downloadFramebuffer : destImage format must be FORMAT_ARGB32 to receive the region of the framebuffer"; + qCDebug(gpugllogging) << "GLBackend::downloadFramebuffer : destImage format must be FORMAT_ARGB32 to receive the region of the framebuffer"; return; } - glBindFramebuffer(GL_READ_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(srcFramebuffer)); + glBindFramebuffer(GL_READ_FRAMEBUFFER, getFramebufferID(srcFramebuffer)); glReadPixels(region.x, region.y, region.z, region.w, format, GL_UNSIGNED_BYTE, destImage.bits()); glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); diff --git a/libraries/gpu/src/gpu/GLBackendPipeline.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackendPipeline.cpp old mode 100755 new mode 100644 similarity index 92% rename from libraries/gpu/src/gpu/GLBackendPipeline.cpp rename to libraries/gpu-gl/src/gpu/gl/GLBackendPipeline.cpp index 0b539f75b9..b66b672850 --- a/libraries/gpu/src/gpu/GLBackendPipeline.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackendPipeline.cpp @@ -8,11 +8,11 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include "GLBackend.h" #include "GLBackendShared.h" -#include "Format.h" - using namespace gpu; +using namespace gpu::gl; GLBackend::GLPipeline::GLPipeline() : _program(nullptr), @@ -157,7 +157,6 @@ void GLBackend::resetPipelineStage() { void GLBackend::releaseUniformBuffer(uint32_t slot) { -#if (GPU_FEATURE_PROFILE == GPU_CORE) auto& buf = _uniform._buffers[slot]; if (buf) { auto* object = Backend::getGPUObject(*buf); @@ -168,7 +167,6 @@ void GLBackend::releaseUniformBuffer(uint32_t slot) { } buf.reset(); } -#endif } void GLBackend::resetUniformStage() { @@ -186,7 +184,6 @@ void GLBackend::do_setUniformBuffer(Batch& batch, size_t paramOffset) { -#if (GPU_FEATURE_PROFILE == GPU_CORE) if (!uniformBuffer) { releaseUniformBuffer(slot); return; @@ -208,21 +205,6 @@ void GLBackend::do_setUniformBuffer(Batch& batch, size_t paramOffset) { releaseResourceTexture(slot); return; } -#else - // because we rely on the program uniform mechanism we need to have - // the program bound, thank you MacOSX Legacy profile. - updatePipeline(); - - GLfloat* data = (GLfloat*) (uniformBuffer->getData() + rangeStart); - glUniform4fv(slot, rangeSize / sizeof(GLfloat[4]), data); - - // NOT working so we ll stick to the uniform float array until we move to core profile - // GLuint bo = getBufferID(*uniformBuffer); - //glUniformBufferEXT(_shader._program, slot, bo); - - (void) CHECK_GL_ERROR(); - -#endif } void GLBackend::releaseResourceTexture(uint32_t slot) { diff --git a/libraries/gpu/src/gpu/GLBackendQuery.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackendQuery.cpp similarity index 68% rename from libraries/gpu/src/gpu/GLBackendQuery.cpp rename to libraries/gpu-gl/src/gpu/gl/GLBackendQuery.cpp index f3a81d504c..4f5b2ff1bf 100644 --- a/libraries/gpu/src/gpu/GLBackendQuery.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackendQuery.cpp @@ -8,10 +8,11 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include "GLBackend.h" #include "GLBackendShared.h" - using namespace gpu; +using namespace gpu::gl; GLBackend::GLQuery::GLQuery() {} @@ -64,12 +65,7 @@ void GLBackend::do_beginQuery(Batch& batch, size_t paramOffset) { auto query = batch._queries.get(batch._params[paramOffset]._uint); GLQuery* glquery = syncGPUObject(*query); if (glquery) { - #if (GPU_FEATURE_PROFILE == GPU_LEGACY) - // (EXT_TIMER_QUERY) - glBeginQuery(GL_TIME_ELAPSED_EXT, glquery->_qo); - #else - glBeginQuery(GL_TIME_ELAPSED, glquery->_qo); - #endif + glBeginQuery(GL_TIME_ELAPSED, glquery->_qo); (void)CHECK_GL_ERROR(); } } @@ -78,12 +74,7 @@ void GLBackend::do_endQuery(Batch& batch, size_t paramOffset) { auto query = batch._queries.get(batch._params[paramOffset]._uint); GLQuery* glquery = syncGPUObject(*query); if (glquery) { - #if (GPU_FEATURE_PROFILE == GPU_LEGACY) - // (EXT_TIMER_QUERY) - glEndQuery(GL_TIME_ELAPSED_EXT); - #else - glEndQuery(GL_TIME_ELAPSED); - #endif + glEndQuery(GL_TIME_ELAPSED); (void)CHECK_GL_ERROR(); } } @@ -92,18 +83,11 @@ void GLBackend::do_getQuery(Batch& batch, size_t paramOffset) { auto query = batch._queries.get(batch._params[paramOffset]._uint); GLQuery* glquery = syncGPUObject(*query); if (glquery) { - #if (GPU_FEATURE_PROFILE == GPU_LEGACY) - // (EXT_TIMER_QUERY) - #if !defined(Q_OS_LINUX) - glGetQueryObjectui64vEXT(glquery->_qo, GL_QUERY_RESULT, &glquery->_result); - #endif - #else - glGetQueryObjectui64v(glquery->_qo, GL_QUERY_RESULT_AVAILABLE, &glquery->_result); - if (glquery->_result == GL_TRUE) { - glGetQueryObjectui64v(glquery->_qo, GL_QUERY_RESULT, &glquery->_result); - query->triggerReturnHandler(glquery->_result); - } - #endif + glGetQueryObjectui64v(glquery->_qo, GL_QUERY_RESULT_AVAILABLE, &glquery->_result); + if (glquery->_result == GL_TRUE) { + glGetQueryObjectui64v(glquery->_qo, GL_QUERY_RESULT, &glquery->_result); + query->triggerReturnHandler(glquery->_result); + } (void)CHECK_GL_ERROR(); } } diff --git a/libraries/gpu/src/gpu/GLBackendShader.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackendShader.cpp old mode 100755 new mode 100644 similarity index 92% rename from libraries/gpu/src/gpu/GLBackendShader.cpp rename to libraries/gpu-gl/src/gpu/gl/GLBackendShader.cpp index 2c4d9e3179..8ebf7751d1 --- a/libraries/gpu/src/gpu/GLBackendShader.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackendShader.cpp @@ -8,10 +8,11 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include "GLBackend.h" #include "GLBackendShared.h" -#include "Format.h" using namespace gpu; +using namespace gpu::gl; GLBackend::GLShader::GLShader() { @@ -30,14 +31,14 @@ GLBackend::GLShader::~GLShader() { bool compileShader(GLenum shaderDomain, const std::string& shaderSource, const std::string& defines, GLuint &shaderObject, GLuint &programObject) { if (shaderSource.empty()) { - qCDebug(gpulogging) << "GLShader::compileShader - no GLSL shader source code ? so failed to create"; + qCDebug(gpugllogging) << "GLShader::compileShader - no GLSL shader source code ? so failed to create"; return false; } // Create the shader object GLuint glshader = glCreateShader(shaderDomain); if (!glshader) { - qCDebug(gpulogging) << "GLShader::compileShader - failed to create the gl shader object"; + qCDebug(gpugllogging) << "GLShader::compileShader - failed to create the gl shader object"; return false; } @@ -79,12 +80,12 @@ bool compileShader(GLenum shaderDomain, const std::string& shaderSource, const s } */ - qCWarning(gpulogging) << "GLShader::compileShader - failed to compile the gl shader object:"; + qCWarning(gpugllogging) << "GLShader::compileShader - failed to compile the gl shader object:"; for (auto s : srcstr) { - qCWarning(gpulogging) << s; + qCWarning(gpugllogging) << s; } - qCWarning(gpulogging) << "GLShader::compileShader - errors:"; - qCWarning(gpulogging) << temp; + qCWarning(gpugllogging) << "GLShader::compileShader - errors:"; + qCWarning(gpugllogging) << temp; delete[] temp; glDeleteShader(glshader); @@ -96,7 +97,7 @@ bool compileShader(GLenum shaderDomain, const std::string& shaderSource, const s // so far so good, program is almost done, need to link: GLuint glprogram = glCreateProgram(); if (!glprogram) { - qCDebug(gpulogging) << "GLShader::compileShader - failed to create the gl shader & gl program object"; + qCDebug(gpugllogging) << "GLShader::compileShader - failed to create the gl shader & gl program object"; return false; } @@ -124,8 +125,8 @@ bool compileShader(GLenum shaderDomain, const std::string& shaderSource, const s char* temp = new char[infoLength]; glGetProgramInfoLog(glprogram, infoLength, NULL, temp); - qCDebug(gpulogging) << "GLShader::compileShader - failed to LINK the gl program object :"; - qCDebug(gpulogging) << temp; + qCDebug(gpugllogging) << "GLShader::compileShader - failed to LINK the gl program object :"; + qCDebug(gpugllogging) << temp; /* filestream.open("debugshader.glsl.info.txt"); @@ -152,7 +153,7 @@ GLuint compileProgram(const std::vector& glshaders) { // A brand new program: GLuint glprogram = glCreateProgram(); if (!glprogram) { - qCDebug(gpulogging) << "GLShader::compileProgram - failed to create the gl program object"; + qCDebug(gpugllogging) << "GLShader::compileProgram - failed to create the gl program object"; return 0; } @@ -185,8 +186,8 @@ GLuint compileProgram(const std::vector& glshaders) { char* temp = new char[infoLength]; glGetProgramInfoLog(glprogram, infoLength, NULL, temp); - qCDebug(gpulogging) << "GLShader::compileProgram - failed to LINK the gl program object :"; - qCDebug(gpulogging) << temp; + qCDebug(gpugllogging) << "GLShader::compileProgram - failed to LINK the gl program object :"; + qCDebug(gpugllogging) << temp; /* filestream.open("debugshader.glsl.info.txt"); @@ -264,7 +265,7 @@ void makeProgramBindings(GLBackend::GLShader::ShaderObject& shaderObject) { GLint linked = 0; glGetProgramiv(glprogram, GL_LINK_STATUS, &linked); if (!linked) { - qCDebug(gpulogging) << "GLShader::makeBindings - failed to link after assigning slotBindings?"; + qCDebug(gpugllogging) << "GLShader::makeBindings - failed to link after assigning slotBindings?"; } // now assign the ubo binding, then DON't relink! @@ -358,7 +359,7 @@ GLBackend::GLShader* compileBackendProgram(const Shader& program) { if (object) { shaderGLObjects.push_back(object->_shaderObjects[version].glshader); } else { - qCDebug(gpulogging) << "GLShader::compileBackendProgram - One of the shaders of the program is not compiled?"; + qCDebug(gpugllogging) << "GLShader::compileBackendProgram - One of the shaders of the program is not compiled?"; return nullptr; } } @@ -559,19 +560,9 @@ ElementResource getFormatFromGLUniform(GLenum gltype) { int makeUniformSlots(GLuint glprogram, const Shader::BindingSet& slotBindings, - Shader::SlotSet& uniforms, Shader::SlotSet& textures, Shader::SlotSet& samplers -#if (GPU_FEATURE_PROFILE == GPU_LEGACY) - , Shader::SlotSet& fakeBuffers -#endif -) { + Shader::SlotSet& uniforms, Shader::SlotSet& textures, Shader::SlotSet& samplers) { GLint uniformsCount = 0; -#if (GPU_FEATURE_PROFILE == GPU_LEGACY) - GLint currentProgram = 0; - glGetIntegerv(GL_CURRENT_PROGRAM, ¤tProgram); - glUseProgram(glprogram); -#endif - glGetProgramiv(glprogram, GL_ACTIVE_UNIFORMS, &uniformsCount); for (int i = 0; i < uniformsCount; i++) { @@ -604,15 +595,6 @@ int makeUniformSlots(GLuint glprogram, const Shader::BindingSet& slotBindings, } if (elementResource._resource == Resource::BUFFER) { -#if (GPU_FEATURE_PROFILE == GPU_LEGACY) - // if in legacy profile, we fake the uniform buffer with an array - // this is where we detect it assuming it's explicitely assinged a binding - auto requestedBinding = slotBindings.find(std::string(sname)); - if (requestedBinding != slotBindings.end()) { - // found one buffer! - fakeBuffers.insert(Shader::Slot(sname, location, elementResource._element, elementResource._resource)); - } -#endif uniforms.insert(Shader::Slot(sname, location, elementResource._element, elementResource._resource)); } else { // For texture/Sampler, the location is the actual binding value @@ -623,11 +605,7 @@ int makeUniformSlots(GLuint glprogram, const Shader::BindingSet& slotBindings, if (requestedBinding != slotBindings.end()) { if (binding != (*requestedBinding)._location) { binding = (*requestedBinding)._location; -#if (GPU_FEATURE_PROFILE == GPU_LEGACY) - glUniform1i(location, binding); -#else glProgramUniform1i(glprogram, location, binding); -#endif } } @@ -637,10 +615,6 @@ int makeUniformSlots(GLuint glprogram, const Shader::BindingSet& slotBindings, } } -#if (GPU_FEATURE_PROFILE == GPU_LEGACY) - glUseProgram(currentProgram); -#endif - return uniformsCount; } diff --git a/libraries/gpu/src/gpu/GLBackendTexelFormat.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackendShared.cpp similarity index 81% rename from libraries/gpu/src/gpu/GLBackendTexelFormat.cpp rename to libraries/gpu-gl/src/gpu/gl/GLBackendShared.cpp index 00528d0030..614de60001 100644 --- a/libraries/gpu/src/gpu/GLBackendTexelFormat.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackendShared.cpp @@ -1,14 +1,60 @@ // -// Created by Bradley Austin Davis on 2016/04/03 +// Created by Bradley Austin Davis on 2016/05/14 // Copyright 2013-2016 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // - #include "GLBackendShared.h" -using namespace gpu; +#include + +Q_DECLARE_LOGGING_CATEGORY(gpugllogging) +Q_LOGGING_CATEGORY(gpugllogging, "hifi.gpu.gl") + +namespace gpu { namespace gl { + +bool checkGLError(const char* name) { + GLenum error = glGetError(); + if (!error) { + return false; + } else { + switch (error) { + case GL_INVALID_ENUM: + qCDebug(gpugllogging) << "GLBackend::" << name << ": An unacceptable value is specified for an enumerated argument.The offending command is ignored and has no other side effect than to set the error flag."; + break; + case GL_INVALID_VALUE: + qCDebug(gpugllogging) << "GLBackend" << name << ": A numeric argument is out of range.The offending command is ignored and has no other side effect than to set the error flag"; + break; + case GL_INVALID_OPERATION: + qCDebug(gpugllogging) << "GLBackend" << name << ": The specified operation is not allowed in the current state.The offending command is ignored and has no other side effect than to set the error flag.."; + break; + case GL_INVALID_FRAMEBUFFER_OPERATION: + qCDebug(gpugllogging) << "GLBackend" << name << ": The framebuffer object is not complete.The offending command is ignored and has no other side effect than to set the error flag."; + break; + case GL_OUT_OF_MEMORY: + qCDebug(gpugllogging) << "GLBackend" << name << ": There is not enough memory left to execute the command.The state of the GL is undefined, except for the state of the error flags, after this error is recorded."; + break; + case GL_STACK_UNDERFLOW: + qCDebug(gpugllogging) << "GLBackend" << name << ": An attempt has been made to perform an operation that would cause an internal stack to underflow."; + break; + case GL_STACK_OVERFLOW: + qCDebug(gpugllogging) << "GLBackend" << name << ": An attempt has been made to perform an operation that would cause an internal stack to overflow."; + break; + } + return true; + } +} + +bool checkGLErrorDebug(const char* name) { +#ifdef DEBUG + return checkGLError(name); +#else + Q_UNUSED(name); + return false; +#endif +} + GLTexelFormat GLTexelFormat::evalGLTexelFormatInternal(const gpu::Element& dstFormat) { GLTexelFormat texel = { GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE }; @@ -43,7 +89,7 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E texel.internalFormat = GL_DEPTH24_STENCIL8; break; default: - qCDebug(gpulogging) << "Unknown combination of texel format"; + qCDebug(gpugllogging) << "Unknown combination of texel format"; } break; } @@ -58,7 +104,7 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E texel.internalFormat = GL_RG8; break; default: - qCDebug(gpulogging) << "Unknown combination of texel format"; + qCDebug(gpugllogging) << "Unknown combination of texel format"; } break; @@ -81,7 +127,7 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E texel.internalFormat = GL_COMPRESSED_SRGB; break; default: - qCDebug(gpulogging) << "Unknown combination of texel format"; + qCDebug(gpugllogging) << "Unknown combination of texel format"; } break; @@ -123,7 +169,7 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E break; case gpu::COMPRESSED_SRGBA: texel.internalFormat = GL_COMPRESSED_SRGB_ALPHA; - + break; // FIXME: WE will want to support this later @@ -144,13 +190,13 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E */ default: - qCDebug(gpulogging) << "Unknown combination of texel format"; + qCDebug(gpugllogging) << "Unknown combination of texel format"; } break; } default: - qCDebug(gpulogging) << "Unknown combination of texel format"; + qCDebug(gpugllogging) << "Unknown combination of texel format"; } return texel; } else { @@ -286,7 +332,7 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E texel.internalFormat = GL_DEPTH24_STENCIL8; break; default: - qCDebug(gpulogging) << "Unknown combination of texel format"; + qCDebug(gpugllogging) << "Unknown combination of texel format"; } break; @@ -302,7 +348,7 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E texel.internalFormat = GL_RG8; break; default: - qCDebug(gpulogging) << "Unknown combination of texel format"; + qCDebug(gpugllogging) << "Unknown combination of texel format"; } break; @@ -329,7 +375,7 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E texel.internalFormat = GL_COMPRESSED_SRGB; break; default: - qCDebug(gpulogging) << "Unknown combination of texel format"; + qCDebug(gpugllogging) << "Unknown combination of texel format"; } break; } @@ -411,14 +457,16 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E texel.internalFormat = GL_COMPRESSED_SRGB_ALPHA; break; default: - qCDebug(gpulogging) << "Unknown combination of texel format"; + qCDebug(gpugllogging) << "Unknown combination of texel format"; } break; } default: - qCDebug(gpulogging) << "Unknown combination of texel format"; + qCDebug(gpugllogging) << "Unknown combination of texel format"; } return texel; } } + +} } \ No newline at end of file diff --git a/libraries/gpu/src/gpu/GLBackendShared.h b/libraries/gpu-gl/src/gpu/gl/GLBackendShared.h similarity index 76% rename from libraries/gpu/src/gpu/GLBackendShared.h rename to libraries/gpu-gl/src/gpu/gl/GLBackendShared.h index aef670e6b0..0f7215f364 100644 --- a/libraries/gpu/src/gpu/GLBackendShared.h +++ b/libraries/gpu-gl/src/gpu/gl/GLBackendShared.h @@ -12,11 +12,10 @@ #define hifi_gpu_GLBackend_Shared_h #include +#include +#include -#include - -#include "GPULogging.h" -#include "GLBackend.h" +namespace gpu { namespace gl { static const GLenum _primitiveToGLmode[gpu::NUM_PRIMITIVES] = { GL_POINTS, @@ -59,10 +58,11 @@ public: static GLTexelFormat evalGLTexelFormat(const gpu::Element& dstFormat, const gpu::Element& srcFormat); }; -// Stupid preprocessor trick to turn the line macro into a string -#define CHECK_GL_ERROR_HELPER(x) #x -// FIXME doesn't build on Linux or Mac. Hmmmm -// #define CHECK_GL_ERROR() gpu::GLBackend::checkGLErrorDebug(__FUNCTION__ ":" CHECK_GL_ERROR_HELPER(__LINE__)) -#define CHECK_GL_ERROR() gpu::GLBackend::checkGLErrorDebug(__FUNCTION__) +bool checkGLError(const char* name = nullptr); +bool checkGLErrorDebug(const char* name = nullptr); + +} } + +#define CHECK_GL_ERROR() gpu::gl::checkGLErrorDebug(__FUNCTION__) #endif diff --git a/libraries/gpu/src/gpu/GLBackendState.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackendState.cpp similarity index 99% rename from libraries/gpu/src/gpu/GLBackendState.cpp rename to libraries/gpu-gl/src/gpu/gl/GLBackendState.cpp index 5ef77773e8..1c1e0b38a4 100644 --- a/libraries/gpu/src/gpu/GLBackendState.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackendState.cpp @@ -8,11 +8,11 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include "GLBackend.h" #include "GLBackendShared.h" -#include "Format.h" - using namespace gpu; +using namespace gpu::gl; GLBackend::GLState::GLState() {} diff --git a/libraries/gpu/src/gpu/GLBackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackendTexture.cpp old mode 100755 new mode 100644 similarity index 98% rename from libraries/gpu/src/gpu/GLBackendTexture.cpp rename to libraries/gpu-gl/src/gpu/gl/GLBackendTexture.cpp index 24b9544168..952e5bad8f --- a/libraries/gpu/src/gpu/GLBackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackendTexture.cpp @@ -8,16 +8,19 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "GPULogging.h" +#include "GLBackend.h" #include #include #include #include "GLBackendShared.h" + #include "GLBackendTextureTransfer.h" using namespace gpu; +using namespace gpu::gl; + GLenum gpuToGLTextureType(const Texture& texture) { switch (texture.getType()) { @@ -408,7 +411,7 @@ void GLBackend::GLTexture::transfer() const { break; default: - qCWarning(gpulogging) << __FUNCTION__ << " case for Texture Type " << _gpuTexture.getType() << " not supported"; + qCWarning(gpugllogging) << __FUNCTION__ << " case for Texture Type " << _gpuTexture.getType() << " not supported"; break; } } @@ -449,7 +452,7 @@ void GLBackend::GLTexture::postTransfer() { break; default: - qCWarning(gpulogging) << __FUNCTION__ << " case for Texture Type " << _gpuTexture.getType() << " not supported"; + qCWarning(gpugllogging) << __FUNCTION__ << " case for Texture Type " << _gpuTexture.getType() << " not supported"; break; } } diff --git a/libraries/gpu/src/gpu/GLBackendTextureTransfer.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackendTextureTransfer.cpp similarity index 98% rename from libraries/gpu/src/gpu/GLBackendTextureTransfer.cpp rename to libraries/gpu-gl/src/gpu/gl/GLBackendTextureTransfer.cpp index 80848f6073..a9635e8307 100644 --- a/libraries/gpu/src/gpu/GLBackendTextureTransfer.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackendTextureTransfer.cpp @@ -5,17 +5,20 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // - #include "GLBackendTextureTransfer.h" -#include "GLBackendShared.h" - #ifdef THREADED_TEXTURE_TRANSFER #include #include #endif + +#include "GLBackendShared.h" + using namespace gpu; +using namespace gpu::gl; + +#include "GLBackend.h" GLTextureTransferHelper::GLTextureTransferHelper() { #ifdef THREADED_TEXTURE_TRANSFER diff --git a/libraries/gpu/src/gpu/GLBackendTextureTransfer.h b/libraries/gpu-gl/src/gpu/gl/GLBackendTextureTransfer.h similarity index 94% rename from libraries/gpu/src/gpu/GLBackendTextureTransfer.h rename to libraries/gpu-gl/src/gpu/gl/GLBackendTextureTransfer.h index 9dc9679628..f344827e53 100644 --- a/libraries/gpu/src/gpu/GLBackendTextureTransfer.h +++ b/libraries/gpu-gl/src/gpu/gl/GLBackendTextureTransfer.h @@ -10,6 +10,7 @@ #include #include #include "GLBackendShared.h" +#include "GLBackend.h" #ifdef Q_OS_WIN #define THREADED_TEXTURE_TRANSFER @@ -17,7 +18,7 @@ class OffscreenGLCanvas; -namespace gpu { +namespace gpu { namespace gl { struct TextureTransferPackage { std::weak_ptr texture; @@ -41,4 +42,4 @@ private: QSharedPointer _canvas; }; -} +} } diff --git a/libraries/gpu/src/gpu/GLBackendTransform.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackendTransform.cpp old mode 100755 new mode 100644 similarity index 99% rename from libraries/gpu/src/gpu/GLBackendTransform.cpp rename to libraries/gpu-gl/src/gpu/gl/GLBackendTransform.cpp index ae8f28fbe3..7c60eac10e --- a/libraries/gpu/src/gpu/GLBackendTransform.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackendTransform.cpp @@ -8,11 +8,11 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include "GLBackend.h" #include "GLBackendShared.h" -#include "Format.h" - using namespace gpu; +using namespace gpu::gl; // Transform Stage void GLBackend::do_setModelTransform(Batch& batch, size_t paramOffset) { diff --git a/libraries/gpu/CMakeLists.txt b/libraries/gpu/CMakeLists.txt index 29115af22f..ca442bbcec 100644 --- a/libraries/gpu/CMakeLists.txt +++ b/libraries/gpu/CMakeLists.txt @@ -2,6 +2,3 @@ set(TARGET_NAME gpu) AUTOSCRIBE_SHADER_LIB(gpu) setup_hifi_library() link_hifi_libraries(shared gl) - -target_glew() -target_opengl() \ No newline at end of file diff --git a/libraries/gpu/src/gpu/Forward.h b/libraries/gpu/src/gpu/Forward.h index 07cef0925a..621ccee2f9 100644 --- a/libraries/gpu/src/gpu/Forward.h +++ b/libraries/gpu/src/gpu/Forward.h @@ -31,6 +31,7 @@ namespace gpu { using int8 = int8_t; using Byte = uint8; + using Size = size_t; using Offset = size_t; using Offsets = std::vector; @@ -80,6 +81,11 @@ namespace gpu { using Textures = std::vector; class TextureView; using TextureViews = std::vector; + + namespace gl { + class GLBuffer; + class GLBackend; + } } #endif diff --git a/libraries/gpu/src/gpu/Resource.h b/libraries/gpu/src/gpu/Resource.h index 70292f215b..21164955d6 100644 --- a/libraries/gpu/src/gpu/Resource.h +++ b/libraries/gpu/src/gpu/Resource.h @@ -208,7 +208,7 @@ protected: Sysmem _sysmem; // FIXME find a more generic way to do this. - friend class GLBackend; + friend class gl::GLBackend; friend class BufferView; }; diff --git a/libraries/gpu/src/gpu/Texture.cpp b/libraries/gpu/src/gpu/Texture.cpp index 2362926c84..a5061c62f3 100755 --- a/libraries/gpu/src/gpu/Texture.cpp +++ b/libraries/gpu/src/gpu/Texture.cpp @@ -884,3 +884,12 @@ Vec3u Texture::evalMipDimensions(uint16 level) const { dimensions >>= level; return glm::max(dimensions, Vec3u(1)); } + +std::function TEXTURE_ID_RESOLVER; + +uint32 Texture::getHardwareId() const { + if (TEXTURE_ID_RESOLVER) { + return TEXTURE_ID_RESOLVER(*this); + } + return 0; +} \ No newline at end of file diff --git a/libraries/gpu/src/gpu/Texture.h b/libraries/gpu/src/gpu/Texture.h index 8f075d906b..bceb4b196a 100755 --- a/libraries/gpu/src/gpu/Texture.h +++ b/libraries/gpu/src/gpu/Texture.h @@ -449,6 +449,8 @@ public: const GPUObjectPointer gpuObject {}; + uint32 getHardwareId() const; + protected: std::unique_ptr< Storage > _storage; diff --git a/libraries/procedural/CMakeLists.txt b/libraries/procedural/CMakeLists.txt index 37c4fbfbe8..7145f7de5c 100644 --- a/libraries/procedural/CMakeLists.txt +++ b/libraries/procedural/CMakeLists.txt @@ -1,5 +1,5 @@ set(TARGET_NAME procedural) AUTOSCRIBE_SHADER_LIB(gpu model) setup_hifi_library() -link_hifi_libraries(shared gpu networking model model-networking) +link_hifi_libraries(shared gpu gpu-gl networking model model-networking) diff --git a/plugins/oculusLegacy/src/OculusLegacyDisplayPlugin.cpp b/plugins/oculusLegacy/src/OculusLegacyDisplayPlugin.cpp index 6ceddec11b..753ff923dd 100644 --- a/plugins/oculusLegacy/src/OculusLegacyDisplayPlugin.cpp +++ b/plugins/oculusLegacy/src/OculusLegacyDisplayPlugin.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include diff --git a/tests/gpu-test/CMakeLists.txt b/tests/gpu-test/CMakeLists.txt index 6b985da4c9..4fc6143ff5 100644 --- a/tests/gpu-test/CMakeLists.txt +++ b/tests/gpu-test/CMakeLists.txt @@ -3,5 +3,5 @@ AUTOSCRIBE_SHADER_LIB(gpu model render-utils) # This is not a testcase -- just set it up as a regular hifi project setup_hifi_project(Quick Gui OpenGL Script Widgets) set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "Tests/manual-tests/") -link_hifi_libraries(networking gl gpu procedural shared fbx model model-networking animation script-engine render render-utils ) +link_hifi_libraries(networking gl gpu gpu-gl procedural shared fbx model model-networking animation script-engine render render-utils ) package_libraries_for_deployment() \ No newline at end of file diff --git a/tests/gpu-test/src/main.cpp b/tests/gpu-test/src/main.cpp index 91b61fb289..b80539b33a 100644 --- a/tests/gpu-test/src/main.cpp +++ b/tests/gpu-test/src/main.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include @@ -87,7 +87,6 @@ uint32_t toCompactColor(const glm::vec4& color); const char* VERTEX_SHADER = R"SHADER( -#version 450 core layout(location = 0) in vec4 inPosition; layout(location = 3) in vec2 inTexCoord0; @@ -157,7 +156,6 @@ void main(void) { })SHADER"; const char* FRAGMENT_SHADER = R"SHADER( -#version 450 core uniform sampler2D originalTexture; @@ -246,7 +244,7 @@ public: makeCurrent(); setupDebugLogger(this); - gpu::Context::init(); + gpu::Context::init(); _context = std::make_shared(); makeCurrent(); auto shader = makeShader(unlit_vert, unlit_frag, gpu::Shader::BindingSet{}); diff --git a/tests/render-utils/CMakeLists.txt b/tests/render-utils/CMakeLists.txt index 25221a1e86..e7e80f7726 100644 --- a/tests/render-utils/CMakeLists.txt +++ b/tests/render-utils/CMakeLists.txt @@ -6,6 +6,6 @@ setup_hifi_project(Quick Gui OpenGL) set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "Tests/manual-tests/") # link in the shared libraries -link_hifi_libraries(render-utils gl gpu shared) +link_hifi_libraries(render-utils gl gpu gpu-gl shared) package_libraries_for_deployment() diff --git a/tests/render-utils/src/main.cpp b/tests/render-utils/src/main.cpp index 6973ca075e..db6598c43d 100644 --- a/tests/render-utils/src/main.cpp +++ b/tests/render-utils/src/main.cpp @@ -12,7 +12,7 @@ #include #include -#include +#include #include #include @@ -111,7 +111,7 @@ public: show(); makeCurrent(); - gpu::Context::init(); + gpu::Context::init(); setupDebugLogger(this); diff --git a/tests/shaders/CMakeLists.txt b/tests/shaders/CMakeLists.txt index e95970dd53..4aa66b92db 100644 --- a/tests/shaders/CMakeLists.txt +++ b/tests/shaders/CMakeLists.txt @@ -8,7 +8,7 @@ set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "Tests/manual-tests/") #include_oglplus() # link in the shared libraries -link_hifi_libraries(shared octree gl gpu model render fbx networking entities +link_hifi_libraries(shared octree gl gpu gpu-gl model render fbx networking entities script-engine physics render-utils entities-renderer) diff --git a/tests/shaders/src/main.cpp b/tests/shaders/src/main.cpp index c50f5769e6..2ef7bbdd02 100644 --- a/tests/shaders/src/main.cpp +++ b/tests/shaders/src/main.cpp @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include @@ -114,7 +114,7 @@ public: show(); makeCurrent(); - gpu::Context::init(); + gpu::Context::init(); setupDebugLogger(this); makeCurrent(); resize(QSize(800, 600));