PostProcessing: Add support for user-supplied anaglyph shaders.

There are lots of different anaglyph glasses out there and there may be even more creative uses for stereoscopic post-processing shaders.
This commit is contained in:
Jules Blok
2015-01-03 01:33:30 +01:00
parent a93433a860
commit 262c3b19ec
14 changed files with 110 additions and 58 deletions

View File

@ -395,29 +395,14 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string &title, con
}
// postproc shader
if (vconfig.backend_info.PPShaders.size())
if (vconfig.backend_info.bSupportsPostProcessing)
{
wxFlexGridSizer* const szr_pp = new wxFlexGridSizer(3, 5, 5);
choice_ppshader = new wxChoice(page_enh, wxID_ANY);
RegisterControl(choice_ppshader, wxGetTranslation(ppshader_desc));
choice_ppshader->AppendString(_("(off)"));
button_config_pp = new wxButton(page_enh, wxID_ANY, _("Config"));
for (const std::string& shader : vconfig.backend_info.PPShaders)
{
choice_ppshader->AppendString(StrToWxStr(shader));
}
if (vconfig.sPostProcessingShader.empty() || vconfig.iStereoMode == STEREO_ANAGLYPH)
choice_ppshader->Select(0);
else
choice_ppshader->SetStringSelection(StrToWxStr(vconfig.sPostProcessingShader));
// Should the configuration button be loaded by default?
PostProcessingShaderConfiguration postprocessing_shader;
postprocessing_shader.LoadShader(vconfig.sPostProcessingShader);
button_config_pp->Enable(postprocessing_shader.HasOptions());
PopulatePostProcessingShaders();
choice_ppshader->Bind(wxEVT_CHOICE, &VideoConfigDiag::Event_PPShader, this);
button_config_pp->Bind(wxEVT_BUTTON, &VideoConfigDiag::Event_ConfigurePPShader, this);
@ -745,3 +730,36 @@ void VideoConfigDiag::CreateDescriptionArea(wxPanel* const page, wxBoxSizer* con
// Store description text object for later lookup
desc_texts.insert(std::pair<wxWindow*,wxStaticText*>(page, desc_text));
}
void VideoConfigDiag::PopulatePostProcessingShaders()
{
std::vector<std::string> &shaders = (vconfig.iStereoMode == STEREO_ANAGLYPH) ?
vconfig.backend_info.AnaglyphShaders : vconfig.backend_info.PPShaders;
if (shaders.empty())
return;
if (vconfig.iStereoMode != STEREO_ANAGLYPH)
choice_ppshader->AppendString(_("(off)"));
for (const std::string& shader : shaders)
{
choice_ppshader->AppendString(StrToWxStr(shader));
}
if (!choice_ppshader->SetStringSelection(StrToWxStr(vconfig.sPostProcessingShader)))
{
// Invalid shader, reset it to default
choice_ppshader->Select(0);
if (vconfig.iStereoMode == STEREO_ANAGLYPH)
vconfig.sPostProcessingShader = shaders[0];
else
vconfig.sPostProcessingShader.clear();
}
// Should the configuration button be loaded by default?
PostProcessingShaderConfiguration postprocessing_shader;
postprocessing_shader.LoadShader(vconfig.sPostProcessingShader);
button_config_pp->Enable(postprocessing_shader.HasOptions());
}

View File

@ -144,7 +144,7 @@ protected:
void Event_PPShader(wxCommandEvent &ev)
{
const int sel = ev.GetInt();
if (sel)
if (sel || vconfig.iStereoMode == STEREO_ANAGLYPH)
vconfig.sPostProcessingShader = WxStrToStr(ev.GetString());
else
vconfig.sPostProcessingShader.clear();
@ -152,7 +152,7 @@ protected:
// Should we enable the configuration button?
PostProcessingShaderConfiguration postprocessing_shader;
postprocessing_shader.LoadShader(vconfig.sPostProcessingShader);
button_config_pp->Enable(postprocessing_shader.HasOptions() && vconfig.iStereoMode != STEREO_ANAGLYPH);
button_config_pp->Enable(postprocessing_shader.HasOptions());
ev.Skip();
}
@ -181,15 +181,10 @@ protected:
void Event_StereoMode(wxCommandEvent &ev)
{
if (ev.GetInt() == STEREO_ANAGLYPH && vconfig.backend_info.PPShaders.size())
if (vconfig.backend_info.bSupportsPostProcessing)
{
// Anaglyph overrides post-processing shaders
choice_ppshader->Select(0);
choice_ppshader->Enable(false);
}
else if (vconfig.backend_info.PPShaders.size())
{
choice_ppshader->Enable(true);
choice_ppshader->Clear();
}
ev.Skip();
@ -214,6 +209,10 @@ protected:
virtual_xfb->Enable(vconfig.bUseXFB);
real_xfb->Enable(vconfig.bUseXFB);
// Repopulating the post-processing shaders can't be done from an event
if (choice_ppshader && choice_ppshader->IsEmpty())
PopulatePostProcessingShaders();
// Things which shouldn't be changed during emulation
if (Core::IsRunning())
{
@ -251,6 +250,7 @@ protected:
void Evt_EnterControl(wxMouseEvent& ev);
void Evt_LeaveControl(wxMouseEvent& ev);
void CreateDescriptionArea(wxPanel* const page, wxBoxSizer* const sizer);
void PopulatePostProcessingShaders();
wxChoice* choice_backend;
wxChoice* choice_adapter;