2014-08-21 09:27:53 +02:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 06:38:14 +01:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-08-21 09:27:53 +02:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2015-09-11 13:20:02 +02:00
|
|
|
#include <vector>
|
2016-04-30 17:34:51 +02:00
|
|
|
#include <glad/glad.h>
|
2016-12-05 02:10:12 +01:00
|
|
|
#include "common/assert.h"
|
2015-09-11 13:20:02 +02:00
|
|
|
#include "common/logging/log.h"
|
2016-09-21 08:52:38 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_shader_util.h"
|
2014-08-21 09:27:53 +02:00
|
|
|
|
2015-10-06 04:33:47 +02:00
|
|
|
namespace GLShader {
|
2014-08-21 09:27:53 +02:00
|
|
|
|
2018-04-07 05:54:44 +02:00
|
|
|
GLuint LoadShader(const char* source, GLenum type) {
|
|
|
|
const char* debug_type;
|
|
|
|
switch (type) {
|
|
|
|
case GL_VERTEX_SHADER:
|
|
|
|
debug_type = "vertex";
|
|
|
|
break;
|
|
|
|
case GL_GEOMETRY_SHADER:
|
|
|
|
debug_type = "geometry";
|
|
|
|
break;
|
|
|
|
case GL_FRAGMENT_SHADER:
|
|
|
|
debug_type = "fragment";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
GLuint shader_id = glCreateShader(type);
|
|
|
|
glShaderSource(shader_id, 1, &source, nullptr);
|
|
|
|
NGLOG_DEBUG(Render_OpenGL, "Compiling {} shader...", debug_type);
|
|
|
|
glCompileShader(shader_id);
|
2014-08-21 09:27:53 +02:00
|
|
|
|
|
|
|
GLint result = GL_FALSE;
|
2018-04-07 05:54:44 +02:00
|
|
|
GLint info_log_length;
|
|
|
|
glGetShaderiv(shader_id, GL_COMPILE_STATUS, &result);
|
|
|
|
glGetShaderiv(shader_id, GL_INFO_LOG_LENGTH, &info_log_length);
|
2014-08-21 09:27:53 +02:00
|
|
|
|
|
|
|
if (info_log_length > 1) {
|
2018-04-07 05:54:44 +02:00
|
|
|
std::string shader_error(info_log_length, ' ');
|
|
|
|
glGetShaderInfoLog(shader_id, info_log_length, nullptr, &shader_error[0]);
|
2016-12-04 12:44:29 +01:00
|
|
|
if (result == GL_TRUE) {
|
2018-04-07 05:54:44 +02:00
|
|
|
NGLOG_DEBUG(Render_OpenGL, "{}", shader_error);
|
2014-12-06 02:53:49 +01:00
|
|
|
} else {
|
2018-04-07 05:54:44 +02:00
|
|
|
NGLOG_ERROR(Render_OpenGL, "Error compiling {} shader:\n{}", debug_type, shader_error);
|
2014-12-06 02:53:49 +01:00
|
|
|
}
|
2014-08-21 09:27:53 +02:00
|
|
|
}
|
2018-04-07 05:54:44 +02:00
|
|
|
return shader_id;
|
2014-08-21 09:27:53 +02:00
|
|
|
}
|
|
|
|
|
2015-10-06 04:33:47 +02:00
|
|
|
} // namespace GLShader
|