summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_opengl/gl_shader_util.h
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2018-04-07 05:54:44 +0200
committerbunnei <bunneidev@gmail.com>2018-04-14 05:48:21 +0200
commit4f2b2d0bc5e56a5f1e05a2d1cae52d8890fa3ce9 (patch)
treeb74c3770fcd689a378db1093c60ae82543841093 /src/video_core/renderer_opengl/gl_shader_util.h
parentgl_resource_manager: Grab latest upstream. (diff)
downloadyuzu-4f2b2d0bc5e56a5f1e05a2d1cae52d8890fa3ce9.tar
yuzu-4f2b2d0bc5e56a5f1e05a2d1cae52d8890fa3ce9.tar.gz
yuzu-4f2b2d0bc5e56a5f1e05a2d1cae52d8890fa3ce9.tar.bz2
yuzu-4f2b2d0bc5e56a5f1e05a2d1cae52d8890fa3ce9.tar.lz
yuzu-4f2b2d0bc5e56a5f1e05a2d1cae52d8890fa3ce9.tar.xz
yuzu-4f2b2d0bc5e56a5f1e05a2d1cae52d8890fa3ce9.tar.zst
yuzu-4f2b2d0bc5e56a5f1e05a2d1cae52d8890fa3ce9.zip
Diffstat (limited to 'src/video_core/renderer_opengl/gl_shader_util.h')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_util.h54
1 files changed, 47 insertions, 7 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_util.h b/src/video_core/renderer_opengl/gl_shader_util.h
index fc7b5e080..5a0008703 100644
--- a/src/video_core/renderer_opengl/gl_shader_util.h
+++ b/src/video_core/renderer_opengl/gl_shader_util.h
@@ -10,14 +10,54 @@
namespace GLShader {
/**
+ * Utility function to create and compile an OpenGL GLSL shader
+ * @param source String of the GLSL shader program
+ * @param type Type of the shader (GL_VERTEX_SHADER, GL_GEOMETRY_SHADER or GL_FRAGMENT_SHADER)
+ */
+GLuint LoadShader(const char* source, GLenum type);
+
+/**
* Utility function to create and compile an OpenGL GLSL shader program (vertex + fragment shader)
- * @param vertex_shader String of the GLSL vertex shader program
- * @param geometry_shader String of the GLSL geometry shader program
- * @param fragment_shader String of the GLSL fragment shader program
- * @returns Handle of the newly created OpenGL shader object
+ * @param separable_program whether to create a separable program
+ * @param shaders ID of shaders to attach to the program
+ * @returns Handle of the newly created OpenGL program object
*/
-GLuint LoadProgram(const char* vertex_shader, const char* geometry_shader,
- const char* fragment_shader, const std::vector<const char*>& feedback_vars = {},
- bool separable_program = false);
+template <typename... T>
+GLuint LoadProgram(bool separable_program, T... shaders) {
+ // Link the program
+ NGLOG_DEBUG(Render_OpenGL, "Linking program...");
+
+ GLuint program_id = glCreateProgram();
+
+ ((shaders == 0 ? (void)0 : glAttachShader(program_id, shaders)), ...);
+
+ if (separable_program) {
+ glProgramParameteri(program_id, GL_PROGRAM_SEPARABLE, GL_TRUE);
+ }
+
+ glLinkProgram(program_id);
+
+ // Check the program
+ GLint result = GL_FALSE;
+ GLint info_log_length;
+ glGetProgramiv(program_id, GL_LINK_STATUS, &result);
+ glGetProgramiv(program_id, GL_INFO_LOG_LENGTH, &info_log_length);
+
+ if (info_log_length > 1) {
+ std::string program_error(info_log_length, ' ');
+ glGetProgramInfoLog(program_id, info_log_length, nullptr, &program_error[0]);
+ if (result == GL_TRUE) {
+ NGLOG_DEBUG(Render_OpenGL, "{}", program_error);
+ } else {
+ NGLOG_ERROR(Render_OpenGL, "Error linking shader:\n{}", program_error);
+ }
+ }
+
+ ASSERT_MSG(result == GL_TRUE, "Shader not linked");
+
+ ((shaders == 0 ? (void)0 : glDetachShader(program_id, shaders)), ...);
+
+ return program_id;
+}
} // namespace GLShader