Factorize matrix block uniform assignment
This commit is contained in:
parent
fbe2896460
commit
cc141fc992
@ -479,10 +479,6 @@ namespace UtilShader
|
||||
glEnableVertexAttribArray(attrib_position);
|
||||
glVertexAttribPointer(attrib_position, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), 0);
|
||||
uniform_color = glGetUniformLocation(Program, "color");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
|
||||
}
|
||||
|
||||
void ColoredLine::setUniforms(const irr::video::SColor &col)
|
||||
@ -779,10 +775,6 @@ namespace MeshShader
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_pass1.frag").c_str());
|
||||
AssignUniforms("ModelMatrix", "InverseModelMatrix");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
|
||||
AssignSamplerNames(Program, 0, "tex");
|
||||
}
|
||||
|
||||
@ -793,10 +785,6 @@ namespace MeshShader
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass1.frag").c_str());
|
||||
AssignUniforms("ModelMatrix", "InverseModelMatrix", "TextureMatrix");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
|
||||
AssignSamplerNames(Program, 0, "tex");
|
||||
}
|
||||
|
||||
@ -807,7 +795,6 @@ namespace MeshShader
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass1.frag").c_str());
|
||||
AssignUniforms("ModelMatrix", "InverseModelMatrix", "windDir");
|
||||
|
||||
AssignSamplerNames(Program, 0, "tex");
|
||||
}
|
||||
|
||||
@ -818,10 +805,6 @@ namespace MeshShader
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/normalmap.frag").c_str());
|
||||
AssignUniforms("ModelMatrix", "InverseModelMatrix");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
|
||||
AssignSamplerNames(Program, 1, "normalMap", 0, "DiffuseForAlpha");
|
||||
}
|
||||
|
||||
@ -835,9 +818,6 @@ namespace MeshShader
|
||||
|
||||
AssignUniforms();
|
||||
AssignSamplerNames(Program, 0, "tex");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
InstancedObjectRefPass1Shader::InstancedObjectRefPass1Shader()
|
||||
@ -850,9 +830,6 @@ namespace MeshShader
|
||||
|
||||
AssignUniforms();
|
||||
AssignSamplerNames(Program, 0, "tex");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
InstancedGrassPass1Shader::InstancedGrassPass1Shader()
|
||||
@ -863,11 +840,7 @@ namespace MeshShader
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/instanced_objectref_pass1.frag").c_str());
|
||||
AssignUniforms("windDir");
|
||||
|
||||
AssignSamplerNames(Program, 0, "tex");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
InstancedNormalMapShader::InstancedNormalMapShader()
|
||||
@ -878,10 +851,6 @@ namespace MeshShader
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/instanced_normalmap.frag").c_str());
|
||||
AssignUniforms();
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
|
||||
AssignSamplerNames(Program, 0, "normalMap", 1, "DiffuseForAlpha");
|
||||
}
|
||||
|
||||
@ -893,10 +862,6 @@ namespace MeshShader
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_pass2.frag").c_str());
|
||||
AssignUniforms("ModelMatrix", "TextureMatrix");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
|
||||
AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo");
|
||||
}
|
||||
|
||||
@ -908,12 +873,7 @@ namespace MeshShader
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/instanced_object_pass2.frag").c_str());
|
||||
AssignUniforms();
|
||||
|
||||
AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
|
||||
}
|
||||
|
||||
InstancedObjectRefPass2Shader::InstancedObjectRefPass2Shader()
|
||||
@ -924,11 +884,7 @@ namespace MeshShader
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/instanced_objectref_pass2.frag").c_str());
|
||||
AssignUniforms();
|
||||
|
||||
AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
DetailledObjectPass2Shader::DetailledObjectPass2Shader()
|
||||
@ -938,9 +894,6 @@ namespace MeshShader
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/detailledobject_pass2.frag").c_str());
|
||||
AssignUniforms("ModelMatrix");
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
|
||||
AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo", 4, "Detail");
|
||||
}
|
||||
|
||||
@ -952,11 +905,7 @@ namespace MeshShader
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/instanced_detailledobject_pass2.frag").c_str());
|
||||
AssignUniforms();
|
||||
|
||||
AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo", 4, "Detail");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
ObjectUnlitShader::ObjectUnlitShader()
|
||||
@ -965,10 +914,6 @@ namespace MeshShader
|
||||
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_unlit.frag").c_str());
|
||||
AssignUniforms("ModelMatrix", "TextureMatrix");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
|
||||
AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "tex");
|
||||
}
|
||||
|
||||
@ -979,10 +924,6 @@ namespace MeshShader
|
||||
GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanced_object_pass.vert").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/instanced_object_unlit.frag").c_str());
|
||||
AssignUniforms();
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
|
||||
AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "tex");
|
||||
}
|
||||
|
||||
@ -993,10 +934,6 @@ namespace MeshShader
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass2.frag").c_str());
|
||||
AssignUniforms("ModelMatrix", "TextureMatrix");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
|
||||
AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo");
|
||||
}
|
||||
|
||||
@ -1007,7 +944,6 @@ namespace MeshShader
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/grass_pass2.frag").c_str());
|
||||
AssignUniforms("ModelMatrix", "windDir");
|
||||
|
||||
AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo");
|
||||
}
|
||||
|
||||
@ -1019,11 +955,7 @@ namespace MeshShader
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/instanced_grass_pass2.frag").c_str());
|
||||
AssignUniforms("windDir", "SunDir");
|
||||
|
||||
AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "dtex", 4, "Albedo");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
SphereMapShader::SphereMapShader()
|
||||
@ -1034,10 +966,6 @@ namespace MeshShader
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectpass_spheremap.frag").c_str());
|
||||
AssignUniforms("ModelMatrix", "InverseModelMatrix");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
|
||||
AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "tex");
|
||||
}
|
||||
|
||||
@ -1050,10 +978,6 @@ namespace MeshShader
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/instanced_objectpass_spheremap.frag").c_str());
|
||||
AssignUniforms();
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
|
||||
AssignSamplerNames(Program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "tex");
|
||||
}
|
||||
|
||||
@ -1106,10 +1030,6 @@ namespace MeshShader
|
||||
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/transparent.frag").c_str());
|
||||
AssignUniforms("ModelMatrix", "TextureMatrix");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
|
||||
AssignSamplerNames(Program, 0, "tex");
|
||||
}
|
||||
|
||||
@ -1119,10 +1039,6 @@ namespace MeshShader
|
||||
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/transparentfog.frag").c_str());
|
||||
AssignUniforms("ModelMatrix", "TextureMatrix", "fogmax", "startH", "endH", "start", "end", "col");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
|
||||
AssignSamplerNames(Program, 0, "tex");
|
||||
}
|
||||
|
||||
@ -1132,10 +1048,7 @@ namespace MeshShader
|
||||
GL_VERTEX_SHADER, file_manager->getAsset("shaders/billboard.vert").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/billboard.frag").c_str());
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
AssignUniforms("ModelViewMatrix", "ProjectionMatrix", "Position", "Size");
|
||||
|
||||
AssignSamplerNames(Program, 0, "tex");
|
||||
}
|
||||
|
||||
@ -1145,9 +1058,6 @@ namespace MeshShader
|
||||
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/colorize.frag").c_str());
|
||||
AssignUniforms("ModelMatrix", "col");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
InstancedColorizeShader::InstancedColorizeShader()
|
||||
@ -1157,9 +1067,6 @@ namespace MeshShader
|
||||
GL_VERTEX_SHADER, file_manager->getAsset("shaders/glow_object.vert").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/glow_object.frag").c_str());
|
||||
AssignUniforms();
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
ShadowShader::ShadowShader()
|
||||
@ -1181,8 +1088,6 @@ namespace MeshShader
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/white.frag").c_str());
|
||||
}
|
||||
AssignUniforms("layer", "ModelMatrix");
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
RSMShader::RSMShader()
|
||||
@ -1193,9 +1098,6 @@ namespace MeshShader
|
||||
|
||||
AssignUniforms("RSMMatrix", "ModelMatrix", "TextureMatrix");
|
||||
AssignSamplerNames(Program, 0, "tex");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
InstancedRSMShader::InstancedRSMShader()
|
||||
@ -1207,9 +1109,6 @@ namespace MeshShader
|
||||
|
||||
AssignUniforms("RSMMatrix");
|
||||
AssignSamplerNames(Program, 0, "tex");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
SplattingRSMShader::SplattingRSMShader()
|
||||
@ -1220,9 +1119,6 @@ namespace MeshShader
|
||||
|
||||
AssignUniforms("RSMMatrix", "ModelMatrix");
|
||||
AssignSamplerNames(Program, 0, "tex_layout", 1, "tex_detail0", 2, "tex_detail1", 3, "tex_detail2", 4, "tex_detail3");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
InstancedShadowShader::InstancedShadowShader()
|
||||
@ -1246,8 +1142,6 @@ namespace MeshShader
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/white.frag").c_str());
|
||||
}
|
||||
AssignUniforms("layer");
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
RefShadowShader::RefShadowShader()
|
||||
@ -1269,9 +1163,6 @@ namespace MeshShader
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_unlit.frag").c_str());
|
||||
}
|
||||
AssignUniforms("layer", "ModelMatrix");
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
|
||||
AssignSamplerNames(Program, 0, "tex");
|
||||
}
|
||||
|
||||
@ -1297,8 +1188,6 @@ namespace MeshShader
|
||||
}
|
||||
AssignUniforms("layer");
|
||||
AssignSamplerNames(Program, 0, "tex");
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
GrassShadowShader::GrassShadowShader()
|
||||
@ -1320,9 +1209,6 @@ namespace MeshShader
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_unlit.frag").c_str());
|
||||
}
|
||||
AssignUniforms("layer", "ModelMatrix", "windDir");
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
|
||||
AssignSamplerNames(Program, 0, "tex");
|
||||
}
|
||||
|
||||
@ -1348,10 +1234,7 @@ namespace MeshShader
|
||||
}
|
||||
|
||||
AssignSamplerNames(Program, 0, "tex");
|
||||
|
||||
AssignUniforms("layer", "windDir");
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
DisplaceMaskShader::DisplaceMaskShader()
|
||||
@ -1360,9 +1243,6 @@ namespace MeshShader
|
||||
GL_VERTEX_SHADER, file_manager->getAsset("shaders/displace.vert").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/white.frag").c_str());
|
||||
AssignUniforms("ModelMatrix");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
|
||||
@ -1378,8 +1258,6 @@ namespace MeshShader
|
||||
1, "color_tex",
|
||||
2, "mask_tex",
|
||||
3, "tex");
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
SkyboxShader::SkyboxShader()
|
||||
@ -1390,9 +1268,6 @@ namespace MeshShader
|
||||
AssignUniforms("ModelMatrix");
|
||||
AssignSamplerNames(Program, 0, "tex");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
|
||||
glGenVertexArrays(1, &cubevao);
|
||||
glBindVertexArray(cubevao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, SharedObject::cubevbo);
|
||||
@ -1409,9 +1284,6 @@ namespace MeshShader
|
||||
GL_GEOMETRY_SHADER, file_manager->getAsset("shaders/normal_visualizer.geom").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/coloredquad.frag").c_str());
|
||||
AssignUniforms("ModelMatrix", "InverseModelMatrix", "color");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
GLuint ViewFrustrumShader::Program;
|
||||
@ -1427,9 +1299,6 @@ namespace MeshShader
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/coloredquad.frag").c_str());
|
||||
attrib_position = glGetAttribLocation(Program, "Position");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
|
||||
uniform_color = glGetUniformLocation(Program, "color");
|
||||
uniform_idx = glGetUniformLocation(Program, "idx");
|
||||
|
||||
@ -1602,9 +1471,6 @@ namespace FullScreenShader
|
||||
|
||||
AssignUniforms();
|
||||
AssignSamplerNames(Program, 0, "tex", 1, "dtex");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
SunLightShader::SunLightShader()
|
||||
@ -1618,9 +1484,6 @@ namespace FullScreenShader
|
||||
|
||||
AssignSamplerNames(Program, 0, "ntex", 1, "dtex");
|
||||
AssignUniforms("direction", "col");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
DiffuseEnvMapShader::DiffuseEnvMapShader()
|
||||
@ -1645,9 +1508,6 @@ namespace FullScreenShader
|
||||
// Use 8 to circumvent a catalyst bug when binding sampler
|
||||
AssignSamplerNames(Program, 0, "ntex", 1, "dtex", 8, "shadowtex");
|
||||
AssignUniforms("direction", "col");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
RadianceHintsConstructionShader::RadianceHintsConstructionShader()
|
||||
@ -1696,8 +1556,6 @@ namespace FullScreenShader
|
||||
TU_SHG = 1;
|
||||
TU_SHB = 2;
|
||||
AssignTextureUnit(Program, TexUnit(TU_SHR, "SHR"), TexUnit(TU_SHG, "SHG"), TexUnit(TU_SHB, "SHB"));
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
GlobalIlluminationReconstructionShader::GlobalIlluminationReconstructionShader()
|
||||
@ -1709,10 +1567,7 @@ namespace FullScreenShader
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/gi.frag").c_str());
|
||||
|
||||
AssignUniforms("RHMatrix", "InvRHMatrix", "extents");
|
||||
|
||||
AssignSamplerNames(Program, 0, "ntex", 1, "dtex", 2, "SHR", 3, "SHG", 4, "SHB");
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
Gaussian17TapHShader::Gaussian17TapHShader()
|
||||
@ -1721,7 +1576,6 @@ namespace FullScreenShader
|
||||
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/bilateralH.frag").c_str());
|
||||
AssignUniforms("pixel");
|
||||
|
||||
AssignSamplerNames(Program, 0, "tex", 1, "depth");
|
||||
}
|
||||
|
||||
@ -1854,9 +1708,6 @@ namespace FullScreenShader
|
||||
|
||||
AssignSamplerNames(Program, 0, "dtex");
|
||||
AssignUniforms("radius", "k", "sigma");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
FogShader::FogShader()
|
||||
@ -1868,9 +1719,6 @@ namespace FullScreenShader
|
||||
|
||||
AssignUniforms("fogmax", "startH", "endH", "start", "end", "col");
|
||||
AssignSamplerNames(Program, 0, "tex");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
MotionBlurShader::MotionBlurShader()
|
||||
@ -1880,7 +1728,6 @@ namespace FullScreenShader
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/motion_blur.frag").c_str());
|
||||
AssignUniforms("previous_viewproj", "center", "boost_amount", "mask_radius");
|
||||
|
||||
AssignSamplerNames(Program, 0, "color_buffer", 1, "dtex");
|
||||
}
|
||||
|
||||
|
@ -19,11 +19,9 @@
|
||||
|
||||
#include <IShaderConstantSetCallBack.h>
|
||||
#include <IMeshSceneNode.h>
|
||||
#include <vector>
|
||||
#include "config/user_config.hpp"
|
||||
#include "utils/singleton.hpp"
|
||||
|
||||
#include "gl_headers.hpp"
|
||||
#include "shaders_util.hpp"
|
||||
|
||||
using namespace irr;
|
||||
class ParticleSystemProxy;
|
||||
@ -52,427 +50,6 @@ public:
|
||||
};
|
||||
}
|
||||
|
||||
bool needsUBO();
|
||||
|
||||
unsigned getGLSLVersion();
|
||||
|
||||
struct UniformHelper
|
||||
{
|
||||
template<unsigned N = 0>
|
||||
static void setUniformsHelper(const std::vector<GLuint> &uniforms)
|
||||
{
|
||||
}
|
||||
|
||||
template<unsigned N = 0, typename... Args>
|
||||
static void setUniformsHelper(const std::vector<GLuint> &uniforms, const core::matrix4 &mat, Args... arg)
|
||||
{
|
||||
glUniformMatrix4fv(uniforms[N], 1, GL_FALSE, mat.pointer());
|
||||
setUniformsHelper<N + 1>(uniforms, arg...);
|
||||
}
|
||||
|
||||
template<unsigned N = 0, typename... Args>
|
||||
static void setUniformsHelper(const std::vector<GLuint> &uniforms, const video::SColorf &col, Args... arg)
|
||||
{
|
||||
glUniform3f(uniforms[N], col.r, col.g, col.b);
|
||||
setUniformsHelper<N + 1>(uniforms, arg...);
|
||||
}
|
||||
|
||||
template<unsigned N = 0, typename... Args>
|
||||
static void setUniformsHelper(const std::vector<GLuint> &uniforms, const video::SColor &col, Args... arg)
|
||||
{
|
||||
glUniform4i(uniforms[N], col.getRed(), col.getGreen(), col.getBlue(), col.getAlpha());
|
||||
setUniformsHelper<N + 1>(uniforms, arg...);
|
||||
}
|
||||
|
||||
template<unsigned N = 0, typename... Args>
|
||||
static void setUniformsHelper(const std::vector<GLuint> &uniforms, const core::vector3df &v, Args... arg)
|
||||
{
|
||||
glUniform3f(uniforms[N], v.X, v.Y, v.Z);
|
||||
setUniformsHelper<N + 1>(uniforms, arg...);
|
||||
}
|
||||
|
||||
|
||||
template<unsigned N = 0, typename... Args>
|
||||
static void setUniformsHelper(const std::vector<GLuint> &uniforms, const core::vector2df &v, Args... arg)
|
||||
{
|
||||
glUniform2f(uniforms[N], v.X, v.Y);
|
||||
setUniformsHelper<N + 1>(uniforms, arg...);
|
||||
}
|
||||
|
||||
template<unsigned N = 0, typename... Args>
|
||||
static void setUniformsHelper(const std::vector<GLuint> &uniforms, const core::dimension2df &v, Args... arg)
|
||||
{
|
||||
glUniform2f(uniforms[N], v.Width, v.Height);
|
||||
setUniformsHelper<N + 1>(uniforms, arg...);
|
||||
}
|
||||
|
||||
template<unsigned N = 0, typename... Args>
|
||||
static void setUniformsHelper(const std::vector<GLuint> &uniforms, float f, Args... arg)
|
||||
{
|
||||
glUniform1f(uniforms[N], f);
|
||||
setUniformsHelper<N + 1>(uniforms, arg...);
|
||||
}
|
||||
|
||||
template<unsigned N = 0, typename... Args>
|
||||
static void setUniformsHelper(const std::vector<GLuint> &uniforms, int f, Args... arg)
|
||||
{
|
||||
glUniform1i(uniforms[N], f);
|
||||
setUniformsHelper<N + 1>(uniforms, arg...);
|
||||
}
|
||||
|
||||
template<unsigned N = 0, typename... Args>
|
||||
static void setUniformsHelper(const std::vector<GLuint> &uniforms, const std::vector<float> &v, Args... arg)
|
||||
{
|
||||
glUniform1fv(uniforms[N], v.size(), v.data());
|
||||
setUniformsHelper<N + 1>(uniforms, arg...);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
void bypassUBO(GLuint Program);
|
||||
|
||||
extern std::vector<void(*)()> CleanTable;
|
||||
|
||||
template<typename T, typename... Args>
|
||||
class ShaderHelperSingleton : public Singleton<T>
|
||||
{
|
||||
protected:
|
||||
std::vector<GLuint> uniforms;
|
||||
|
||||
void AssignUniforms_impl()
|
||||
{
|
||||
}
|
||||
|
||||
template<typename... U>
|
||||
void AssignUniforms_impl(const char* name, U... rest)
|
||||
{
|
||||
uniforms.push_back(glGetUniformLocation(Program, name));
|
||||
AssignUniforms_impl(rest...);
|
||||
}
|
||||
|
||||
template<typename... U>
|
||||
void AssignUniforms(U... rest)
|
||||
{
|
||||
static_assert(sizeof...(rest) == sizeof...(Args), "Count of Uniform's name mismatch");
|
||||
AssignUniforms_impl(rest...);
|
||||
}
|
||||
|
||||
public:
|
||||
GLuint Program;
|
||||
|
||||
ShaderHelperSingleton()
|
||||
{
|
||||
CleanTable.push_back(this->kill);
|
||||
}
|
||||
|
||||
~ShaderHelperSingleton()
|
||||
{
|
||||
glDeleteProgram(Program);
|
||||
}
|
||||
|
||||
void setUniforms(const Args & ... args) const
|
||||
{
|
||||
if (needsUBO())
|
||||
bypassUBO(Program);
|
||||
UniformHelper::setUniformsHelper(uniforms, args...);
|
||||
}
|
||||
};
|
||||
|
||||
enum SamplerType {
|
||||
Trilinear_Anisotropic_Filtered,
|
||||
Semi_trilinear,
|
||||
Bilinear_Filtered,
|
||||
Bilinear_Clamped_Filtered,
|
||||
Nearest_Filtered,
|
||||
Shadow_Sampler,
|
||||
Volume_Linear_Filtered,
|
||||
Trilinear_cubemap,
|
||||
};
|
||||
|
||||
void setTextureSampler(GLenum, GLuint, GLuint, GLuint);
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct CreateSamplers;
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct BindTexture;
|
||||
|
||||
template<>
|
||||
struct CreateSamplers<>
|
||||
{
|
||||
static void exec(std::vector<unsigned> &, std::vector<GLenum> &e)
|
||||
{}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct BindTexture<>
|
||||
{
|
||||
static void exec(const std::vector<unsigned> &TU, const std::vector<unsigned> &TexId, unsigned N)
|
||||
{}
|
||||
};
|
||||
|
||||
GLuint createNearestSampler();
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct CreateSamplers<Nearest_Filtered, tp...>
|
||||
{
|
||||
static void exec(std::vector<unsigned> &v, std::vector<GLenum> &e)
|
||||
{
|
||||
v.push_back(createNearestSampler());
|
||||
e.push_back(GL_TEXTURE_2D);
|
||||
CreateSamplers<tp...>::exec(v, e);
|
||||
}
|
||||
};
|
||||
|
||||
void BindTextureNearest(unsigned TU, unsigned tid);
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct BindTexture<Nearest_Filtered, tp...>
|
||||
{
|
||||
static void exec(const std::vector<unsigned> &TU, const std::vector<unsigned> &TexId, unsigned N)
|
||||
{
|
||||
BindTextureNearest(TU[N], TexId[N]);
|
||||
BindTexture<tp...>::exec(TU, TexId, N + 1);
|
||||
}
|
||||
};
|
||||
|
||||
GLuint createBilinearSampler();
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct CreateSamplers<Bilinear_Filtered, tp...>
|
||||
{
|
||||
static void exec(std::vector<unsigned> &v, std::vector<GLenum> &e)
|
||||
{
|
||||
v.push_back(createBilinearSampler());
|
||||
e.push_back(GL_TEXTURE_2D);
|
||||
CreateSamplers<tp...>::exec(v, e);
|
||||
}
|
||||
};
|
||||
|
||||
void BindTextureBilinear(unsigned TU, unsigned tex);
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct BindTexture<Bilinear_Filtered, tp...>
|
||||
{
|
||||
static void exec(const std::vector<unsigned> &TU, const std::vector<unsigned> &TexId, unsigned N)
|
||||
{
|
||||
BindTextureBilinear(TU[N], TexId[N]);
|
||||
BindTexture<tp...>::exec(TU, TexId, N + 1);
|
||||
}
|
||||
};
|
||||
|
||||
GLuint createBilinearClampedSampler();
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct CreateSamplers<Bilinear_Clamped_Filtered, tp...>
|
||||
{
|
||||
static void exec(std::vector<unsigned> &v, std::vector<GLenum> &e)
|
||||
{
|
||||
v.push_back(createBilinearClampedSampler());
|
||||
e.push_back(GL_TEXTURE_2D);
|
||||
CreateSamplers<tp...>::exec(v, e);
|
||||
}
|
||||
};
|
||||
|
||||
void BindTextureBilinearClamped(unsigned TU, unsigned tex);
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct BindTexture<Bilinear_Clamped_Filtered, tp...>
|
||||
{
|
||||
static void exec(const std::vector<unsigned> &TU, const std::vector<unsigned> &TexId, unsigned N)
|
||||
{
|
||||
BindTextureBilinearClamped(TU[N], TexId[N]);
|
||||
BindTexture<tp...>::exec(TU, TexId, N + 1);
|
||||
}
|
||||
};
|
||||
|
||||
GLuint createSemiTrilinearSampler();
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct CreateSamplers<Semi_trilinear, tp...>
|
||||
{
|
||||
static void exec(std::vector<unsigned> &v, std::vector<GLenum> &e)
|
||||
{
|
||||
v.push_back(createSemiTrilinearSampler());
|
||||
e.push_back(GL_TEXTURE_2D);
|
||||
CreateSamplers<tp...>::exec(v, e);
|
||||
}
|
||||
};
|
||||
|
||||
void BindTextureSemiTrilinear(unsigned TU, unsigned tex);
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct BindTexture<Semi_trilinear, tp...>
|
||||
{
|
||||
static void exec(const std::vector<unsigned> &TU, const std::vector<unsigned> &TexId, unsigned N)
|
||||
{
|
||||
BindTextureSemiTrilinear(TU[N], TexId[N]);
|
||||
BindTexture<tp...>::exec(TU, TexId, N + 1);
|
||||
}
|
||||
};
|
||||
|
||||
GLuint createTrilinearSampler();
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct CreateSamplers<Trilinear_Anisotropic_Filtered, tp...>
|
||||
{
|
||||
static void exec(std::vector<unsigned> &v, std::vector<GLenum> &e)
|
||||
{
|
||||
v.push_back(createTrilinearSampler());
|
||||
e.push_back(GL_TEXTURE_2D);
|
||||
CreateSamplers<tp...>::exec(v, e);
|
||||
}
|
||||
};
|
||||
|
||||
void BindTextureTrilinearAnisotropic(unsigned TU, unsigned tex);
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct CreateSamplers<Trilinear_cubemap, tp...>
|
||||
{
|
||||
static void exec(std::vector<unsigned> &v, std::vector<GLenum> &e)
|
||||
{
|
||||
v.push_back(createTrilinearSampler());
|
||||
e.push_back(GL_TEXTURE_CUBE_MAP);
|
||||
CreateSamplers<tp...>::exec(v, e);
|
||||
}
|
||||
};
|
||||
|
||||
void BindCubemapTrilinear(unsigned TU, unsigned tex);
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct BindTexture<Trilinear_cubemap, tp...>
|
||||
{
|
||||
static void exec(const std::vector<unsigned> &TU, const std::vector<unsigned> &TexId, unsigned N)
|
||||
{
|
||||
BindCubemapTrilinear(TU[N], TexId[N]);
|
||||
BindTexture<tp...>::exec(TU, TexId, N + 1);
|
||||
}
|
||||
};
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct BindTexture<Trilinear_Anisotropic_Filtered, tp...>
|
||||
{
|
||||
static void exec(const std::vector<unsigned> &TU, const std::vector<unsigned> &TexId, unsigned N)
|
||||
{
|
||||
BindTextureTrilinearAnisotropic(TU[N], TexId[N]);
|
||||
BindTexture<tp...>::exec(TU, TexId, N + 1);
|
||||
}
|
||||
};
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct CreateSamplers<Volume_Linear_Filtered, tp...>
|
||||
{
|
||||
static void exec(std::vector<unsigned> &v, std::vector<GLenum> &e)
|
||||
{
|
||||
v.push_back(createBilinearSampler());
|
||||
e.push_back(GL_TEXTURE_3D);
|
||||
CreateSamplers<tp...>::exec(v, e);
|
||||
}
|
||||
};
|
||||
|
||||
void BindTextureVolume(unsigned TU, unsigned tex);
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct BindTexture<Volume_Linear_Filtered, tp...>
|
||||
{
|
||||
static void exec(const std::vector<unsigned> &TU, const std::vector<unsigned> &TexId, unsigned N)
|
||||
{
|
||||
BindTextureVolume(TU[N], TexId[N]);
|
||||
BindTexture<tp...>::exec(TU, TexId, N + 1);
|
||||
}
|
||||
};
|
||||
|
||||
GLuint createShadowSampler();
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct CreateSamplers<Shadow_Sampler, tp...>
|
||||
{
|
||||
static void exec(std::vector<unsigned> &v, std::vector<GLenum> &e)
|
||||
{
|
||||
v.push_back(createShadowSampler());
|
||||
e.push_back(GL_TEXTURE_2D_ARRAY);
|
||||
CreateSamplers<tp...>::exec(v, e);
|
||||
}
|
||||
};
|
||||
|
||||
void BindTextureShadow(unsigned TU, unsigned tex);
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct BindTexture<Shadow_Sampler, tp...>
|
||||
{
|
||||
static void exec(const std::vector<unsigned> &TU, const std::vector<unsigned> &TexId, unsigned N)
|
||||
{
|
||||
BindTextureShadow(TU[N], TexId[N]);
|
||||
BindTexture<tp...>::exec(TU, TexId, N + 1);
|
||||
}
|
||||
};
|
||||
|
||||
template<SamplerType...tp>
|
||||
class TextureRead
|
||||
{
|
||||
private:
|
||||
template<unsigned N, typename...Args>
|
||||
void AssignTextureNames_impl(GLuint)
|
||||
{
|
||||
static_assert(N == sizeof...(tp), "Wrong number of texture name");
|
||||
}
|
||||
|
||||
template<unsigned N, typename...Args>
|
||||
void AssignTextureNames_impl(GLuint Program, GLuint TexUnit, const char *name, Args...args)
|
||||
{
|
||||
GLuint location = glGetUniformLocation(Program, name);
|
||||
TextureLocation.push_back(location);
|
||||
glUniform1i(location, TexUnit);
|
||||
TextureUnits.push_back(TexUnit);
|
||||
AssignTextureNames_impl<N + 1>(Program, args...);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::vector<GLuint> TextureUnits;
|
||||
std::vector<GLenum> TextureType;
|
||||
std::vector<GLenum> TextureLocation;
|
||||
template<typename...Args>
|
||||
void AssignSamplerNames(GLuint Program, Args...args)
|
||||
{
|
||||
CreateSamplers<tp...>::exec(SamplersId, TextureType);
|
||||
|
||||
glUseProgram(Program);
|
||||
AssignTextureNames_impl<0>(Program, args...);
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
public:
|
||||
std::vector<GLuint> SamplersId;
|
||||
void SetTextureUnits(const std::vector<GLuint> &args)
|
||||
{
|
||||
assert(args.size() == sizeof...(tp) && "Too much texture unit provided");
|
||||
if (getGLSLVersion() >= 330)
|
||||
{
|
||||
for (unsigned i = 0; i < args.size(); i++)
|
||||
{
|
||||
setTextureSampler(TextureType[i], TextureUnits[i], args[i], SamplersId[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
BindTexture<tp...>::exec(TextureUnits, args, 0);
|
||||
}
|
||||
|
||||
~TextureRead()
|
||||
{
|
||||
for (unsigned i = 0; i < SamplersId.size(); i++)
|
||||
glDeleteSamplers(1, &SamplersId[i]);
|
||||
}
|
||||
|
||||
void SetTextureHandles(const std::vector<uint64_t> &args)
|
||||
{
|
||||
assert(args.size() == TextureLocation.size() && "Wrong Handle count");
|
||||
for (unsigned i = 0; i < args.size(); i++)
|
||||
{
|
||||
if (args[i])
|
||||
glUniformHandleui64ARB(TextureLocation[i], args[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
namespace MeshShader
|
||||
{
|
||||
|
435
src/graphics/shaders_util.hpp
Normal file
435
src/graphics/shaders_util.hpp
Normal file
@ -0,0 +1,435 @@
|
||||
#ifndef SHADERS_UTIL_HPP
|
||||
#define SHADERS_UTIL_HPP
|
||||
|
||||
#include "utils/singleton.hpp"
|
||||
#include <vector>
|
||||
#include <matrix4.h>
|
||||
#include <SColor.h>
|
||||
#include <vector3d.h>
|
||||
#include "gl_headers.hpp"
|
||||
|
||||
bool needsUBO();
|
||||
|
||||
unsigned getGLSLVersion();
|
||||
|
||||
struct UniformHelper
|
||||
{
|
||||
template<unsigned N = 0>
|
||||
static void setUniformsHelper(const std::vector<GLuint> &uniforms)
|
||||
{
|
||||
}
|
||||
|
||||
template<unsigned N = 0, typename... Args>
|
||||
static void setUniformsHelper(const std::vector<GLuint> &uniforms, const irr::core::matrix4 &mat, Args... arg)
|
||||
{
|
||||
glUniformMatrix4fv(uniforms[N], 1, GL_FALSE, mat.pointer());
|
||||
setUniformsHelper<N + 1>(uniforms, arg...);
|
||||
}
|
||||
|
||||
template<unsigned N = 0, typename... Args>
|
||||
static void setUniformsHelper(const std::vector<GLuint> &uniforms, const irr::video::SColorf &col, Args... arg)
|
||||
{
|
||||
glUniform3f(uniforms[N], col.r, col.g, col.b);
|
||||
setUniformsHelper<N + 1>(uniforms, arg...);
|
||||
}
|
||||
|
||||
template<unsigned N = 0, typename... Args>
|
||||
static void setUniformsHelper(const std::vector<GLuint> &uniforms, const irr::video::SColor &col, Args... arg)
|
||||
{
|
||||
glUniform4i(uniforms[N], col.getRed(), col.getGreen(), col.getBlue(), col.getAlpha());
|
||||
setUniformsHelper<N + 1>(uniforms, arg...);
|
||||
}
|
||||
|
||||
template<unsigned N = 0, typename... Args>
|
||||
static void setUniformsHelper(const std::vector<GLuint> &uniforms, const irr::core::vector3df &v, Args... arg)
|
||||
{
|
||||
glUniform3f(uniforms[N], v.X, v.Y, v.Z);
|
||||
setUniformsHelper<N + 1>(uniforms, arg...);
|
||||
}
|
||||
|
||||
|
||||
template<unsigned N = 0, typename... Args>
|
||||
static void setUniformsHelper(const std::vector<GLuint> &uniforms, const irr::core::vector2df &v, Args... arg)
|
||||
{
|
||||
glUniform2f(uniforms[N], v.X, v.Y);
|
||||
setUniformsHelper<N + 1>(uniforms, arg...);
|
||||
}
|
||||
|
||||
template<unsigned N = 0, typename... Args>
|
||||
static void setUniformsHelper(const std::vector<GLuint> &uniforms, const irr::core::dimension2df &v, Args... arg)
|
||||
{
|
||||
glUniform2f(uniforms[N], v.Width, v.Height);
|
||||
setUniformsHelper<N + 1>(uniforms, arg...);
|
||||
}
|
||||
|
||||
template<unsigned N = 0, typename... Args>
|
||||
static void setUniformsHelper(const std::vector<GLuint> &uniforms, float f, Args... arg)
|
||||
{
|
||||
glUniform1f(uniforms[N], f);
|
||||
setUniformsHelper<N + 1>(uniforms, arg...);
|
||||
}
|
||||
|
||||
template<unsigned N = 0, typename... Args>
|
||||
static void setUniformsHelper(const std::vector<GLuint> &uniforms, int f, Args... arg)
|
||||
{
|
||||
glUniform1i(uniforms[N], f);
|
||||
setUniformsHelper<N + 1>(uniforms, arg...);
|
||||
}
|
||||
|
||||
template<unsigned N = 0, typename... Args>
|
||||
static void setUniformsHelper(const std::vector<GLuint> &uniforms, const std::vector<float> &v, Args... arg)
|
||||
{
|
||||
glUniform1fv(uniforms[N], v.size(), v.data());
|
||||
setUniformsHelper<N + 1>(uniforms, arg...);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
void bypassUBO(GLuint Program);
|
||||
|
||||
extern std::vector<void(*)()> CleanTable;
|
||||
|
||||
template<typename T, typename... Args>
|
||||
class ShaderHelperSingleton : public Singleton<T>
|
||||
{
|
||||
protected:
|
||||
std::vector<GLuint> uniforms;
|
||||
|
||||
void AssignUniforms_impl()
|
||||
{
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
if (uniform_ViewProjectionMatrixesUBO != GL_INVALID_INDEX)
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
template<typename... U>
|
||||
void AssignUniforms_impl(const char* name, U... rest)
|
||||
{
|
||||
uniforms.push_back(glGetUniformLocation(Program, name));
|
||||
AssignUniforms_impl(rest...);
|
||||
}
|
||||
|
||||
template<typename... U>
|
||||
void AssignUniforms(U... rest)
|
||||
{
|
||||
static_assert(sizeof...(rest) == sizeof...(Args), "Count of Uniform's name mismatch");
|
||||
AssignUniforms_impl(rest...);
|
||||
}
|
||||
|
||||
public:
|
||||
GLuint Program;
|
||||
|
||||
ShaderHelperSingleton()
|
||||
{
|
||||
CleanTable.push_back(this->kill);
|
||||
}
|
||||
|
||||
~ShaderHelperSingleton()
|
||||
{
|
||||
glDeleteProgram(Program);
|
||||
}
|
||||
|
||||
void setUniforms(const Args & ... args) const
|
||||
{
|
||||
if (needsUBO())
|
||||
bypassUBO(Program);
|
||||
UniformHelper::setUniformsHelper(uniforms, args...);
|
||||
}
|
||||
};
|
||||
|
||||
enum SamplerType {
|
||||
Trilinear_Anisotropic_Filtered,
|
||||
Semi_trilinear,
|
||||
Bilinear_Filtered,
|
||||
Bilinear_Clamped_Filtered,
|
||||
Nearest_Filtered,
|
||||
Shadow_Sampler,
|
||||
Volume_Linear_Filtered,
|
||||
Trilinear_cubemap,
|
||||
};
|
||||
|
||||
void setTextureSampler(GLenum, GLuint, GLuint, GLuint);
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct CreateSamplers;
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct BindTexture;
|
||||
|
||||
template<>
|
||||
struct CreateSamplers<>
|
||||
{
|
||||
static void exec(std::vector<unsigned> &, std::vector<GLenum> &e)
|
||||
{}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct BindTexture<>
|
||||
{
|
||||
static void exec(const std::vector<unsigned> &TU, const std::vector<unsigned> &TexId, unsigned N)
|
||||
{}
|
||||
};
|
||||
|
||||
GLuint createNearestSampler();
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct CreateSamplers<Nearest_Filtered, tp...>
|
||||
{
|
||||
static void exec(std::vector<unsigned> &v, std::vector<GLenum> &e)
|
||||
{
|
||||
v.push_back(createNearestSampler());
|
||||
e.push_back(GL_TEXTURE_2D);
|
||||
CreateSamplers<tp...>::exec(v, e);
|
||||
}
|
||||
};
|
||||
|
||||
void BindTextureNearest(unsigned TU, unsigned tid);
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct BindTexture<Nearest_Filtered, tp...>
|
||||
{
|
||||
static void exec(const std::vector<unsigned> &TU, const std::vector<unsigned> &TexId, unsigned N)
|
||||
{
|
||||
BindTextureNearest(TU[N], TexId[N]);
|
||||
BindTexture<tp...>::exec(TU, TexId, N + 1);
|
||||
}
|
||||
};
|
||||
|
||||
GLuint createBilinearSampler();
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct CreateSamplers<Bilinear_Filtered, tp...>
|
||||
{
|
||||
static void exec(std::vector<unsigned> &v, std::vector<GLenum> &e)
|
||||
{
|
||||
v.push_back(createBilinearSampler());
|
||||
e.push_back(GL_TEXTURE_2D);
|
||||
CreateSamplers<tp...>::exec(v, e);
|
||||
}
|
||||
};
|
||||
|
||||
void BindTextureBilinear(unsigned TU, unsigned tex);
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct BindTexture<Bilinear_Filtered, tp...>
|
||||
{
|
||||
static void exec(const std::vector<unsigned> &TU, const std::vector<unsigned> &TexId, unsigned N)
|
||||
{
|
||||
BindTextureBilinear(TU[N], TexId[N]);
|
||||
BindTexture<tp...>::exec(TU, TexId, N + 1);
|
||||
}
|
||||
};
|
||||
|
||||
GLuint createBilinearClampedSampler();
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct CreateSamplers<Bilinear_Clamped_Filtered, tp...>
|
||||
{
|
||||
static void exec(std::vector<unsigned> &v, std::vector<GLenum> &e)
|
||||
{
|
||||
v.push_back(createBilinearClampedSampler());
|
||||
e.push_back(GL_TEXTURE_2D);
|
||||
CreateSamplers<tp...>::exec(v, e);
|
||||
}
|
||||
};
|
||||
|
||||
void BindTextureBilinearClamped(unsigned TU, unsigned tex);
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct BindTexture<Bilinear_Clamped_Filtered, tp...>
|
||||
{
|
||||
static void exec(const std::vector<unsigned> &TU, const std::vector<unsigned> &TexId, unsigned N)
|
||||
{
|
||||
BindTextureBilinearClamped(TU[N], TexId[N]);
|
||||
BindTexture<tp...>::exec(TU, TexId, N + 1);
|
||||
}
|
||||
};
|
||||
|
||||
GLuint createSemiTrilinearSampler();
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct CreateSamplers<Semi_trilinear, tp...>
|
||||
{
|
||||
static void exec(std::vector<unsigned> &v, std::vector<GLenum> &e)
|
||||
{
|
||||
v.push_back(createSemiTrilinearSampler());
|
||||
e.push_back(GL_TEXTURE_2D);
|
||||
CreateSamplers<tp...>::exec(v, e);
|
||||
}
|
||||
};
|
||||
|
||||
void BindTextureSemiTrilinear(unsigned TU, unsigned tex);
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct BindTexture<Semi_trilinear, tp...>
|
||||
{
|
||||
static void exec(const std::vector<unsigned> &TU, const std::vector<unsigned> &TexId, unsigned N)
|
||||
{
|
||||
BindTextureSemiTrilinear(TU[N], TexId[N]);
|
||||
BindTexture<tp...>::exec(TU, TexId, N + 1);
|
||||
}
|
||||
};
|
||||
|
||||
GLuint createTrilinearSampler();
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct CreateSamplers<Trilinear_Anisotropic_Filtered, tp...>
|
||||
{
|
||||
static void exec(std::vector<unsigned> &v, std::vector<GLenum> &e)
|
||||
{
|
||||
v.push_back(createTrilinearSampler());
|
||||
e.push_back(GL_TEXTURE_2D);
|
||||
CreateSamplers<tp...>::exec(v, e);
|
||||
}
|
||||
};
|
||||
|
||||
void BindTextureTrilinearAnisotropic(unsigned TU, unsigned tex);
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct CreateSamplers<Trilinear_cubemap, tp...>
|
||||
{
|
||||
static void exec(std::vector<unsigned> &v, std::vector<GLenum> &e)
|
||||
{
|
||||
v.push_back(createTrilinearSampler());
|
||||
e.push_back(GL_TEXTURE_CUBE_MAP);
|
||||
CreateSamplers<tp...>::exec(v, e);
|
||||
}
|
||||
};
|
||||
|
||||
void BindCubemapTrilinear(unsigned TU, unsigned tex);
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct BindTexture<Trilinear_cubemap, tp...>
|
||||
{
|
||||
static void exec(const std::vector<unsigned> &TU, const std::vector<unsigned> &TexId, unsigned N)
|
||||
{
|
||||
BindCubemapTrilinear(TU[N], TexId[N]);
|
||||
BindTexture<tp...>::exec(TU, TexId, N + 1);
|
||||
}
|
||||
};
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct BindTexture<Trilinear_Anisotropic_Filtered, tp...>
|
||||
{
|
||||
static void exec(const std::vector<unsigned> &TU, const std::vector<unsigned> &TexId, unsigned N)
|
||||
{
|
||||
BindTextureTrilinearAnisotropic(TU[N], TexId[N]);
|
||||
BindTexture<tp...>::exec(TU, TexId, N + 1);
|
||||
}
|
||||
};
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct CreateSamplers<Volume_Linear_Filtered, tp...>
|
||||
{
|
||||
static void exec(std::vector<unsigned> &v, std::vector<GLenum> &e)
|
||||
{
|
||||
v.push_back(createBilinearSampler());
|
||||
e.push_back(GL_TEXTURE_3D);
|
||||
CreateSamplers<tp...>::exec(v, e);
|
||||
}
|
||||
};
|
||||
|
||||
void BindTextureVolume(unsigned TU, unsigned tex);
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct BindTexture<Volume_Linear_Filtered, tp...>
|
||||
{
|
||||
static void exec(const std::vector<unsigned> &TU, const std::vector<unsigned> &TexId, unsigned N)
|
||||
{
|
||||
BindTextureVolume(TU[N], TexId[N]);
|
||||
BindTexture<tp...>::exec(TU, TexId, N + 1);
|
||||
}
|
||||
};
|
||||
|
||||
GLuint createShadowSampler();
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct CreateSamplers<Shadow_Sampler, tp...>
|
||||
{
|
||||
static void exec(std::vector<unsigned> &v, std::vector<GLenum> &e)
|
||||
{
|
||||
v.push_back(createShadowSampler());
|
||||
e.push_back(GL_TEXTURE_2D_ARRAY);
|
||||
CreateSamplers<tp...>::exec(v, e);
|
||||
}
|
||||
};
|
||||
|
||||
void BindTextureShadow(unsigned TU, unsigned tex);
|
||||
|
||||
template<SamplerType...tp>
|
||||
struct BindTexture<Shadow_Sampler, tp...>
|
||||
{
|
||||
static void exec(const std::vector<unsigned> &TU, const std::vector<unsigned> &TexId, unsigned N)
|
||||
{
|
||||
BindTextureShadow(TU[N], TexId[N]);
|
||||
BindTexture<tp...>::exec(TU, TexId, N + 1);
|
||||
}
|
||||
};
|
||||
|
||||
template<SamplerType...tp>
|
||||
class TextureRead
|
||||
{
|
||||
private:
|
||||
template<unsigned N, typename...Args>
|
||||
void AssignTextureNames_impl(GLuint)
|
||||
{
|
||||
static_assert(N == sizeof...(tp), "Wrong number of texture name");
|
||||
}
|
||||
|
||||
template<unsigned N, typename...Args>
|
||||
void AssignTextureNames_impl(GLuint Program, GLuint TexUnit, const char *name, Args...args)
|
||||
{
|
||||
GLuint location = glGetUniformLocation(Program, name);
|
||||
TextureLocation.push_back(location);
|
||||
glUniform1i(location, TexUnit);
|
||||
TextureUnits.push_back(TexUnit);
|
||||
AssignTextureNames_impl<N + 1>(Program, args...);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::vector<GLuint> TextureUnits;
|
||||
std::vector<GLenum> TextureType;
|
||||
std::vector<GLenum> TextureLocation;
|
||||
template<typename...Args>
|
||||
void AssignSamplerNames(GLuint Program, Args...args)
|
||||
{
|
||||
CreateSamplers<tp...>::exec(SamplersId, TextureType);
|
||||
|
||||
glUseProgram(Program);
|
||||
AssignTextureNames_impl<0>(Program, args...);
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
public:
|
||||
std::vector<GLuint> SamplersId;
|
||||
void SetTextureUnits(const std::vector<GLuint> &args)
|
||||
{
|
||||
assert(args.size() == sizeof...(tp) && "Too much texture unit provided");
|
||||
if (getGLSLVersion() >= 330)
|
||||
{
|
||||
for (unsigned i = 0; i < args.size(); i++)
|
||||
{
|
||||
setTextureSampler(TextureType[i], TextureUnits[i], args[i], SamplersId[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
BindTexture<tp...>::exec(TextureUnits, args, 0);
|
||||
}
|
||||
|
||||
~TextureRead()
|
||||
{
|
||||
for (unsigned i = 0; i < SamplersId.size(); i++)
|
||||
glDeleteSamplers(1, &SamplersId[i]);
|
||||
}
|
||||
|
||||
void SetTextureHandles(const std::vector<uint64_t> &args)
|
||||
{
|
||||
assert(args.size() == TextureLocation.size() && "Wrong Handle count");
|
||||
for (unsigned i = 0; i < args.size(); i++)
|
||||
{
|
||||
if (args[i])
|
||||
glUniformHandleui64ARB(TextureLocation[i], args[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user