all repos — mgba @ f922f3c1521f02a5f51ca3368512068a4e5b9548

mGBA Game Boy Advance Emulator

Qt: Add preprocessor shader step customization
Jeffrey Pfau jeffrey@endrift.com
Sun, 22 Nov 2015 13:56:53 -0800
commit

f922f3c1521f02a5f51ca3368512068a4e5b9548

parent

a9ae152dd4793064c3159de59cd3bc6b32a8ebee

M CHANGESCHANGES

@@ -5,6 +5,7 @@ - I/O viewer

- Booting of multiboot images - Customization of GIF recording - Libretro: Cheat code support + - Support for GLSL shaders Bugfixes: - Util: Fix PowerPC PNG read/write pixel order - Qt: Use safer isLoaded check in GameController
M src/platform/opengl/gles2.csrc/platform/opengl/gles2.c

@@ -84,18 +84,35 @@ glClearColor(0.f, 0.f, 0.f, 1.f);

struct GBAGLES2Uniform* uniforms = malloc(sizeof(struct GBAGLES2Uniform) * 3); uniforms[0].name = "gamma"; + uniforms[0].readableName = "Gamma"; uniforms[0].type = GL_FLOAT; uniforms[0].value.f = 1.0f; + uniforms[0].min.f = 0.1f; + uniforms[0].max.f = 3.0f; uniforms[1].name = "scale"; + uniforms[1].readableName = "Scale"; uniforms[1].type = GL_FLOAT_VEC3; uniforms[1].value.fvec3[0] = 1.0f; uniforms[1].value.fvec3[1] = 1.0f; uniforms[1].value.fvec3[2] = 1.0f; + uniforms[1].min.fvec3[0] = -1.0f; + uniforms[1].min.fvec3[1] = -1.0f; + uniforms[1].min.fvec3[2] = -1.0f; + uniforms[1].max.fvec3[0] = 2.0f; + uniforms[1].max.fvec3[1] = 2.0f; + uniforms[1].max.fvec3[2] = 2.0f; uniforms[2].name = "bias"; + uniforms[2].readableName = "Bias"; uniforms[2].type = GL_FLOAT_VEC3; uniforms[2].value.fvec3[0] = 0.0f; uniforms[2].value.fvec3[1] = 0.0f; uniforms[2].value.fvec3[2] = 0.0f; + uniforms[2].min.fvec3[0] = -1.0f; + uniforms[2].min.fvec3[1] = -1.0f; + uniforms[2].min.fvec3[2] = -1.0f; + uniforms[2].max.fvec3[0] = 1.0f; + uniforms[2].max.fvec3[1] = 1.0f; + uniforms[2].max.fvec3[2] = 1.0f; GBAGLES2ShaderInit(&context->initialShader, _vertexShader, _fragmentShader, -1, -1, uniforms, 3); GBAGLES2ShaderInit(&context->finalShader, 0, 0, 0, 0, 0, 0); glDeleteFramebuffers(1, &context->finalShader.fbo);
M src/platform/qt/DisplayGL.cppsrc/platform/qt/DisplayGL.cpp

@@ -208,6 +208,19 @@ m_backend->swap = [](VideoBackend* v) {

PainterGL* painter = static_cast<PainterGL*>(v->user); painter->m_gl->swapBuffers(); }; + + m_gl->makeCurrent(); +#if defined(_WIN32) && defined(USE_EPOXY) + epoxy_handle_external_wglMakeCurrent(); +#endif + m_backend->init(m_backend, reinterpret_cast<WHandle>(m_gl->winId())); +#if !defined(_WIN32) || defined(USE_EPOXY) + if (m_supportsShaders) { + m_shader.preprocessShader = static_cast<void*>(&reinterpret_cast<GBAGLES2Context*>(m_backend)->initialShader); + } +#endif + m_gl->doneCurrent(); + m_backend->user = this; m_backend->filter = false; m_backend->lockAspectRatio = false;

@@ -224,11 +237,14 @@ }

for (auto item : m_free) { delete[] item; } - delete m_backend; - m_backend = nullptr; +#if !defined(_WIN32) || defined(USE_EPOXY) if (m_shader.passes) { GBAGLES2ShaderFree(&m_shader); } +#endif + m_backend->deinit(m_backend); + delete m_backend; + m_backend = nullptr; } void PainterGL::setContext(GBAThread* context) {

@@ -265,10 +281,9 @@ m_gl->makeCurrent();

