mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-07 22:55:40 +12:00
Qt: Shader editor now works
This commit is contained in:
parent
d87477832b
commit
186fd3b94b
6 changed files with 63 additions and 35 deletions
include
src
core/renderer_gl
host_shaders
panda_qt
|
@ -17,12 +17,11 @@ class ShaderEditorWindow : public QDialog {
|
|||
Zep::IZepReplProvider replProvider;
|
||||
static constexpr float fontSize = 14.0f;
|
||||
|
||||
// Whether this backend supports shader editor
|
||||
bool shaderEditorSupported = true;
|
||||
|
||||
public:
|
||||
// Whether this backend supports shader editor
|
||||
bool supported = true;
|
||||
|
||||
ShaderEditorWindow(QWidget* parent, const std::string& filename, const std::string& initialText);
|
||||
void setText(const std::string& text) { zepWidget.GetEditor().GetMRUBuffer()->SetText(text); }
|
||||
|
||||
void setEnable(bool enable);
|
||||
};
|
|
@ -92,6 +92,7 @@ class RendererGL final : public Renderer {
|
|||
// Note: The caller is responsible for deleting the currently bound FBO before calling this
|
||||
void setFBO(uint handle) { screenFramebuffer.m_handle = handle; }
|
||||
void resetStateManager() { gl.reset(); }
|
||||
void initUbershader(OpenGL::Program& program);
|
||||
|
||||
#ifdef PANDA3DS_FRONTEND_QT
|
||||
virtual void initGraphicsContext([[maybe_unused]] GL::Context* context) override { initGraphicsContextInternal(); }
|
||||
|
|
|
@ -57,24 +57,7 @@ void RendererGL::initGraphicsContextInternal() {
|
|||
OpenGL::Shader vert({vertexShaderSource.begin(), vertexShaderSource.size()}, OpenGL::Vertex);
|
||||
OpenGL::Shader frag({fragmentShaderSource.begin(), fragmentShaderSource.size()}, OpenGL::Fragment);
|
||||
triangleProgram.create({vert, frag});
|
||||
gl.useProgram(triangleProgram);
|
||||
|
||||
textureEnvSourceLoc = OpenGL::uniformLocation(triangleProgram, "u_textureEnvSource");
|
||||
textureEnvOperandLoc = OpenGL::uniformLocation(triangleProgram, "u_textureEnvOperand");
|
||||
textureEnvCombinerLoc = OpenGL::uniformLocation(triangleProgram, "u_textureEnvCombiner");
|
||||
textureEnvColorLoc = OpenGL::uniformLocation(triangleProgram, "u_textureEnvColor");
|
||||
textureEnvScaleLoc = OpenGL::uniformLocation(triangleProgram, "u_textureEnvScale");
|
||||
|
||||
depthScaleLoc = OpenGL::uniformLocation(triangleProgram, "u_depthScale");
|
||||
depthOffsetLoc = OpenGL::uniformLocation(triangleProgram, "u_depthOffset");
|
||||
depthmapEnableLoc = OpenGL::uniformLocation(triangleProgram, "u_depthmapEnable");
|
||||
picaRegLoc = OpenGL::uniformLocation(triangleProgram, "u_picaRegs");
|
||||
|
||||
// Init sampler objects. Texture 0 goes in texture unit 0, texture 1 in TU 1, texture 2 in TU 2, and the light maps go in TU 3
|
||||
glUniform1i(OpenGL::uniformLocation(triangleProgram, "u_tex0"), 0);
|
||||
glUniform1i(OpenGL::uniformLocation(triangleProgram, "u_tex1"), 1);
|
||||
glUniform1i(OpenGL::uniformLocation(triangleProgram, "u_tex2"), 2);
|
||||
glUniform1i(OpenGL::uniformLocation(triangleProgram, "u_tex_lighting_lut"), 3);
|
||||
initUbershader(triangleProgram);
|
||||
|
||||
auto displayVertexShaderSource = gl_resources.open("opengl_display.vert");
|
||||
auto displayFragmentShaderSource = gl_resources.open("opengl_display.frag");
|
||||
|
@ -814,5 +797,41 @@ void RendererGL::deinitGraphicsContext() {
|
|||
printf("RendererGL::DeinitGraphicsContext called\n");
|
||||
}
|
||||
|
||||
std::string RendererGL::getUbershader() { return ""; }
|
||||
void RendererGL::setUbershader(const std::string& shader) {}
|
||||
std::string RendererGL::getUbershader() {
|
||||
auto gl_resources = cmrc::RendererGL::get_filesystem();
|
||||
auto fragmentShader = gl_resources.open("opengl_fragment_shader.frag");
|
||||
|
||||
return std::string(fragmentShader.begin(), fragmentShader.end());
|
||||
}
|
||||
|
||||
void RendererGL::setUbershader(const std::string& shader) {
|
||||
auto gl_resources = cmrc::RendererGL::get_filesystem();
|
||||
auto vertexShaderSource = gl_resources.open("opengl_vertex_shader.vert");
|
||||
|
||||
OpenGL::Shader vert({vertexShaderSource.begin(), vertexShaderSource.size()}, OpenGL::Vertex);
|
||||
OpenGL::Shader frag(shader, OpenGL::Fragment);
|
||||
triangleProgram.create({vert, frag});
|
||||
|
||||
initUbershader(triangleProgram);
|
||||
}
|
||||
|
||||
void RendererGL::initUbershader(OpenGL::Program& program) {
|
||||
gl.useProgram(program);
|
||||
|
||||
textureEnvSourceLoc = OpenGL::uniformLocation(program, "u_textureEnvSource");
|
||||
textureEnvOperandLoc = OpenGL::uniformLocation(program, "u_textureEnvOperand");
|
||||
textureEnvCombinerLoc = OpenGL::uniformLocation(program, "u_textureEnvCombiner");
|
||||
textureEnvColorLoc = OpenGL::uniformLocation(program, "u_textureEnvColor");
|
||||
textureEnvScaleLoc = OpenGL::uniformLocation(program, "u_textureEnvScale");
|
||||
|
||||
depthScaleLoc = OpenGL::uniformLocation(program, "u_depthScale");
|
||||
depthOffsetLoc = OpenGL::uniformLocation(program, "u_depthOffset");
|
||||
depthmapEnableLoc = OpenGL::uniformLocation(program, "u_depthmapEnable");
|
||||
picaRegLoc = OpenGL::uniformLocation(program, "u_picaRegs");
|
||||
|
||||
// Init sampler objects. Texture 0 goes in texture unit 0, texture 1 in TU 1, texture 2 in TU 2, and the light maps go in TU 3
|
||||
glUniform1i(OpenGL::uniformLocation(program, "u_tex0"), 0);
|
||||
glUniform1i(OpenGL::uniformLocation(program, "u_tex1"), 1);
|
||||
glUniform1i(OpenGL::uniformLocation(program, "u_tex2"), 2);
|
||||
glUniform1i(OpenGL::uniformLocation(program, "u_tex_lighting_lut"), 3);
|
||||
}
|
|
@ -279,26 +279,26 @@ void calcLighting(out vec4 primary_color, out vec4 secondary_color) {
|
|||
}
|
||||
}
|
||||
|
||||
uint lookup_config = bitfieldExtract(GPUREG_LIGHTING_CONFIG0, 4, 4);
|
||||
uint lookup_config = bitfieldExtract(GPUREG_LIGHTi_CONFIG, 4, 4);
|
||||
if (lookup_config == 0u) {
|
||||
d[D1_LUT] = 1.0;
|
||||
d[FR_LUT] = 1.0;
|
||||
d[D1_LUT] = 0.0;
|
||||
d[FR_LUT] = 0.0;
|
||||
d[RG_LUT] = d[RB_LUT] = d[RR_LUT];
|
||||
} else if (lookup_config == 1u) {
|
||||
d[D0_LUT] = 1.0;
|
||||
d[D1_LUT] = 1.0;
|
||||
d[D0_LUT] = 0.0;
|
||||
d[D1_LUT] = 0.0;
|
||||
d[RG_LUT] = d[RB_LUT] = d[RR_LUT];
|
||||
} else if (lookup_config == 2u) {
|
||||
d[FR_LUT] = 1.0;
|
||||
d[SP_LUT] = 1.0;
|
||||
d[FR_LUT] = 0.0;
|
||||
d[SP_LUT] = 0.0;
|
||||
d[RG_LUT] = d[RB_LUT] = d[RR_LUT];
|
||||
} else if (lookup_config == 3u) {
|
||||
d[SP_LUT] = 1.0;
|
||||
d[SP_LUT] = 0.0;
|
||||
d[RG_LUT] = d[RB_LUT] = d[RR_LUT] = 1.0;
|
||||
} else if (lookup_config == 4u) {
|
||||
d[FR_LUT] = 1.0;
|
||||
d[FR_LUT] = 0.0;
|
||||
} else if (lookup_config == 5u) {
|
||||
d[D1_LUT] = 1.0;
|
||||
d[D1_LUT] = 0.0;
|
||||
} else if (lookup_config == 6u) {
|
||||
d[RG_LUT] = d[RB_LUT] = d[RR_LUT];
|
||||
}
|
||||
|
|
|
@ -78,7 +78,11 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent)
|
|||
patchWindow = new PatchWindow(this);
|
||||
luaEditor = new TextEditorWindow(this, "script.lua", "");
|
||||
shaderEditor = new ShaderEditorWindow(this, "shader.glsl", "");
|
||||
|
||||
shaderEditor->setEnable(emu->getRenderer()->supportsShaderReload());
|
||||
if (shaderEditor->supported) {
|
||||
shaderEditor->setText(emu->getRenderer()->getUbershader());
|
||||
}
|
||||
|
||||
auto args = QCoreApplication::arguments();
|
||||
if (args.size() > 1) {
|
||||
|
@ -351,6 +355,11 @@ void MainWindow::dispatchMessage(const EmulatorMessage& message) {
|
|||
emu->getServiceManager().getHID().setTouchScreenPress(message.touchscreen.x, message.touchscreen.y);
|
||||
break;
|
||||
case MessageType::ReleaseTouchscreen: emu->getServiceManager().getHID().releaseTouchScreen(); break;
|
||||
|
||||
case MessageType::ReloadUbershader:
|
||||
emu->getRenderer()->setUbershader(*message.string.str);
|
||||
delete message.string.str;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ ShaderEditorWindow::ShaderEditorWindow(QWidget* parent, const std::string& filen
|
|||
}
|
||||
|
||||
void ShaderEditorWindow::setEnable(bool enable) {
|
||||
shaderEditorSupported = enable;
|
||||
supported = enable;
|
||||
|
||||
if (enable) {
|
||||
setDisabled(false);
|
||||
|
|
Loading…
Add table
Reference in a new issue