From 10ee34683e0e42fc4eb8700113b439337c470013 Mon Sep 17 00:00:00 2001 From: deltaoscarmike <37912794+deltaoscarmike@users.noreply.github.com> Date: Sat, 17 Nov 2018 13:13:25 +0100 Subject: [PATCH 1/4] DX to openGL/openGLES transpilation fixes --- src/libprojectM/Renderer/Renderer.cpp | 4 +- src/libprojectM/Renderer/ShaderEngine.cpp | 14 +- src/libprojectM/Renderer/ShaderEngine.hpp | 4 +- .../Renderer/hlslparser/src/GLSLGenerator.cpp | 141 +++++++++++++----- .../Renderer/hlslparser/src/GLSLGenerator.h | 5 +- .../Renderer/hlslparser/src/HLSLParser.cpp | 4 + 6 files changed, 123 insertions(+), 49 deletions(-) diff --git a/src/libprojectM/Renderer/Renderer.cpp b/src/libprojectM/Renderer/Renderer.cpp index 5da27fcb6..79bd974dd 100644 --- a/src/libprojectM/Renderer/Renderer.cpp +++ b/src/libprojectM/Renderer/Renderer.cpp @@ -193,7 +193,7 @@ std::string Renderer::SetPipeline(Pipeline &pipeline) { currentPipe = &pipeline; shaderEngine.reset(); - if (!shaderEngine.loadPresetShaders(pipeline)) { + if (!shaderEngine.loadPresetShaders(pipeline, m_presetName)) { return "Shader compilation error"; } @@ -467,7 +467,7 @@ void Renderer::reset(int w, int h) shaderEngine.setParams(texsizeX, texsizeY, beatDetect, textureManager); shaderEngine.reset(); - shaderEngine.loadPresetShaders(*currentPipe); + shaderEngine.loadPresetShaders(*currentPipe, m_presetName); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); diff --git a/src/libprojectM/Renderer/ShaderEngine.cpp b/src/libprojectM/Renderer/ShaderEngine.cpp index a182720a8..459db53b1 100644 --- a/src/libprojectM/Renderer/ShaderEngine.cpp +++ b/src/libprojectM/Renderer/ShaderEngine.cpp @@ -19,8 +19,10 @@ #ifdef USE_GLES #define GLSL_VERSION "300 es" + #define SHADER_VERSION M4::GLSLGenerator::Version_300_ES #else #define GLSL_VERSION "330" + #define SHADER_VERSION M4::GLSLGenerator::Version_330 #endif @@ -340,7 +342,7 @@ std::string blur1_frag( " blur.xyz = blur.xyz*fscale + fbias;\n" "" " color.xyz = blur;\n" - " color.w = 1;\n" + " color.w = 1.0;\n" "}\n"); std::string blur2_frag( @@ -383,13 +385,13 @@ std::string blur2_frag( " blur.xyz *= w_div;\n" "" " // tone it down at the edges: (only happens on 1st X pass!)\n" - " float t = min( min(fragment_texture.x, fragment_texture.y), 1-max(fragment_texture.x, fragment_texture.y) );\n" + " float t = min( min(fragment_texture.x, fragment_texture.y), 1.0-max(fragment_texture.x, fragment_texture.y) );\n" " t = sqrt(t);\n" " t = edge_darken_c1 + edge_darken_c2*clamp(t*edge_darken_c3, 0.0, 1.0);\n" " blur.xyz *= t;\n" "" " color.xyz = blur;\n" - " color.w = 1;\n" + " color.w = 1.0;\n" "}\n"); @@ -741,7 +743,7 @@ GLuint ShaderEngine::compilePresetShader(const PresentShaderType shaderType, Sha } // generate GLSL - if (!generator.Generate(&tree, M4::GLSLGenerator::Target_FragmentShader, M4::GLSLGenerator::Version_140, "PS")) { + if (!generator.Generate(&tree, M4::GLSLGenerator::Target_FragmentShader, SHADER_VERSION, "PS")) { std::cerr << "Failed to transpile HLSL(step3) " << shaderTypeString << " shader to GLSL" << std::endl; #if !DUMP_SHADERS_ON_ERROR std::cerr << "Source: " << std::endl << sourcePreprocessed << std::endl; @@ -1131,7 +1133,7 @@ bool ShaderEngine::linkProgram(GLuint programID) { } -bool ShaderEngine::loadPresetShaders(Pipeline &pipeline) { +bool ShaderEngine::loadPresetShaders(Pipeline &pipeline, const std::string & presetName) { bool ok = true; @@ -1140,6 +1142,8 @@ bool ShaderEngine::loadPresetShaders(Pipeline &pipeline) { blur2_enabled = false; blur3_enabled = false; + m_presetName = presetName; + // compile and link warp and composite shaders from pipeline if (!pipeline.warpShader.programSource.empty()) { programID_presetWarp = loadPresetShader(PresentWarpShader, pipeline.warpShader, pipeline.warpShaderFilename); diff --git a/src/libprojectM/Renderer/ShaderEngine.hpp b/src/libprojectM/Renderer/ShaderEngine.hpp index a244f9a15..09caa5d0e 100644 --- a/src/libprojectM/Renderer/ShaderEngine.hpp +++ b/src/libprojectM/Renderer/ShaderEngine.hpp @@ -38,7 +38,7 @@ public: ShaderEngine(); virtual ~ShaderEngine(); - bool loadPresetShaders(Pipeline &pipeline); + bool loadPresetShaders(Pipeline &pipeline, const std::string &presetName); bool enableWarpShader(Shader &shader, const Pipeline &pipeline, const PipelineContext &pipelineContext, const glm::mat4 & mat_ortho); bool enableCompositeShader(Shader &shader, const Pipeline &pipeline, const PipelineContext &pipelineContext); void RenderBlurTextures(const Pipeline &pipeline, const PipelineContext &pipelineContext); @@ -115,6 +115,8 @@ private: GLuint programID_presetComp, programID_presetWarp; bool presetCompShaderLoaded, presetWarpShaderLoaded; + + std::string m_presetName; }; #endif /* SHADERENGINE_HPP_ */ diff --git a/src/libprojectM/Renderer/hlslparser/src/GLSLGenerator.cpp b/src/libprojectM/Renderer/hlslparser/src/GLSLGenerator.cpp index 0afb03f8c..4e5f94ba1 100755 --- a/src/libprojectM/Renderer/hlslparser/src/GLSLGenerator.cpp +++ b/src/libprojectM/Renderer/hlslparser/src/GLSLGenerator.cpp @@ -114,7 +114,7 @@ GLSLGenerator::GLSLGenerator() : m_tree = NULL; m_entryName = NULL; m_target = Target_VertexShader; - m_version = Version_140; + m_version = Version_330; m_versionLegacy = false; m_inAttribPrefix = NULL; m_outAttribPrefix = NULL; @@ -147,6 +147,8 @@ bool GLSLGenerator::Generate(HLSLTree* tree, Target target, Version version, con m_versionLegacy = (version == Version_110 || version == Version_100_ES); m_options = options; + globalVarsAssignements.clear(); + ChooseUniqueName("matrix_row", m_matrixRowFunction, sizeof(m_matrixRowFunction)); ChooseUniqueName("matrix_ctor", m_matrixCtorFunction, sizeof(m_matrixCtorFunction)); ChooseUniqueName("matrix_mul", m_matrixMulFunction, sizeof(m_matrixMulFunction)); @@ -215,6 +217,10 @@ bool GLSLGenerator::Generate(HLSLTree* tree, Target target, Version version, con { m_writer.WriteLine(0, "#version 150"); } + else if (m_version == Version_330) + { + m_writer.WriteLine(0, "#version 330"); + } else if (m_version == Version_100_ES) { m_writer.WriteLine(0, "#version 100"); @@ -224,6 +230,7 @@ bool GLSLGenerator::Generate(HLSLTree* tree, Target target, Version version, con { m_writer.WriteLine(0, "#version 300 es"); m_writer.WriteLine(0, "precision highp float;"); + m_writer.WriteLine(0, "precision highp sampler3D;"); } else { @@ -846,7 +853,30 @@ void GLSLGenerator::OutputExpression(HLSLExpression* expression, const HLSLType* } m_writer.Write("clamp("); OutputExpression(argument[0]); - m_writer.Write(", 0.0, 1.0)"); + HLSLBaseType baseType = argument[0]->expressionType.baseType; + switch (baseType) { + case HLSLBaseType_Float: + case HLSLBaseType_Float2: + case HLSLBaseType_Float3: + case HLSLBaseType_Float4: + m_writer.Write(", 0.0, 1.0)"); + break; + + case HLSLBaseType_Int: + case HLSLBaseType_Int2: + case HLSLBaseType_Int3: + case HLSLBaseType_Int4: + case HLSLBaseType_Uint: + case HLSLBaseType_Uint2: + case HLSLBaseType_Uint3: + case HLSLBaseType_Uint4: + m_writer.Write(", 0, 1)"); + break; + + default: + Error("saturate unhandled type: %s", GetTypeName(argument[0]->expressionType)); + break; + } handled = true; } else if (String_Equal(functionName, "rsqrt")) @@ -854,7 +884,7 @@ void GLSLGenerator::OutputExpression(HLSLExpression* expression, const HLSLType* HLSLExpression* argument[1]; if (GetFunctionArguments(functionCall, argument, 1) != 1) { - Error("saturate expects 1 argument"); + Error("rsqrt expects 1 argument"); return; } m_writer.Write("inversesqrt("); @@ -1025,13 +1055,20 @@ void GLSLGenerator::OutputStatements(int indent, HLSLStatement* statement, const // GLSL doesn't seem have texture uniforms, so just ignore them. if (declaration->type.baseType != HLSLBaseType_Texture) { + bool skipAssignement = true; + if (indent != 0) + { + skipAssignement = false; + } + m_writer.BeginLine(indent, declaration->fileName, declaration->line); if (indent == 0 && (declaration->type.flags & HLSLTypeFlag_Uniform)) { // At the top level, we need the "uniform" keyword. m_writer.Write("uniform "); + skipAssignement = false; } - OutputDeclaration(declaration); + OutputDeclaration(declaration, skipAssignement); m_writer.EndLine(";"); } } @@ -1146,7 +1183,7 @@ void GLSLGenerator::OutputStatements(int indent, HLSLStatement* statement, const m_writer.Write("for ("); if (forStatement->initialization != NULL) { - OutputDeclaration(forStatement->initialization); + OutputDeclaration(forStatement->initialization, false); } else { @@ -1757,6 +1794,18 @@ void GLSLGenerator::OutputEntryCaller(HLSLFunction* entryFunction) argument = argument->nextArgument; } + + // Initialize global variables + for(HLSLDeclaration *declaration : globalVarsAssignements) + { + m_writer.BeginLine(1, declaration->fileName, declaration->line); + OutputDeclarationBody( declaration->type, GetSafeIdentifierName( declaration->name ) ); + + OutputDeclarationAssignement(declaration); + m_writer.EndLine(";"); + } + + const char* resultName = "result"; // Call the original entry function. @@ -1812,7 +1861,7 @@ void GLSLGenerator::OutputEntryCaller(HLSLFunction* entryFunction) m_writer.WriteLine(0, "}"); } -void GLSLGenerator::OutputDeclaration(HLSLDeclaration* declaration) +void GLSLGenerator::OutputDeclaration(HLSLDeclaration* declaration, const bool skipAssignement) { OutputDeclarationType( declaration->type ); @@ -1826,47 +1875,59 @@ void GLSLGenerator::OutputDeclaration(HLSLDeclaration* declaration) if( declaration->assignment != NULL ) { - m_writer.Write( " = " ); - if( declaration->type.array ) - { - m_writer.Write( "%s[]( ", GetTypeName( declaration->type ) ); - OutputExpressionList( declaration->assignment ); - m_writer.Write( " )" ); - } - else + if (!skipAssignement) { - bool matrixCtorNeeded = false; - if (IsMatrixType(declaration->type.baseType)) - { - matrixCtor ctor = matrixCtorBuilder(declaration->type, declaration->assignment); - if (std::find(matrixCtors.cbegin(), matrixCtors.cend(), ctor) != matrixCtors.cend()) - { - matrixCtorNeeded = true; - } - } - - if (matrixCtorNeeded) - { - // Matrix contructors needs to be adapted since GLSL access a matrix as m[c][r] while HLSL is m[r][c] - matrixCtor ctor = matrixCtorBuilder(declaration->type, declaration->assignment); - m_writer.Write("%s(", matrixCtorsId[ctor].c_str()); - OutputExpressionList(declaration->assignment); - m_writer.Write(")"); - } - else - { - m_writer.Write( "%s( ", GetTypeName( declaration->type ) ); - OutputExpressionList( declaration->assignment ); - m_writer.Write( " )" ); - } - } - } + OutputDeclarationAssignement(declaration); + } + else + { + globalVarsAssignements.push_back(declaration); + } + } lastDecl = declaration; declaration = declaration->nextDeclaration; } } +void GLSLGenerator::OutputDeclarationAssignement(HLSLDeclaration* declaration) +{ + m_writer.Write( " = " ); + if( declaration->type.array ) + { + m_writer.Write( "%s[]( ", GetTypeName( declaration->type ) ); + OutputExpressionList( declaration->assignment ); + m_writer.Write( " )" ); + } + else + { + bool matrixCtorNeeded = false; + if (IsMatrixType(declaration->type.baseType)) + { + matrixCtor ctor = matrixCtorBuilder(declaration->type, declaration->assignment); + if (std::find(matrixCtors.cbegin(), matrixCtors.cend(), ctor) != matrixCtors.cend()) + { + matrixCtorNeeded = true; + } + } + + if (matrixCtorNeeded) + { + // Matrix contructors needs to be adapted since GLSL access a matrix as m[c][r] while HLSL is m[r][c] + matrixCtor ctor = matrixCtorBuilder(declaration->type, declaration->assignment); + m_writer.Write("%s(", matrixCtorsId[ctor].c_str()); + OutputExpressionList(declaration->assignment); + m_writer.Write(")"); + } + else + { + m_writer.Write( "%s( ", GetTypeName( declaration->type ) ); + OutputExpressionList( declaration->assignment ); + m_writer.Write( " )" ); + } + } +} + void GLSLGenerator::OutputDeclaration(const HLSLType& type, const char* name) { OutputDeclarationType( type ); diff --git a/src/libprojectM/Renderer/hlslparser/src/GLSLGenerator.h b/src/libprojectM/Renderer/hlslparser/src/GLSLGenerator.h index 2dc37efae..443288112 100755 --- a/src/libprojectM/Renderer/hlslparser/src/GLSLGenerator.h +++ b/src/libprojectM/Renderer/hlslparser/src/GLSLGenerator.h @@ -31,6 +31,7 @@ public: Version_110, // OpenGL 2.0 Version_140, // OpenGL 3.1 Version_150, // OpenGL 3.2 + Version_330, // OpenGL 3.3 Version_100_ES, // OpenGL ES 2.0 Version_300_ES, // OpenGL ES 3.0 }; @@ -82,10 +83,11 @@ private: void OutputAttribute(const HLSLType& type, const char* semantic, AttributeModifier modifier); void OutputAttributes(HLSLFunction* entryFunction); void OutputEntryCaller(HLSLFunction* entryFunction); - void OutputDeclaration(HLSLDeclaration* declaration); + void OutputDeclaration(HLSLDeclaration* declaration, const bool skipAssignement); void OutputDeclarationType( const HLSLType& type ); void OutputDeclarationBody( const HLSLType& type, const char* name ); void OutputDeclaration(const HLSLType& type, const char* name); + void OutputDeclarationAssignement(HLSLDeclaration* declaration); void OutputCast(const HLSLType& type); void OutputSetOutAttribute(const char* semantic, const char* resultName); @@ -161,6 +163,7 @@ private: std::vector matrixCtors; std::map matrixCtorsId; + std::vector globalVarsAssignements; }; diff --git a/src/libprojectM/Renderer/hlslparser/src/HLSLParser.cpp b/src/libprojectM/Renderer/hlslparser/src/HLSLParser.cpp index 00b185a63..fb0ec6c50 100755 --- a/src/libprojectM/Renderer/hlslparser/src/HLSLParser.cpp +++ b/src/libprojectM/Renderer/hlslparser/src/HLSLParser.cpp @@ -1184,6 +1184,10 @@ static bool GetBinaryOpResultType(HLSLBinaryOp binaryOp, const HLSLType& type1, result.baseType = HLSLBaseType( HLSLBaseType_Bool + numComponents - 1 ); break; } + case HLSLBinaryOp_Mod: + result.baseType = HLSLBaseType_Int; + break; + default: result.baseType = _binaryOpTypeLookup[type1.baseType - HLSLBaseType_FirstNumeric][type2.baseType - HLSLBaseType_FirstNumeric]; break; From 64d62429fb2a8c6687b646f7eba3b6141f378aa2 Mon Sep 17 00:00:00 2001 From: deltaoscarmike <37912794+deltaoscarmike@users.noreply.github.com> Date: Tue, 20 Nov 2018 20:29:09 +0100 Subject: [PATCH 2/4] Assignement -> Assignment --- .../Renderer/hlslparser/src/GLSLGenerator.cpp | 26 +++++++++---------- .../Renderer/hlslparser/src/GLSLGenerator.h | 6 ++--- .../Renderer/hlslparser/src/HLSLTree.cpp | 16 ++++++------ .../Renderer/hlslparser/src/HLSLTree.h | 2 +- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/libprojectM/Renderer/hlslparser/src/GLSLGenerator.cpp b/src/libprojectM/Renderer/hlslparser/src/GLSLGenerator.cpp index 4e5f94ba1..079de8c1e 100755 --- a/src/libprojectM/Renderer/hlslparser/src/GLSLGenerator.cpp +++ b/src/libprojectM/Renderer/hlslparser/src/GLSLGenerator.cpp @@ -147,7 +147,7 @@ bool GLSLGenerator::Generate(HLSLTree* tree, Target target, Version version, con m_versionLegacy = (version == Version_110 || version == Version_100_ES); m_options = options; - globalVarsAssignements.clear(); + globalVarsAssignments.clear(); ChooseUniqueName("matrix_row", m_matrixRowFunction, sizeof(m_matrixRowFunction)); ChooseUniqueName("matrix_ctor", m_matrixCtorFunction, sizeof(m_matrixCtorFunction)); @@ -184,7 +184,7 @@ bool GLSLGenerator::Generate(HLSLTree* tree, Target target, Version version, con m_outAttribPrefix = "rast_"; } - m_tree->ReplaceUniformsAssignements(); + m_tree->ReplaceUniformsAssignments(); HLSLRoot* root = m_tree->GetRoot(); HLSLStatement* statement = root->statement; @@ -1055,10 +1055,10 @@ void GLSLGenerator::OutputStatements(int indent, HLSLStatement* statement, const // GLSL doesn't seem have texture uniforms, so just ignore them. if (declaration->type.baseType != HLSLBaseType_Texture) { - bool skipAssignement = true; + bool skipAssignment = true; if (indent != 0) { - skipAssignement = false; + skipAssignment = false; } m_writer.BeginLine(indent, declaration->fileName, declaration->line); @@ -1066,9 +1066,9 @@ void GLSLGenerator::OutputStatements(int indent, HLSLStatement* statement, const { // At the top level, we need the "uniform" keyword. m_writer.Write("uniform "); - skipAssignement = false; + skipAssignment = false; } - OutputDeclaration(declaration, skipAssignement); + OutputDeclaration(declaration, skipAssignment); m_writer.EndLine(";"); } } @@ -1796,12 +1796,12 @@ void GLSLGenerator::OutputEntryCaller(HLSLFunction* entryFunction) // Initialize global variables - for(HLSLDeclaration *declaration : globalVarsAssignements) + for(HLSLDeclaration *declaration : globalVarsAssignments) { m_writer.BeginLine(1, declaration->fileName, declaration->line); OutputDeclarationBody( declaration->type, GetSafeIdentifierName( declaration->name ) ); - OutputDeclarationAssignement(declaration); + OutputDeclarationAssignment(declaration); m_writer.EndLine(";"); } @@ -1861,7 +1861,7 @@ void GLSLGenerator::OutputEntryCaller(HLSLFunction* entryFunction) m_writer.WriteLine(0, "}"); } -void GLSLGenerator::OutputDeclaration(HLSLDeclaration* declaration, const bool skipAssignement) +void GLSLGenerator::OutputDeclaration(HLSLDeclaration* declaration, const bool skipAssignment) { OutputDeclarationType( declaration->type ); @@ -1875,13 +1875,13 @@ void GLSLGenerator::OutputDeclaration(HLSLDeclaration* declaration, const bool s if( declaration->assignment != NULL ) { - if (!skipAssignement) + if (!skipAssignment) { - OutputDeclarationAssignement(declaration); + OutputDeclarationAssignment(declaration); } else { - globalVarsAssignements.push_back(declaration); + globalVarsAssignments.push_back(declaration); } } @@ -1890,7 +1890,7 @@ void GLSLGenerator::OutputDeclaration(HLSLDeclaration* declaration, const bool s } } -void GLSLGenerator::OutputDeclarationAssignement(HLSLDeclaration* declaration) +void GLSLGenerator::OutputDeclarationAssignment(HLSLDeclaration* declaration) { m_writer.Write( " = " ); if( declaration->type.array ) diff --git a/src/libprojectM/Renderer/hlslparser/src/GLSLGenerator.h b/src/libprojectM/Renderer/hlslparser/src/GLSLGenerator.h index 443288112..098425231 100755 --- a/src/libprojectM/Renderer/hlslparser/src/GLSLGenerator.h +++ b/src/libprojectM/Renderer/hlslparser/src/GLSLGenerator.h @@ -83,11 +83,11 @@ private: void OutputAttribute(const HLSLType& type, const char* semantic, AttributeModifier modifier); void OutputAttributes(HLSLFunction* entryFunction); void OutputEntryCaller(HLSLFunction* entryFunction); - void OutputDeclaration(HLSLDeclaration* declaration, const bool skipAssignement); + void OutputDeclaration(HLSLDeclaration* declaration, const bool skipAssignment); void OutputDeclarationType( const HLSLType& type ); void OutputDeclarationBody( const HLSLType& type, const char* name ); void OutputDeclaration(const HLSLType& type, const char* name); - void OutputDeclarationAssignement(HLSLDeclaration* declaration); + void OutputDeclarationAssignment(HLSLDeclaration* declaration); void OutputCast(const HLSLType& type); void OutputSetOutAttribute(const char* semantic, const char* resultName); @@ -163,7 +163,7 @@ private: std::vector matrixCtors; std::map matrixCtorsId; - std::vector globalVarsAssignements; + std::vector globalVarsAssignments; }; diff --git a/src/libprojectM/Renderer/hlslparser/src/HLSLTree.cpp b/src/libprojectM/Renderer/hlslparser/src/HLSLTree.cpp index 9c8f98f21..0e7d5cb25 100755 --- a/src/libprojectM/Renderer/hlslparser/src/HLSLTree.cpp +++ b/src/libprojectM/Renderer/hlslparser/src/HLSLTree.cpp @@ -610,14 +610,14 @@ int HLSLTree::GetExpressionValue(HLSLExpression * expression, float values[4]) return 0; } -bool HLSLTree::ReplaceUniformsAssignements() +bool HLSLTree::ReplaceUniformsAssignments() { - struct ReplaceUniformsAssignementsVisitor: HLSLTreeVisitor + struct ReplaceUniformsAssignmentsVisitor: HLSLTreeVisitor { HLSLTree * tree; std::map uniforms; std::map uniformsReplaced; - bool withinAssignement; + bool withinAssignment; virtual void VisitDeclaration(HLSLDeclaration * node) { @@ -660,17 +660,17 @@ bool HLSLTree::ReplaceUniformsAssignements() if (IsAssignOp(node->binaryOp)) { - withinAssignement = true; + withinAssignment = true; } VisitExpression(node->expression1); - withinAssignement = false; + withinAssignment = false; } virtual void VisitIdentifierExpression(HLSLIdentifierExpression * node) { - if (withinAssignement) + if (withinAssignment) { // Check if variable is a uniform if (uniforms.find(node->name) != uniforms.end()) @@ -699,9 +699,9 @@ bool HLSLTree::ReplaceUniformsAssignements() } }; - ReplaceUniformsAssignementsVisitor visitor; + ReplaceUniformsAssignmentsVisitor visitor; visitor.tree = this; - visitor.withinAssignement = false; + visitor.withinAssignment = false; visitor.VisitRoot(m_root); return true; diff --git a/src/libprojectM/Renderer/hlslparser/src/HLSLTree.h b/src/libprojectM/Renderer/hlslparser/src/HLSLTree.h index 4400655af..109d471f5 100755 --- a/src/libprojectM/Renderer/hlslparser/src/HLSLTree.h +++ b/src/libprojectM/Renderer/hlslparser/src/HLSLTree.h @@ -993,7 +993,7 @@ public: int GetExpressionValue(HLSLExpression * expression, float values[4]); bool NeedsFunction(const char * name); - bool ReplaceUniformsAssignements(); + bool ReplaceUniformsAssignments(); void EnumerateMatrixCtorsNeeded(std::vector & matrixCtors); private: From 271f1f2f6874c48536803649d61595240109d816 Mon Sep 17 00:00:00 2001 From: deltaoscarmike <37912794+deltaoscarmike@users.noreply.github.com> Date: Tue, 20 Nov 2018 20:34:36 +0100 Subject: [PATCH 3/4] - Matrix assignment: DX to GL adaptation - GLES fix --- src/libprojectM/Renderer/ShaderEngine.cpp | 50 +++++++++++------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/libprojectM/Renderer/ShaderEngine.cpp b/src/libprojectM/Renderer/ShaderEngine.cpp index 459db53b1..620c5bfd0 100644 --- a/src/libprojectM/Renderer/ShaderEngine.cpp +++ b/src/libprojectM/Renderer/ShaderEngine.cpp @@ -325,7 +325,7 @@ std::string blur1_frag( " #define w_div _c3.z\n" "" " // note: if you just take one sample at exactly uv.xy, you get an avg of 4 pixels.\n" - " vec2 uv2 = fragment_texture.xy + srctexsize.zw*vec2(1,1); // + moves blur UP, LEFT by 1-pixel increments\n" + " vec2 uv2 = fragment_texture.xy + srctexsize.zw*vec2(1.0,1.0); // + moves blur UP, LEFT by 1-pixel increments\n" "" " vec3 blur = \n" " ( texture( texture_sampler, uv2 + vec2( d1*srctexsize.z,0) ).xyz\n" @@ -863,30 +863,30 @@ void ShaderEngine::SetupShaderVariables(GLuint program, const Pipeline &pipeline temp_mat[i] = my * temp_mat[i]; } - glUniformMatrix4x3fv(glGetUniformLocation(program, "rot_s1"), 1, GL_FALSE, glm::value_ptr(glm::mat4x3(temp_mat[0]))); - glUniformMatrix4x3fv(glGetUniformLocation(program, "rot_s2"), 1, GL_FALSE, glm::value_ptr(glm::mat4x3(temp_mat[1]))); - glUniformMatrix4x3fv(glGetUniformLocation(program, "rot_s3"), 1, GL_FALSE, glm::value_ptr(glm::mat4x3(temp_mat[2]))); - glUniformMatrix4x3fv(glGetUniformLocation(program, "rot_s4"), 1, GL_FALSE, glm::value_ptr(glm::mat4x3(temp_mat[3]))); - glUniformMatrix4x3fv(glGetUniformLocation(program, "rot_d1"), 1, GL_FALSE, glm::value_ptr(glm::mat4x3(temp_mat[4]))); - glUniformMatrix4x3fv(glGetUniformLocation(program, "rot_d2"), 1, GL_FALSE, glm::value_ptr(glm::mat4x3(temp_mat[5]))); - glUniformMatrix4x3fv(glGetUniformLocation(program, "rot_d3"), 1, GL_FALSE, glm::value_ptr(glm::mat4x3(temp_mat[6]))); - glUniformMatrix4x3fv(glGetUniformLocation(program, "rot_d4"), 1, GL_FALSE, glm::value_ptr(glm::mat4x3(temp_mat[7]))); - glUniformMatrix4x3fv(glGetUniformLocation(program, "rot_f1"), 1, GL_FALSE, glm::value_ptr(glm::mat4x3(temp_mat[8]))); - glUniformMatrix4x3fv(glGetUniformLocation(program, "rot_f2"), 1, GL_FALSE, glm::value_ptr(glm::mat4x3(temp_mat[9]))); - glUniformMatrix4x3fv(glGetUniformLocation(program, "rot_f3"), 1, GL_FALSE, glm::value_ptr(glm::mat4x3(temp_mat[10]))); - glUniformMatrix4x3fv(glGetUniformLocation(program, "rot_f4"), 1, GL_FALSE, glm::value_ptr(glm::mat4x3(temp_mat[11]))); - glUniformMatrix4x3fv(glGetUniformLocation(program, "rot_vf1"), 1, GL_FALSE, glm::value_ptr(glm::mat4x3(temp_mat[12]))); - glUniformMatrix4x3fv(glGetUniformLocation(program, "rot_vf2"), 1, GL_FALSE, glm::value_ptr(glm::mat4x3(temp_mat[13]))); - glUniformMatrix4x3fv(glGetUniformLocation(program, "rot_vf3"), 1, GL_FALSE, glm::value_ptr(glm::mat4x3(temp_mat[14]))); - glUniformMatrix4x3fv(glGetUniformLocation(program, "rot_vf4"), 1, GL_FALSE, glm::value_ptr(glm::mat4x3(temp_mat[15]))); - glUniformMatrix4x3fv(glGetUniformLocation(program, "rot_uf1"), 1, GL_FALSE, glm::value_ptr(glm::mat4x3(temp_mat[16]))); - glUniformMatrix4x3fv(glGetUniformLocation(program, "rot_uf2"), 1, GL_FALSE, glm::value_ptr(glm::mat4x3(temp_mat[17]))); - glUniformMatrix4x3fv(glGetUniformLocation(program, "rot_uf3"), 1, GL_FALSE, glm::value_ptr(glm::mat4x3(temp_mat[18]))); - glUniformMatrix4x3fv(glGetUniformLocation(program, "rot_uf4"), 1, GL_FALSE, glm::value_ptr(glm::mat4x3(temp_mat[19]))); - glUniformMatrix4x3fv(glGetUniformLocation(program, "rot_rand1"), 1, GL_FALSE, glm::value_ptr(glm::mat4x3(temp_mat[20]))); - glUniformMatrix4x3fv(glGetUniformLocation(program, "rot_rand2"), 1, GL_FALSE, glm::value_ptr(glm::mat4x3(temp_mat[21]))); - glUniformMatrix4x3fv(glGetUniformLocation(program, "rot_rand3"), 1, GL_FALSE, glm::value_ptr(glm::mat4x3(temp_mat[22]))); - glUniformMatrix4x3fv(glGetUniformLocation(program, "rot_rand4"), 1, GL_FALSE, glm::value_ptr(glm::mat4x3(temp_mat[23]))); + glUniformMatrix3x4fv(glGetUniformLocation(program, "rot_s1"), 1, GL_FALSE, glm::value_ptr(glm::mat3x4(temp_mat[0]))); + glUniformMatrix3x4fv(glGetUniformLocation(program, "rot_s2"), 1, GL_FALSE, glm::value_ptr(glm::mat3x4(temp_mat[1]))); + glUniformMatrix3x4fv(glGetUniformLocation(program, "rot_s3"), 1, GL_FALSE, glm::value_ptr(glm::mat3x4(temp_mat[2]))); + glUniformMatrix3x4fv(glGetUniformLocation(program, "rot_s4"), 1, GL_FALSE, glm::value_ptr(glm::mat3x4(temp_mat[3]))); + glUniformMatrix3x4fv(glGetUniformLocation(program, "rot_d1"), 1, GL_FALSE, glm::value_ptr(glm::mat3x4(temp_mat[4]))); + glUniformMatrix3x4fv(glGetUniformLocation(program, "rot_d2"), 1, GL_FALSE, glm::value_ptr(glm::mat3x4(temp_mat[5]))); + glUniformMatrix3x4fv(glGetUniformLocation(program, "rot_d3"), 1, GL_FALSE, glm::value_ptr(glm::mat3x4(temp_mat[6]))); + glUniformMatrix3x4fv(glGetUniformLocation(program, "rot_d4"), 1, GL_FALSE, glm::value_ptr(glm::mat3x4(temp_mat[7]))); + glUniformMatrix3x4fv(glGetUniformLocation(program, "rot_f1"), 1, GL_FALSE, glm::value_ptr(glm::mat3x4(temp_mat[8]))); + glUniformMatrix3x4fv(glGetUniformLocation(program, "rot_f2"), 1, GL_FALSE, glm::value_ptr(glm::mat3x4(temp_mat[9]))); + glUniformMatrix3x4fv(glGetUniformLocation(program, "rot_f3"), 1, GL_FALSE, glm::value_ptr(glm::mat3x4(temp_mat[10]))); + glUniformMatrix3x4fv(glGetUniformLocation(program, "rot_f4"), 1, GL_FALSE, glm::value_ptr(glm::mat3x4(temp_mat[11]))); + glUniformMatrix3x4fv(glGetUniformLocation(program, "rot_vf1"), 1, GL_FALSE, glm::value_ptr(glm::mat3x4(temp_mat[12]))); + glUniformMatrix3x4fv(glGetUniformLocation(program, "rot_vf2"), 1, GL_FALSE, glm::value_ptr(glm::mat3x4(temp_mat[13]))); + glUniformMatrix3x4fv(glGetUniformLocation(program, "rot_vf3"), 1, GL_FALSE, glm::value_ptr(glm::mat3x4(temp_mat[14]))); + glUniformMatrix3x4fv(glGetUniformLocation(program, "rot_vf4"), 1, GL_FALSE, glm::value_ptr(glm::mat3x4(temp_mat[15]))); + glUniformMatrix3x4fv(glGetUniformLocation(program, "rot_uf1"), 1, GL_FALSE, glm::value_ptr(glm::mat3x4(temp_mat[16]))); + glUniformMatrix3x4fv(glGetUniformLocation(program, "rot_uf2"), 1, GL_FALSE, glm::value_ptr(glm::mat3x4(temp_mat[17]))); + glUniformMatrix3x4fv(glGetUniformLocation(program, "rot_uf3"), 1, GL_FALSE, glm::value_ptr(glm::mat3x4(temp_mat[18]))); + glUniformMatrix3x4fv(glGetUniformLocation(program, "rot_uf4"), 1, GL_FALSE, glm::value_ptr(glm::mat3x4(temp_mat[19]))); + glUniformMatrix3x4fv(glGetUniformLocation(program, "rot_rand1"), 1, GL_FALSE, glm::value_ptr(glm::mat3x4(temp_mat[20]))); + glUniformMatrix3x4fv(glGetUniformLocation(program, "rot_rand2"), 1, GL_FALSE, glm::value_ptr(glm::mat3x4(temp_mat[21]))); + glUniformMatrix3x4fv(glGetUniformLocation(program, "rot_rand3"), 1, GL_FALSE, glm::value_ptr(glm::mat3x4(temp_mat[22]))); + glUniformMatrix3x4fv(glGetUniformLocation(program, "rot_rand4"), 1, GL_FALSE, glm::value_ptr(glm::mat3x4(temp_mat[23]))); // set program uniform "_q[a-h]" values (_qa.x, _qa.y, _qa.z, _qa.w, _qb.x, _qb.y ... ) alias q[1-32] for (int i=0; i < 32; i+=4) { From d9f65d921165b0de15412b89e656845ef98af0c8 Mon Sep 17 00:00:00 2001 From: deltaoscarmike <37912794+deltaoscarmike@users.noreply.github.com> Date: Wed, 21 Nov 2018 18:39:52 +0100 Subject: [PATCH 4/4] Disable OGL debug for GLES build Memory leak fix --- src/projectM-sdl/projectM_SDL_main.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/projectM-sdl/projectM_SDL_main.cpp b/src/projectM-sdl/projectM_SDL_main.cpp index f56061871..db48ea421 100644 --- a/src/projectM-sdl/projectM_SDL_main.cpp +++ b/src/projectM-sdl/projectM_SDL_main.cpp @@ -8,8 +8,8 @@ #include "pmSDL.hpp" -#define FAKE_AUDIO 0 -#define TEST_ALL_PRESETS 0 +#define FAKE_AUDIO 0 +#define TEST_ALL_PRESETS 0 #if OGL_DEBUG void DebugLog(GLenum source, @@ -146,7 +146,7 @@ int main(int argc, char *argv[]) { } app->init(win, &glCtx); -#if OGL_DEBUG +#if OGL_DEBUG && !USE_GLES glEnable(GL_DEBUG_OUTPUT); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); glDebugMessageCallback(DebugLog, NULL); @@ -172,6 +172,8 @@ int main(int argc, char *argv[]) { fprintf(stdout, "Preset loading errors: %d/%d [%d%%]\n", buildErrors, app->getPlaylistSize(), (buildErrors*100) / app->getPlaylistSize()); } + delete app; + return PROJECTM_SUCCESS; #endif