Skip to content

Commit

Permalink
Shadertoy: add "Reset Params Values" button
Browse files Browse the repository at this point in the history
  • Loading branch information
devernay committed Jul 4, 2016
1 parent 7b6aa9a commit 31a0f56
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
75 changes: 75 additions & 0 deletions Shadertoy/Shadertoy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,10 @@ using namespace OFX;
#define kParamAutoLabel "Auto. Params"
#define kParamAutoHint "Automatically set the parameters from the shader source next time image is rendered. May require clicking twice, depending on the OpenFX host."

#define kParamResetParams "resetParams"
#define kParamResetParamsLabel "Reset Params Values"
#define kParamResetParamsHint "Set the extra parameters to their default values, as set automatically by the \"Auto. Params\", or in the \"Extra Parameters\" group."


#define kParamImageShaderDefault \
"void mainImage( out vec4 fragColor, in vec2 fragCoord )\n" \
Expand Down Expand Up @@ -1526,6 +1530,62 @@ ShadertoyPlugin::updateExtra()
}
}

// reset the extra parameters to their default value
void
ShadertoyPlugin::resetParamsValues()
{
beginEditBlock(kParamResetParams);
unsigned paramCount = std::max( 0, std::min(_paramCount->getValue(), NBUNIFORMS) );
for (unsigned i = 0; i < paramCount; ++i) {
UniformTypeEnum t = (UniformTypeEnum)_paramType[i]->getValue();
if (t == eUniformTypeNone) {
continue;
}
switch (t) {
case eUniformTypeBool: {
bool v;
_paramDefaultBool[i]->getValue(v);
_paramValueBool[i]->setValue(v);
break;
}
case eUniformTypeInt: {
int v;
_paramDefaultInt[i]->getValue(v);
_paramValueInt[i]->setValue(v);
break;
}
case eUniformTypeFloat: {
double v;
_paramDefaultFloat[i]->getValue(v);
_paramValueFloat[i]->setValue(v);
break;
}
case eUniformTypeVec2: {
double v0, v1;
_paramDefaultVec2[i]->getValue(v0, v1);
_paramValueVec2[i]->setValue(v0, v1);
break;
}
case eUniformTypeVec3: {
double v0, v1, v2;
_paramDefaultVec3[i]->getValue(v0, v1, v2);
_paramValueVec3[i]->setValue(v0, v1, v2);
break;
}
case eUniformTypeVec4: {
double v0, v1, v2, v3;
_paramDefaultVec4[i]->getValue(v0, v1, v2, v3);
_paramValueVec4[i]->setValue(v0, v1, v2, v3);
break;
}
default:
assert(false);
break;
}
}
endEditBlock();
}

void
ShadertoyPlugin::changedParam(const OFX::InstanceChangedArgs &args,
const std::string &paramName)
Expand Down Expand Up @@ -1599,6 +1659,8 @@ ShadertoyPlugin::changedParam(const OFX::InstanceChangedArgs &args,
updateVisibility();
updateClips();
}
} else if (paramName == kParamResetParams) {
resetParamsValues();
} else if (paramName == kParamImageShaderSource) {
_imageShaderCompile->setEnabled(true);
} else if ( ( (paramName == kParamCount) ||
Expand Down Expand Up @@ -2139,6 +2201,19 @@ ShadertoyPluginFactory::describeInContext(OFX::ImageEffectDescriptor &desc,
OFX::PushButtonParamDescriptor* param = desc.definePushButtonParam(kParamAuto);
param->setLabel(kParamAutoLabel);
param->setHint(kParamAutoHint);
param->setLayoutHint(eLayoutHintNoNewLine, 1);
if (page) {
page->addChild(*param);
}
if (group) {
param->setParent(*group);
}
}

{
OFX::PushButtonParamDescriptor* param = desc.definePushButtonParam(kParamResetParams);
param->setLabel(kParamResetParamsLabel);
param->setHint(kParamResetParamsHint);
if (page) {
page->addChild(*param);
}
Expand Down
1 change: 1 addition & 0 deletions Shadertoy/Shadertoy.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ class ShadertoyPlugin
void updateVisibilityParam(unsigned i, bool visible);
void updateExtra();
void updateClips();
void resetParamsValues();

// do not need to delete these, the ImageEffect is managing them for us
OFX::Clip *_dstClip;
Expand Down

0 comments on commit 31a0f56

Please sign in to comment.