diff --git a/Shadertoy/Shadertoy.cpp b/Shadertoy/Shadertoy.cpp index fa740b50c..cfb197010 100644 --- a/Shadertoy/Shadertoy.cpp +++ b/Shadertoy/Shadertoy.cpp @@ -24,8 +24,7 @@ * http://www.iquilezles.org/apps/shadertoy/index2.html (original Shader Toy v0.4) * * TODO: - * - add a "Renderer Info..." press button, which displays OpenGL renderer info in a dialog window - * - add RoD parameters (see SeExpr) + * - add RoD + extra parameters (see SeExpr) * - add multipass support (using tabs for UI as in shadertoys) */ @@ -288,6 +287,10 @@ using namespace OFX; #define kParamUseGPUHint "If GPU rendering is available, use it. If the checkbox is not enabled, GPU rendering is not available on this host." #endif +#define kParamRendererInfo "rendererInfo" +#define kParamRendererInfoLabel "Renderer Info..." +#define kParamRendererInfoHint "Retrieve information about the current OpenGL renderer." + #define kClipChannel "iChannel" //////////////////////////////////////////////////////////////////////////////// @@ -451,7 +454,7 @@ ShadertoyPlugin::getClipPreferences(OFX::ClipPreferencesSetter &clipPreferences) } void -ShadertoyPlugin::changedParam(const OFX::InstanceChangedArgs &/*args*/, +ShadertoyPlugin::changedParam(const OFX::InstanceChangedArgs &args, const std::string ¶mName) { if (paramName == kParamImageShaderFileName || @@ -480,6 +483,33 @@ ShadertoyPlugin::changedParam(const OFX::InstanceChangedArgs &/*args*/, ++_imageShaderID; #endif _imageShaderChanged = true; + } else if (paramName == kParamRendererInfo) { + const OFX::ImageEffectHostDescription &gHostDescription = *OFX::getImageEffectHostDescription(); + bool openGLRender = false; + std::string message; +#if defined(OFX_SUPPORTS_OPENGLRENDER) + if (gHostDescription.supportsOpenGLRender) { + _useGPUIfAvailable->getValueAtTime(args.time, openGLRender); + } + + if (openGLRender) { + OFX::MultiThread::AutoMutex lock(_rendererInfoMutex); + message = _rendererInfoGL; + } +#endif +#ifdef HAVE_OSMESA + if (!openGLRender) { + OFX::MultiThread::AutoMutex lock(_rendererInfoMutex); + message = _rendererInfoMesa; + } +#endif // HAVE_OSMESA + if (message.empty()) { + sendMessage(OFX::Message::eMessageMessage, "", "OpenGL renderer info not yet available.\n" + "Please execute at least one image render and try again."); + } else { + sendMessage(OFX::Message::eMessageMessage, "", message); + } + } } @@ -732,6 +762,15 @@ ShadertoyPluginFactory::describeInContext(OFX::ImageEffectDescriptor &desc, OFX: } } #endif + + { + OFX::PushButtonParamDescriptor* param = desc.definePushButtonParam(kParamRendererInfo); + param->setLabel(kParamRendererInfoLabel); + param->setHint(kParamRendererInfoHint); + if (page) { + page->addChild(*param); + } + } } OFX::ImageEffect* diff --git a/Shadertoy/Shadertoy.h b/Shadertoy/Shadertoy.h index ac9f2a2e3..473fa3e4d 100644 --- a/Shadertoy/Shadertoy.h +++ b/Shadertoy/Shadertoy.h @@ -105,6 +105,9 @@ class ShadertoyPlugin : public OFX::ImageEffect ShadertoyShaderOpenGL *_imageShader; // (OpenGL-only) shader information bool _imageShaderChanged; // (OpenGL-only) shader ID needs to be recompiled + OFX::MultiThread::Mutex _rendererInfoMutex; + std::string _rendererInfoGL; + #if defined(HAVE_OSMESA) // A list of Mesa contexts available for rendering. // renderMesa() pops the last element, uses it, then pushes it back. @@ -112,6 +115,8 @@ class ShadertoyPlugin : public OFX::ImageEffect // That way, we can have multithreaded OSMesa rendering without having to create a context at each render std::list _osmesa; OFX::MultiThread::Mutex _osmesaMutex; + + std::string _rendererInfoMesa; #endif }; diff --git a/Shadertoy/ShadertoyRender.h b/Shadertoy/ShadertoyRender.h index dd40dfaab..6264c7f49 100644 --- a/Shadertoy/ShadertoyRender.h +++ b/Shadertoy/ShadertoyRender.h @@ -1166,6 +1166,28 @@ ShadertoyPlugin::contextAttached() DPRINT(("GL_SHADING_LANGUAGE_VERSION = %s\n", (char *) glGetString(GL_SHADING_LANGUAGE_VERSION))); DPRINT(("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS))); #endif + { + OFX::MultiThread::AutoMutex lock(_rendererInfoMutex); +#ifdef USE_OSMESA + std::string &message = _rendererInfoMesa; +#else + std::string &message = _rendererInfoGL; +#endif + if (message.empty()) { + message += "OpenGL renderer information:"; + message += "\nGL_RENDERER = "; + message += (char *) glGetString(GL_RENDERER); + message += "\nGL_VERSION = "; + message += (char *) glGetString(GL_VERSION); + message += "\nGL_VENDOR = "; + message += (char *) glGetString(GL_VENDOR); + message += "\nGL_SHADING_LANGUAGE_VERSION = "; + message += (char *) glGetString(GL_SHADING_LANGUAGE_VERSION); + message += "\nGL_EXTENSIONS = "; + message += (char *) glGetString(GL_EXTENSIONS); + } + } + // Non-power-of-two textures are supported if the GL version is 2.0 or greater, or if the implementation exports the GL_ARB_texture_non_power_of_two extension. (Mesa does, of course) int major, minor; getGlVersion(&major, &minor);