mirror of
https://github.com/projectM-visualizer/projectm.git
synced 2026-02-06 21:15:37 +00:00
Merge pull request #123 from projectM-visualizer/gles_fixes
DX to openGL/openGLES transpilation fixes
This commit is contained in:
@ -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);
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -323,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"
|
||||
@ -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;
|
||||
@ -861,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) {
|
||||
@ -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);
|
||||
|
||||
@ -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_ */
|
||||
|
||||
@ -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;
|
||||
|
||||
globalVarsAssignments.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));
|
||||
@ -182,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;
|
||||
@ -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 skipAssignment = true;
|
||||
if (indent != 0)
|
||||
{
|
||||
skipAssignment = 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 ");
|
||||
skipAssignment = false;
|
||||
}
|
||||
OutputDeclaration(declaration);
|
||||
OutputDeclaration(declaration, skipAssignment);
|
||||
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 : globalVarsAssignments)
|
||||
{
|
||||
m_writer.BeginLine(1, declaration->fileName, declaration->line);
|
||||
OutputDeclarationBody( declaration->type, GetSafeIdentifierName( declaration->name ) );
|
||||
|
||||
OutputDeclarationAssignment(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 skipAssignment)
|
||||
{
|
||||
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 (!skipAssignment)
|
||||
{
|
||||
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( " )" );
|
||||
}
|
||||
}
|
||||
}
|
||||
OutputDeclarationAssignment(declaration);
|
||||
}
|
||||
else
|
||||
{
|
||||
globalVarsAssignments.push_back(declaration);
|
||||
}
|
||||
}
|
||||
|
||||
lastDecl = declaration;
|
||||
declaration = declaration->nextDeclaration;
|
||||
}
|
||||
}
|
||||
|
||||
void GLSLGenerator::OutputDeclarationAssignment(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 );
|
||||
|
||||
@ -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 skipAssignment);
|
||||
void OutputDeclarationType( const HLSLType& type );
|
||||
void OutputDeclarationBody( const HLSLType& type, const char* name );
|
||||
void OutputDeclaration(const HLSLType& type, const char* name);
|
||||
void OutputDeclarationAssignment(HLSLDeclaration* declaration);
|
||||
void OutputCast(const HLSLType& type);
|
||||
|
||||
void OutputSetOutAttribute(const char* semantic, const char* resultName);
|
||||
@ -161,6 +163,7 @@ private:
|
||||
|
||||
std::vector<matrixCtor> matrixCtors;
|
||||
std::map<matrixCtor,std::string> matrixCtorsId;
|
||||
std::vector<HLSLDeclaration*> globalVarsAssignments;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -1186,6 +1186,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;
|
||||
|
||||
@ -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<std::string, HLSLDeclaration *> uniforms;
|
||||
std::map<std::string, std::string> 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;
|
||||
|
||||
@ -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<matrixCtor> & matrixCtors);
|
||||
|
||||
private:
|
||||
|
||||
@ -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,
|
||||
@ -136,7 +136,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);
|
||||
@ -162,6 +162,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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user