#if defined(_WIN32) && defined(USE_EPOXY) epoxy_handle_external_wglMakeCurrent(); #endif - m_backend->init(m_backend, reinterpret_cast<WHandle>(m_gl->winId())); #if !defined(_WIN32) || defined(USE_EPOXY) - if (m_shader.passes) { + if (m_supportsShaders && m_shader.passes) { GBAGLES2ShaderAttach(reinterpret_cast<GBAGLES2Context*>(m_backend), static_cast<GBAGLES2Shader*>(m_shader.passes), m_shader.nPasses); } #endif

@@ -314,7 +329,6 @@ #endif

dequeueAll(); m_backend->clear(m_backend); m_backend->swap(m_backend); - m_backend->deinit(m_backend); m_gl->doneCurrent(); m_gl->context()->moveToThread(m_gl->thread()); moveToThread(m_gl->thread());
M src/platform/qt/ShaderSelector.cppsrc/platform/qt/ShaderSelector.cpp

@@ -106,55 +106,13 @@ m_ui.author->clear();

} #if !defined(_WIN32) || defined(USE_EPOXY) + m_ui.passes->addTab(makePage(static_cast<GBAGLES2Shader*>(m_shaders->preprocessShader)), tr("Preprocessing")); GBAGLES2Shader* shaders = static_cast<GBAGLES2Shader*>(m_shaders->passes); for (size_t p = 0; p < m_shaders->nPasses; ++p) { - QWidget* page = new QWidget; - QFormLayout* layout = new QFormLayout; - page->setLayout(layout); - for (size_t u = 0 ; u < shaders[p].nUniforms; ++u) { - QGridLayout* settings = new QGridLayout; - GBAGLES2Uniform* uniform = &shaders[p].uniforms[u]; - switch (uniform->type) { - case GL_FLOAT: - addUniform(settings, &uniform->value.f, uniform->min.f, uniform->max.f, 0, 0); - break; - case GL_FLOAT_VEC2: - addUniform(settings, &uniform->value.fvec2[0], uniform->min.fvec2[0], uniform->max.fvec2[0], 0, 0); - addUniform(settings, &uniform->value.fvec2[1], uniform->min.fvec2[1], uniform->max.fvec2[1], 0, 1); - break; - case GL_FLOAT_VEC3: - addUniform(settings, &uniform->value.fvec3[0], uniform->min.fvec3[0], uniform->max.fvec3[0], 0, 0); - addUniform(settings, &uniform->value.fvec3[1], uniform->min.fvec3[1], uniform->max.fvec3[1], 0, 1); - addUniform(settings, &uniform->value.fvec3[2], uniform->min.fvec3[2], uniform->max.fvec3[2], 0, 2); - break; - case GL_FLOAT_VEC4: - addUniform(settings, &uniform->value.fvec4[0], uniform->min.fvec4[0], uniform->max.fvec4[0], 0, 0); - addUniform(settings, &uniform->value.fvec4[1], uniform->min.fvec4[1], uniform->max.fvec4[1], 0, 1); - addUniform(settings, &uniform->value.fvec4[2], uniform->min.fvec4[2], uniform->max.fvec4[2], 0, 2); - addUniform(settings, &uniform->value.fvec4[3], uniform->min.fvec4[3], uniform->max.fvec4[3], 0, 3); - break; - case GL_INT: - addUniform(settings, &uniform->value.i, uniform->min.i, uniform->max.i, 0, 0); - break; - case GL_INT_VEC2: - addUniform(settings, &uniform->value.ivec2[0], uniform->min.ivec2[0], uniform->max.ivec2[0], 0, 0); - addUniform(settings, &uniform->value.ivec2[1], uniform->min.ivec2[1], uniform->max.ivec2[1], 0, 1); - break; - case GL_INT_VEC3: - addUniform(settings, &uniform->value.ivec3[0], uniform->min.ivec3[0], uniform->max.ivec3[0], 0, 0); - addUniform(settings, &uniform->value.ivec3[1], uniform->min.ivec3[1], uniform->max.ivec3[1], 0, 1); - addUniform(settings, &uniform->value.ivec3[2], uniform->min.ivec3[2], uniform->max.ivec3[2], 0, 2); - break; - case GL_INT_VEC4: - addUniform(settings, &uniform->value.ivec4[0], uniform->min.ivec4[0], uniform->max.ivec4[0], 0, 0); - addUniform(settings, &uniform->value.ivec4[1], uniform->min.ivec4[1], uniform->max.ivec4[1], 0, 1); - addUniform(settings, &uniform->value.ivec4[2], uniform->min.ivec4[2], uniform->max.ivec4[2], 0, 2); - addUniform(settings, &uniform->value.ivec4[3], uniform->min.ivec4[3], uniform->max.ivec4[3], 0, 3); - break; - } - layout->addRow(shaders[p].uniforms[u].readableName, settings); + QWidget* page = makePage(&shaders[p]); + if (page) { + m_ui.passes->addTab(page, tr("Pass %1").arg(p + 1)); } - m_ui.passes->addTab(page, tr("Pass %1").arg(p + 1)); } #endif }

