Skip to content

Commit

Permalink
Shadertoy: add "Rederer Info..." push button
Browse files Browse the repository at this point in the history
  • Loading branch information
devernay committed Apr 19, 2016
1 parent 39e2ba5 commit 2786f90
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
45 changes: 42 additions & 3 deletions Shadertoy/Shadertoy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/

Expand Down Expand Up @@ -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"

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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 &paramName)
{
if (paramName == kParamImageShaderFileName ||
Expand Down Expand Up @@ -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);
}

}
}

Expand Down Expand Up @@ -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*
Expand Down
5 changes: 5 additions & 0 deletions Shadertoy/Shadertoy.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,18 @@ 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.
// A new context is created if the list is empty.
// That way, we can have multithreaded OSMesa rendering without having to create a context at each render
std::list<OSMesaPrivate *> _osmesa;
OFX::MultiThread::Mutex _osmesaMutex;

std::string _rendererInfoMesa;
#endif
};

Expand Down
22 changes: 22 additions & 0 deletions Shadertoy/ShadertoyRender.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2786f90

Please sign in to comment.