suyu/src/video_core/renderer_opengl/gl_shader_util.cpp

55 lines
1.6 KiB
C++
Raw Normal View History

// Copyright 2014 Citra Emulator Project
2014-12-17 06:38:14 +01:00
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
2015-09-11 13:20:02 +02:00
#include <vector>
#include <glad/glad.h>
#include "common/assert.h"
2015-09-11 13:20:02 +02:00
#include "common/logging/log.h"
#include "video_core/renderer_opengl/gl_shader_util.h"
namespace OpenGL::GLShader {
namespace {
constexpr const char* GetStageDebugName(GLenum type) {
2018-04-07 05:54:44 +02:00
switch (type) {
case GL_VERTEX_SHADER:
return "vertex";
2018-04-07 05:54:44 +02:00
case GL_GEOMETRY_SHADER:
return "geometry";
2018-04-07 05:54:44 +02:00
case GL_FRAGMENT_SHADER:
return "fragment";
case GL_COMPUTE_SHADER:
return "compute";
2018-04-07 05:54:44 +02:00
default:
UNREACHABLE();
}
}
} // Anonymous namespace
GLuint LoadShader(const char* source, GLenum type) {
const char* debug_type = GetStageDebugName(type);
const GLuint shader_id = glCreateShader(type);
2018-04-07 05:54:44 +02:00
glShaderSource(shader_id, 1, &source, nullptr);
2018-07-02 18:13:26 +02:00
LOG_DEBUG(Render_OpenGL, "Compiling {} shader...", debug_type);
2018-04-07 05:54:44 +02:00
glCompileShader(shader_id);
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);
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-07-02 18:13:26 +02:00
LOG_DEBUG(Render_OpenGL, "{}", shader_error);
} else {
2018-07-02 18:13:26 +02:00
LOG_ERROR(Render_OpenGL, "Error compiling {} shader:\n{}", debug_type, shader_error);
}
}
2018-04-07 05:54:44 +02:00
return shader_id;
}
} // namespace OpenGL::GLShader