@@ -191,3 +149,56 @@ *value = v;

// TODO: Config }); } + +QWidget* ShaderSelector::makePage(GBAGLES2Shader* shader) { + if (!shader->nUniforms) { + return nullptr; + } + QWidget* page = new QWidget; + QFormLayout* layout = new QFormLayout; + page->setLayout(layout); + for (size_t u = 0 ; u < shader->nUniforms; ++u) { + QGridLayout* settings = new QGridLayout; + GBAGLES2Uniform* uniform = &shader->uniforms[u]; + switch (uniform->type) { + case GL_FLOAT: + addUniform(settings, &uniform->value.f, uniform->min.f, uniform->max.f, 0, 0); + break; + case GL_FLOAT_VEC2: + addUniform(settings, &uniform->value.fvec2[0], uniform->min.fvec2[0], uniform->max.fvec2[0], 0, 0); + addUniform(settings, &uniform->value.fvec2[1], uniform->min.fvec2[1], uniform->max.fvec2[1], 0, 1); + break; + case GL_FLOAT_VEC3: + addUniform(settings, &uniform->value.fvec3[0], uniform->min.fvec3[0], uniform->max.fvec3[0], 0, 0); + addUniform(settings, &uniform->value.fvec3[1], uniform->min.fvec3[1], uniform->max.fvec3[1], 0, 1); + addUniform(settings, &uniform->value.fvec3[2], uniform->min.fvec3[2], uniform->max.fvec3[2], 0, 2); + break; + case GL_FLOAT_VEC4: + addUniform(settings, &uniform->value.fvec4[0], uniform->min.fvec4[0], uniform->max.fvec4[0], 0, 0); + addUniform(settings, &uniform->value.fvec4[1], uniform->min.fvec4[1], uniform->max.fvec4[1], 0, 1); + addUniform(settings, &uniform->value.fvec4[2], uniform->min.fvec4[2], uniform->max.fvec4[2], 0, 2); + addUniform(settings, &uniform->value.fvec4[3], uniform->min.fvec4[3], uniform->max.fvec4[3], 0, 3); + break; + case GL_INT: + addUniform(settings, &uniform->value.i, uniform->min.i, uniform->max.i, 0, 0); + break; + case GL_INT_VEC2: + addUniform(settings, &uniform->value.ivec2[0], uniform->min.ivec2[0], uniform->max.ivec2[0], 0, 0); + addUniform(settings, &uniform->value.ivec2[1], uniform->min.ivec2[1], uniform->max.ivec2[1], 0, 1); + break; + case GL_INT_VEC3: + addUniform(settings, &uniform->value.ivec3[0], uniform->min.ivec3[0], uniform->max.ivec3[0], 0, 0); + addUniform(settings, &uniform->value.ivec3[1], uniform->min.ivec3[1], uniform->max.ivec3[1], 0, 1); + addUniform(settings, &uniform->value.ivec3[2], uniform->min.ivec3[2], uniform->max.ivec3[2], 0, 2); + break; + case GL_INT_VEC4: + addUniform(settings, &uniform->value.ivec4[0], uniform->min.ivec4[0], uniform->max.ivec4[0], 0, 0); + addUniform(settings, &uniform->value.ivec4[1], uniform->min.ivec4[1], uniform->max.ivec4[1], 0, 1); + addUniform(settings, &uniform->value.ivec4[2], uniform->min.ivec4[2], uniform->max.ivec4[2], 0, 2); + addUniform(settings, &uniform->value.ivec4[3], uniform->min.ivec4[3], uniform->max.ivec4[3], 0, 3); + break; + } + layout->addRow(shader->uniforms[u].readableName, settings); + } + return page; +}
M src/platform/qt/ShaderSelector.hsrc/platform/qt/ShaderSelector.h

@@ -10,6 +10,7 @@ #include <QDialog>

#include "ui_ShaderSelector.h" +struct GBAGLES2Shader; class QGridLayout; struct VideoShader;

@@ -36,6 +37,7 @@

private: void addUniform(QGridLayout*, float* value, float min, float max, int y, int x); void addUniform(QGridLayout*, int* value, int min, int max, int y, int x); + QWidget* makePage(GBAGLES2Shader*); Ui::ShaderSelector m_ui; Display* m_display;
M src/platform/video-backend.hsrc/platform/video-backend.h

@@ -36,6 +36,7 @@ struct VideoShader {

const char* name; const char* author; const char* description; + void* preprocessShader; void* passes; size_t nPasses; };