diff --git a/bsnes/nall/function.hpp b/bsnes/nall/function.hpp index 39612fd7..acf39b61 100755 --- a/bsnes/nall/function.hpp +++ b/bsnes/nall/function.hpp @@ -17,31 +17,44 @@ namespace nall { struct data_t { R (*callback)(const data_t&, P...); - union { - R (*callback_global)(P...); - struct { - R (derived::*callback_member)(P...); - void *object; - }; + R (*callback_global)(P...); + struct { + R (derived::*callback_member)(P...); + void *callback_object; }; + std::function callback_lambda; } data; static R callback_global(const data_t &data, P... p) { - return data.callback_global(p...); + return data.callback_global(std::forward

(p)...); } template static R callback_member(const data_t &data, P... p) { - return (((C*)data.object)->*((R (C::*&)(P...))data.callback_member))(p...); + return (((C*)data.callback_object)->*((R (C::*&)(P...))data.callback_member))(std::forward

(p)...); + } + + static R callback_lambda(const data_t &data, P... p) { + return data.callback_lambda(std::forward

(p)...); } public: - R operator()(P... p) const { return data.callback(data, p...); } + R operator()(P... p) const { return data.callback(data, std::forward

(p)...); } operator bool() const { return data.callback; } void reset() { data.callback = 0; } - function& operator=(const function &source) { memcpy(&data, &source.data, sizeof(data_t)); return *this; } - function(const function &source) { operator=(source); } + function& operator=(const function &source) { + data.callback = source.data.callback; + data.callback_global = source.data.callback_global; + data.callback_member = source.data.callback_member; + data.callback_object = source.data.callback_object; + data.callback_lambda = source.data.callback_lambda; + return *this; + } + + function(const function &source) { + operator=(source); + } //no pointer function() { @@ -66,7 +79,7 @@ namespace nall { static_assert(sizeof data.callback_member >= sizeof callback, "callback_member is too small"); data.callback = &callback_member; (R (C::*&)(P...))data.callback_member = callback; - data.object = object; + data.callback_object = object; } //const member function pointer @@ -75,15 +88,15 @@ namespace nall { static_assert(sizeof data.callback_member >= sizeof callback, "callback_member is too small"); data.callback = &callback_member; (R (C::*&)(P...))data.callback_member = (R (C::*&)(P...))callback; - data.object = object; + data.callback_object = object; } //lambda function pointer template - function(T callback) { + function(const T &callback) { static_assert(std::is_same::type>::value, "lambda mismatch"); - data.callback = &callback_global; - data.callback_global = (R (*)(P...))callback; + data.callback = &callback_lambda; + data.callback_lambda = callback; } }; } diff --git a/bsnes/nall/string/xml.hpp b/bsnes/nall/string/xml.hpp index 411b477a..169d1388 100755 --- a/bsnes/nall/string/xml.hpp +++ b/bsnes/nall/string/xml.hpp @@ -79,7 +79,7 @@ inline string xml_element::parse() const { data << cdata; offset += strlen(cdata); - source += offset + 3; + source += 9 + offset + 3; continue; } else { return ""; diff --git a/bsnes/phoenix/windows/viewport.cpp b/bsnes/phoenix/windows/viewport.cpp index 497462d7..21e38d79 100755 --- a/bsnes/phoenix/windows/viewport.cpp +++ b/bsnes/phoenix/windows/viewport.cpp @@ -1,6 +1,6 @@ void Viewport::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height) { widget->window = CreateWindow( - L"phoenix_window", L"", + L"phoenix_viewport", L"", WS_CHILD | WS_VISIBLE | WS_DISABLED, x, y, width, height, parent.widget->window, (HMENU)object->id, GetModuleHandle(0), 0 @@ -11,3 +11,7 @@ void Viewport::create(Window &parent, unsigned x, unsigned y, unsigned width, un uintptr_t Viewport::handle() { return (uintptr_t)widget->window; } + +static LRESULT CALLBACK Viewport_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { + return DefWindowProc(hwnd, msg, wparam, lparam); +} diff --git a/bsnes/phoenix/windows/windows.cpp b/bsnes/phoenix/windows/windows.cpp index 4a266d93..8a1ce782 100755 --- a/bsnes/phoenix/windows/windows.cpp +++ b/bsnes/phoenix/windows/windows.cpp @@ -440,6 +440,18 @@ OS::OS() { wc.lpszMenuName = 0; wc.style = CS_HREDRAW | CS_VREDRAW; RegisterClass(&wc); + + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hbrBackground = CreateSolidBrush(RGB(0, 0, 0)); + wc.hCursor = LoadCursor(0, IDC_ARROW); + wc.hIcon = LoadIcon(0, IDI_APPLICATION); + wc.hInstance = GetModuleHandle(0); + wc.lpfnWndProc = Viewport_windowProc; + wc.lpszClassName = L"phoenix_viewport"; + wc.lpszMenuName = 0; + wc.style = CS_HREDRAW | CS_VREDRAW; + RegisterClass(&wc); } } diff --git a/bsnes/ruby/ruby.cpp b/bsnes/ruby/ruby.cpp index bab22501..50bb5a96 100755 --- a/bsnes/ruby/ruby.cpp +++ b/bsnes/ruby/ruby.cpp @@ -14,6 +14,7 @@ InputInterface input; const char *Video::Handle = "Handle"; const char *Video::Synchronize = "Synchronize"; const char *Video::Filter = "Filter"; +const char *Video::Shader = "Shader"; const char *Video::FragmentShader = "FragmentShader"; const char *Video::VertexShader = "VertexShader"; diff --git a/bsnes/ruby/video.hpp b/bsnes/ruby/video.hpp index e7f0f824..c79c5531 100755 --- a/bsnes/ruby/video.hpp +++ b/bsnes/ruby/video.hpp @@ -3,6 +3,7 @@ public: static const char *Handle; static const char *Synchronize; static const char *Filter; + static const char *Shader; static const char *FragmentShader; static const char *VertexShader; diff --git a/bsnes/ruby/video/direct3d.cpp b/bsnes/ruby/video/direct3d.cpp index f4fa5cbc..a9404d8e 100755 --- a/bsnes/ruby/video/direct3d.cpp +++ b/bsnes/ruby/video/direct3d.cpp @@ -24,7 +24,7 @@ public: LPDIRECT3DTEXTURE9 texture; LPDIRECT3DSURFACE9 surface; LPD3DXEFFECT effect; - string shaderSource; + string shader_source_xml; bool lost; unsigned iwidth, iheight; @@ -64,7 +64,7 @@ public: if(name == Video::Handle) return true; if(name == Video::Synchronize) return true; if(name == Video::Filter) return true; - if(name == Video::FragmentShader) return true; + if(name == Video::Shader) return true; return false; } @@ -92,8 +92,8 @@ public: return true; } - if(name == Video::FragmentShader) { - set_fragment_shader(any_cast(value)); + if(name == Video::Shader) { + set_shader(any_cast(value)); return true; } @@ -268,7 +268,7 @@ public: //failure to do so causes scaling issues on some video drivers. if(state.width != rd.right || state.height != rd.bottom) { init(); - set_fragment_shader(shaderSource); + set_shader(shader_source_xml); return; } @@ -327,7 +327,7 @@ public: if(device->Present(0, 0, 0, 0) == D3DERR_DEVICELOST) lost = true; } - void set_fragment_shader(const char *source) { + void set_shader(const char *source) { if(!caps.shader) return; if(effect) { @@ -336,11 +336,27 @@ public: } if(!source || !*source) { - shaderSource = ""; + shader_source_xml = ""; return; } + shader_source_xml = source; - shaderSource = source; + bool is_hlsl = false; + string shader_source; + xml_element document = xml_parse(shader_source_xml); + foreach(head, document.element) { + if(head.name == "shader") { + foreach(attribute, head.attribute) { + if(attribute.name == "language" && attribute.content == "HLSL") is_hlsl = true; + } + foreach(element, head.element) { + if(element.name == "source") { + if(is_hlsl) shader_source = element.parse(); + } + } + } + } + if(shader_source == "") return; HMODULE d3dx; for(unsigned i = 0; i < 256; i++) { @@ -356,7 +372,7 @@ public: TextureProc textureProc = (TextureProc)GetProcAddress(d3dx, "D3DXCreateTextureFromFileA"); LPD3DXBUFFER pBufferErrors = NULL; - effectProc(device, shaderSource, lstrlenA(source), NULL, NULL, 0, NULL, &effect, &pBufferErrors); + effectProc(device, shader_source, lstrlenA(shader_source), NULL, NULL, 0, NULL, &effect, &pBufferErrors); D3DXHANDLE hTech; effect->FindNextValidTechnique(NULL, &hTech); diff --git a/bsnes/ruby/video/glx.cpp b/bsnes/ruby/video/glx.cpp index 3e1c6014..1f6f9a3b 100755 --- a/bsnes/ruby/video/glx.cpp +++ b/bsnes/ruby/video/glx.cpp @@ -2,7 +2,7 @@ video.glx author: byuu license: public domain - last updated: 2010-01-05 + last updated: 2010-09-28 Design notes: SGI's GLX is the X11/Xlib interface to OpenGL. @@ -62,6 +62,7 @@ public: if(name == Video::Handle) return true; if(name == Video::Synchronize) return true; if(name == Video::Filter) return true; + if(name == Video::Shader) return true; if(name == Video::FragmentShader) return true; if(name == Video::VertexShader) return true; return false; @@ -93,6 +94,11 @@ public: return true; } + if(name == Video::Shader) { + OpenGL::set_shader(any_cast(value)); + return true; + } + if(name == Video::FragmentShader) { OpenGL::set_fragment_shader(any_cast(value)); return true; diff --git a/bsnes/ruby/video/opengl.hpp b/bsnes/ruby/video/opengl.hpp index 4be24f06..add60abb 100755 --- a/bsnes/ruby/video/opengl.hpp +++ b/bsnes/ruby/video/opengl.hpp @@ -122,7 +122,7 @@ public: } } - void set_fragment_shader(const char *source) { + void set_shader(const char *source) { if(!shader_support) return; if(fragmentshader) { @@ -131,19 +131,6 @@ public: fragmentshader = 0; } - if(source) { - fragmentshader = glCreateShader(GL_FRAGMENT_SHADER); - glShaderSource(fragmentshader, 1, &source, 0); - glCompileShader(fragmentshader); - glAttachShader(glprogram, fragmentshader); - } - - glLinkProgram(glprogram); - } - - void set_vertex_shader(const char *source) { - if(!shader_support) return; - if(vertexshader) { glDetachShader(glprogram, vertexshader); glDeleteShader(vertexshader); @@ -151,15 +138,49 @@ public: } if(source) { - vertexshader = glCreateShader(GL_VERTEX_SHADER); - glShaderSource(vertexshader, 1, &source, 0); - glCompileShader(vertexshader); - glAttachShader(glprogram, vertexshader); + bool is_glsl = false; + string fragment_source; + string vertex_source; + + xml_element document = xml_parse(source); + foreach(head, document.element) { + if(head.name == "shader") { + foreach(attribute, head.attribute) { + if(attribute.name == "language" && attribute.content == "GLSL") is_glsl = true; + } + foreach(element, head.element) { + if(element.name == "fragment") { + fragment_source = element.parse(); + } else if(element.name == "vertex") { + vertex_source = element.parse(); + } + } + } + } + + if(is_glsl) { + if(fragment_source != "") set_fragment_shader(fragment_source); + if(vertex_source != "") set_vertex_shader(vertex_source); + } } glLinkProgram(glprogram); } + void set_fragment_shader(const char *source) { + fragmentshader = glCreateShader(GL_FRAGMENT_SHADER); + glShaderSource(fragmentshader, 1, &source, 0); + glCompileShader(fragmentshader); + glAttachShader(glprogram, fragmentshader); + } + + void set_vertex_shader(const char *source) { + vertexshader = glCreateShader(GL_VERTEX_SHADER); + glShaderSource(vertexshader, 1, &source, 0); + glCompileShader(vertexshader); + glAttachShader(glprogram, vertexshader); + } + void init() { //disable unused features glDisable(GL_ALPHA_TEST); diff --git a/bsnes/ruby/video/wgl.cpp b/bsnes/ruby/video/wgl.cpp index 23bc2221..333bfae6 100755 --- a/bsnes/ruby/video/wgl.cpp +++ b/bsnes/ruby/video/wgl.cpp @@ -29,8 +29,7 @@ public: if(name == Video::Handle) return true; if(name == Video::Synchronize) return true; if(name == Video::Filter) return true; - if(name == Video::FragmentShader) return true; - if(name == Video::VertexShader) return true; + if(name == Video::Shader) return true; return false; } @@ -59,13 +58,8 @@ public: return true; } - if(name == Video::FragmentShader) { - OpenGL::set_fragment_shader(any_cast(value)); - return true; - } - - if(name == Video::VertexShader) { - OpenGL::set_vertex_shader(any_cast(value)); + if(name == Video::Shader) { + OpenGL::set_shader(any_cast(value)); return true; } diff --git a/bsnes/snes/snes.hpp b/bsnes/snes/snes.hpp index 1d952b10..9bab3d11 100755 --- a/bsnes/snes/snes.hpp +++ b/bsnes/snes/snes.hpp @@ -1,7 +1,7 @@ namespace SNES { namespace Info { static const char Name[] = "bsnes"; - static const char Version[] = "070.02"; + static const char Version[] = "070.03"; static const unsigned SerializerVersion = 13; } } diff --git a/bsnes/ui-phoenix/config.cpp b/bsnes/ui-phoenix/config.cpp index 983a8ff1..9df58337 100755 --- a/bsnes/ui-phoenix/config.cpp +++ b/bsnes/ui-phoenix/config.cpp @@ -17,8 +17,9 @@ void Configuration::create() { attach(video.driver = "", "video.driver"); attach(video.synchronize = false, "video.synchronize"); - attach(video.region = 0, "video.region"); attach(video.smooth = true, "video.smooth"); + attach(video.shader = "", "video.shader"); + attach(video.region = 0, "video.region"); attach(video.scale = 2, "video.scale"); attach(video.aspectRatioCorrection = true, "video.aspectRatioCorrection"); attach(video.contrast = 100, "video.contrast"); diff --git a/bsnes/ui-phoenix/config.hpp b/bsnes/ui-phoenix/config.hpp index d1f65372..498b97fb 100755 --- a/bsnes/ui-phoenix/config.hpp +++ b/bsnes/ui-phoenix/config.hpp @@ -11,8 +11,9 @@ struct Configuration : public configuration { struct Video { string driver; bool synchronize; - bool region; bool smooth; + string shader; + bool region; unsigned scale; bool aspectRatioCorrection; unsigned contrast; diff --git a/bsnes/ui-phoenix/general/file-browser.cpp b/bsnes/ui-phoenix/general/file-browser.cpp index 26a5eda3..99ca9fdc 100755 --- a/bsnes/ui-phoenix/general/file-browser.cpp +++ b/bsnes/ui-phoenix/general/file-browser.cpp @@ -48,6 +48,9 @@ void FileBrowser::fileOpen(FileBrowser::Mode requestedMode, function callback); void create(); diff --git a/bsnes/ui-phoenix/main.cpp b/bsnes/ui-phoenix/main.cpp index 3a48c2a7..e3625bbc 100755 --- a/bsnes/ui-phoenix/main.cpp +++ b/bsnes/ui-phoenix/main.cpp @@ -62,6 +62,7 @@ void Application::main(int argc, char **argv) { video.driver("None"); video.init(); } + utility.setShader(); audio.driver(config.audio.driver); audio.set(Audio::Handle, mainWindow.viewport.handle()); diff --git a/bsnes/ui-phoenix/settings/video.cpp b/bsnes/ui-phoenix/settings/video.cpp index 332da6d0..7b40a500 100755 --- a/bsnes/ui-phoenix/settings/video.cpp +++ b/bsnes/ui-phoenix/settings/video.cpp @@ -5,7 +5,7 @@ void VideoSettings::create() { Window::create(0, 0, 256, 256, "Video Settings"); setDefaultFont(application.proportionalFont); - unsigned x = 5, y = 5; + unsigned x = 5, y = 5, height = Style::TextBoxHeight; colorAdjustmentLabel.create(*this, x, y, 430, Style::LabelHeight, "Color Adjustment :."); y += Style::LabelHeight + 5; colorAdjustmentLabel.setFont(application.proportionalFontBold); @@ -24,6 +24,15 @@ void VideoSettings::create() { gammaRampCheck.create (*this, x, y, 430, Style::CheckBoxHeight, "Enable NTSC gamma ramp simulation"); y += Style::CheckBoxHeight + 5; + shaderLabel.create(*this, x, y, 340, Style::LabelHeight, "Pixel Shader :."); y += Style::LabelHeight + 5; + shaderLabel.setFont(application.proportionalFontBold); + + shaderPath.create(*this, x, y, 430 - height - height - 10, height); + shaderPath.setEditable(false); + shaderPath.setText(config.video.shader); + shaderClear.create(*this, x + 430 - height - height - 5, y, height, height, ""); + shaderSelect.create(*this, x + 430 - height, y, height, height, "..."); y += height + 5; + setGeometry(160, 160, 440, y); contrastSlider.setPosition(config.video.contrast); @@ -33,6 +42,20 @@ void VideoSettings::create() { contrastSlider.onChange = brightnessSlider.onChange = gammaSlider.onChange = gammaRampCheck.onTick = { &VideoSettings::adjust, this }; + + shaderClear.onTick = []() { + config.video.shader = ""; + videoSettings.shaderPath.setText(config.video.shader); + utility.setShader(); + }; + + shaderSelect.onTick = []() { + fileBrowser.fileOpen(FileBrowser::Mode::Shader, [](string filename) { + config.video.shader = filename; + videoSettings.shaderPath.setText(config.video.shader); + utility.setShader(); + }); + }; } void VideoSettings::adjust() { diff --git a/bsnes/ui-phoenix/settings/video.hpp b/bsnes/ui-phoenix/settings/video.hpp index fd946d7e..04cfcb60 100755 --- a/bsnes/ui-phoenix/settings/video.hpp +++ b/bsnes/ui-phoenix/settings/video.hpp @@ -10,6 +10,10 @@ struct VideoSettings : Window { Label gammaValue; HorizontalSlider gammaSlider; CheckBox gammaRampCheck; + Label shaderLabel; + TextBox shaderPath; + Button shaderClear; + Button shaderSelect; void create(); void adjust(); diff --git a/bsnes/ui-phoenix/utility/utility.cpp b/bsnes/ui-phoenix/utility/utility.cpp index d25d4514..a54c56e1 100755 --- a/bsnes/ui-phoenix/utility/utility.cpp +++ b/bsnes/ui-phoenix/utility/utility.cpp @@ -51,6 +51,12 @@ void Utility::setScale(unsigned scale) { mainWindow.setGeometry(128, 128, width, height); } +void Utility::setShader() { + string data; + data.readfile(config.video.shader); + video.set(Video::Shader, (const char*)data); +} + void Utility::cartridgeLoaded() { SNES::system.power(); cheatEditor.load(cartridge.baseName); diff --git a/bsnes/ui-phoenix/utility/utility.hpp b/bsnes/ui-phoenix/utility/utility.hpp index 589af593..e8a4e551 100755 --- a/bsnes/ui-phoenix/utility/utility.hpp +++ b/bsnes/ui-phoenix/utility/utility.hpp @@ -5,6 +5,7 @@ struct Utility : property { void showMessage(const char *text); void setScale(unsigned scale = 0); + void setShader(); void cartridgeLoaded(); void cartridgeUnloaded(); diff --git a/bsnes/ui-qt/config.cpp b/bsnes/ui-qt/config.cpp index 2b62f405..a72c9b4b 100755 --- a/bsnes/ui-qt/config.cpp +++ b/bsnes/ui-qt/config.cpp @@ -60,8 +60,7 @@ Configuration::Configuration() { attach(path.bsx = "", "path.bsx"); attach(path.st = "", "path.st"); attach(path.sgb = "", "path.sgb"); - attach(path.fragmentShader = "", "path.fragmentShader"); - attach(path.vertexShader = "", "path.vertexShader"); + attach(path.shader = "", "path.shader"); attach(path.current.folder = "", "path.current.folder"); attach(path.current.movie = "", "path.current.movie"); diff --git a/bsnes/ui-qt/config.hpp b/bsnes/ui-qt/config.hpp index 67b5c2e6..34d8113a 100755 --- a/bsnes/ui-qt/config.hpp +++ b/bsnes/ui-qt/config.hpp @@ -30,7 +30,7 @@ public: string startup; //startup path string rom, save, state, patch, cheat, data; string bsx, st, sgb; - string fragmentShader, vertexShader; + string shader; struct Current { string folder, movie, shader, cartridge; diff --git a/bsnes/ui-qt/settings/video.cpp b/bsnes/ui-qt/settings/video.cpp index e0bb0932..35693abd 100755 --- a/bsnes/ui-qt/settings/video.cpp +++ b/bsnes/ui-qt/settings/video.cpp @@ -138,29 +138,14 @@ VideoSettingsWindow::VideoSettingsWindow() { pixelShaderLayout = new QGridLayout; layout->addLayout(pixelShaderLayout); - fragmentShaderLabel = new QLabel("Fragment:"); - pixelShaderLayout->addWidget(fragmentShaderLabel, 0, 0); + shaderValue = new QLineEdit; + pixelShaderLayout->addWidget(shaderValue, 0, 0); - fragmentShaderValue = new QLineEdit; - pixelShaderLayout->addWidget(fragmentShaderValue, 0, 1); + shaderSelect = new QPushButton("Select ..."); + pixelShaderLayout->addWidget(shaderSelect, 0, 1); - fragmentShaderSelect = new QPushButton("Select ..."); - pixelShaderLayout->addWidget(fragmentShaderSelect, 0, 2); - - fragmentShaderDefault = new QPushButton("Default"); - pixelShaderLayout->addWidget(fragmentShaderDefault, 0, 3); - - vertexShaderLabel = new QLabel("Vertex:"); - pixelShaderLayout->addWidget(vertexShaderLabel, 1, 0); - - vertexShaderValue = new QLineEdit; - pixelShaderLayout->addWidget(vertexShaderValue, 1, 1); - - vertexShaderSelect = new QPushButton("Select ..."); - pixelShaderLayout->addWidget(vertexShaderSelect, 1, 2); - - vertexShaderDefault = new QPushButton("Default"); - pixelShaderLayout->addWidget(vertexShaderDefault, 1, 3); + shaderDefault = new QPushButton("Default"); + pixelShaderLayout->addWidget(shaderDefault, 0, 2); connect(autoHideFullscreenMenu, SIGNAL(stateChanged(int)), this, SLOT(autoHideFullscreenMenuToggle())); connect(contrastSlider, SIGNAL(valueChanged(int)), this, SLOT(contrastAdjust(int))); @@ -172,31 +157,18 @@ VideoSettingsWindow::VideoSettingsWindow() { connect(cropTopSlider, SIGNAL(valueChanged(int)), this, SLOT(cropTopAdjust(int))); connect(cropRightSlider, SIGNAL(valueChanged(int)), this, SLOT(cropRightAdjust(int))); connect(cropBottomSlider, SIGNAL(valueChanged(int)), this, SLOT(cropBottomAdjust(int))); - connect(fragmentShaderSelect, SIGNAL(released()), this, SLOT(selectFragmentShader())); - connect(fragmentShaderDefault, SIGNAL(released()), this, SLOT(defaultFragmentShader())); - connect(vertexShaderSelect, SIGNAL(released()), this, SLOT(selectVertexShader())); - connect(vertexShaderDefault, SIGNAL(released()), this, SLOT(defaultVertexShader())); + connect(shaderSelect, SIGNAL(released()), this, SLOT(selectShader())); + connect(shaderDefault, SIGNAL(released()), this, SLOT(defaultShader())); syncUi(); } void VideoSettingsWindow::synchronizePixelShaderSettings() { - if(!video.cap(Video::FragmentShader) && !video.cap(Video::VertexShader)) { + if(video.cap(Video::Shader) == false) { pixelShaderLabel->hide(); - } - - if(!video.cap(Video::FragmentShader)) { - fragmentShaderLabel->hide(); - fragmentShaderValue->hide(); - fragmentShaderSelect->hide(); - fragmentShaderDefault->hide(); - } - - if(!video.cap(Video::VertexShader)) { - vertexShaderLabel->hide(); - vertexShaderValue->hide(); - vertexShaderSelect->hide(); - vertexShaderDefault->hide(); + shaderValue->hide(); + shaderSelect->hide(); + shaderDefault->hide(); } } @@ -239,8 +211,7 @@ void VideoSettingsWindow::syncUi() { cropBottomValue->setText(string() << n << "%"); cropBottomSlider->setSliderPosition(n); - fragmentShaderValue->setText(config().path.fragmentShader); - vertexShaderValue->setText(config().path.vertexShader); + shaderValue->setText(config().path.shader); } void VideoSettingsWindow::autoHideFullscreenMenuToggle() { @@ -301,41 +272,21 @@ void VideoSettingsWindow::cropBottomAdjust(int state) { syncUi(); } -void VideoSettingsWindow::selectFragmentShader() { +void VideoSettingsWindow::selectShader() { fileBrowser->onChange.reset(); - fileBrowser->onActivate = { &VideoSettingsWindow::assignFragmentShader, this }; - fileBrowser->onAccept = { &VideoSettingsWindow::assignFragmentShader, this }; - fileBrowser->setWindowTitle("Select Fragment Shader"); + fileBrowser->onActivate = { &VideoSettingsWindow::assignShader, this }; + fileBrowser->onAccept = { &VideoSettingsWindow::assignShader, this }; + fileBrowser->setWindowTitle("Select Pixel Shader"); fileBrowser->setPath(config().path.current.shader); - fileBrowser->setNameFilters("All files (*)"); + fileBrowser->setNameFilters("Shader files (*.shader)"); fileBrowser->chooseFile(); } -void VideoSettingsWindow::selectVertexShader() { - fileBrowser->onChange.reset(); - fileBrowser->onActivate = { &VideoSettingsWindow::assignVertexShader, this }; - fileBrowser->onAccept = { &VideoSettingsWindow::assignVertexShader, this }; - fileBrowser->setWindowTitle("Select Vertex Shader"); - fileBrowser->setPath(config().path.current.shader); - fileBrowser->setNameFilters("All files (*)"); - fileBrowser->chooseFile(); -} +void VideoSettingsWindow::defaultShader() { assignShader(""); } -void VideoSettingsWindow::defaultFragmentShader() { assignFragmentShader(""); } -void VideoSettingsWindow::defaultVertexShader() { assignVertexShader(""); } - -void VideoSettingsWindow::assignFragmentShader(const string &filename) { +void VideoSettingsWindow::assignShader(const string &filename) { if(filename == "" || QDir(filename).exists() == false) { - config().path.fragmentShader = filename; - if(filename != "") config().path.current.shader = dir(filename); - syncUi(); - utility.updatePixelShader(); - } -} - -void VideoSettingsWindow::assignVertexShader(const string &filename) { - if(filename == "" || QDir(filename).exists() == false) { - config().path.vertexShader = filename; + config().path.shader = filename; if(filename != "") config().path.current.shader = dir(filename); syncUi(); utility.updatePixelShader(); diff --git a/bsnes/ui-qt/settings/video.moc.hpp b/bsnes/ui-qt/settings/video.moc.hpp index 38895a30..ac362006 100755 --- a/bsnes/ui-qt/settings/video.moc.hpp +++ b/bsnes/ui-qt/settings/video.moc.hpp @@ -37,14 +37,9 @@ public: QSlider *cropBottomSlider; QLabel *pixelShaderLabel; QGridLayout *pixelShaderLayout; - QLabel *fragmentShaderLabel; - QLineEdit *fragmentShaderValue; - QPushButton *fragmentShaderSelect; - QPushButton *fragmentShaderDefault; - QLabel *vertexShaderLabel; - QLineEdit *vertexShaderValue; - QPushButton *vertexShaderSelect; - QPushButton *vertexShaderDefault; + QLineEdit *shaderValue; + QPushButton *shaderSelect; + QPushButton *shaderDefault; void synchronizePixelShaderSettings(); void syncUi(); @@ -61,14 +56,11 @@ private slots: void cropTopAdjust(int); void cropRightAdjust(int); void cropBottomAdjust(int); - void selectFragmentShader(); - void selectVertexShader(); - void defaultFragmentShader(); - void defaultVertexShader(); + void selectShader(); + void defaultShader(); private: - void assignFragmentShader(const string &filename); - void assignVertexShader(const string &filename); + void assignShader(const string &filename); }; extern VideoSettingsWindow *videoSettingsWindow; diff --git a/bsnes/ui-qt/utility/utility.cpp b/bsnes/ui-qt/utility/utility.cpp index d1077ef0..28dd19ff 100755 --- a/bsnes/ui-qt/utility/utility.cpp +++ b/bsnes/ui-qt/utility/utility.cpp @@ -73,16 +73,10 @@ void Utility::updateColorFilter() { void Utility::updatePixelShader() { string filedata; - if(filedata.readfile(config().path.fragmentShader)) { - video.set(Video::FragmentShader, (const char*)filedata); + if(filedata.readfile(config().path.shader)) { + video.set(Video::Shader, (const char*)filedata); } else { - video.set(Video::FragmentShader, (const char*)0); - } - - if(filedata.readfile(config().path.vertexShader)) { - video.set(Video::VertexShader, (const char*)filedata); - } else { - video.set(Video::VertexShader, (const char*)0); + video.set(Video::Shader, (const char*)0); } }