- [Psy-X] additional shader compilation checks

This commit is contained in:
Ilya Shurumov 2021-01-09 15:01:17 +06:00
parent 05ca0aee3e
commit 4394c66e0d
2 changed files with 47 additions and 17 deletions

View File

@ -668,26 +668,44 @@ GTE_VERTEX_SHADER
GPU_FRAGMENT_SAMPLE_SHADER(16) GPU_FRAGMENT_SAMPLE_SHADER(16)
"#endif\n"; "#endif\n";
void GR_Shader_CheckShaderStatus(GLuint shader) int GR_Shader_CheckShaderStatus(GLuint shader)
{ {
char info[1024]; char info[1024];
GLint result;
glGetShaderiv(shader, GL_COMPILE_STATUS, &result);
if (result)
return 1;
glGetShaderInfoLog(shader, sizeof(info), NULL, info); glGetShaderInfoLog(shader, sizeof(info), NULL, info);
if (info[0] && strlen(info) > 8) if (info[0] && strlen(info) > 8)
{ {
eprinterr("%s\n", info); eprinterr("%s\n", info);
assert(0); assert(0);
} }
return 0;
} }
void GR_Shader_CheckProgramStatus(GLuint program) int GR_Shader_CheckProgramStatus(GLuint program)
{ {
char info[1024]; char info[1024];
GLint result;
glGetShaderiv(program, GL_LINK_STATUS, &result);
if (result)
return 1;
glGetProgramInfoLog(program, sizeof(info), NULL, info); glGetProgramInfoLog(program, sizeof(info), NULL, info);
if (info[0] && strlen(info) > 8) if (info[0] && strlen(info) > 8)
{ {
eprinterr("%s\n", info); eprinterr("%s\n", info);
assert(0); assert(0);
} }
return 0;
} }
ShaderID GR_Shader_Compile(const char* source) ShaderID GR_Shader_Compile(const char* source)
@ -755,19 +773,29 @@ ShaderID GR_Shader_Compile(const char* source)
GLuint program = glCreateProgram(); GLuint program = glCreateProgram();
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER); {
glShaderSource(vertexShader, 3, vs_list, NULL); GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
glCompileShader(vertexShader); glShaderSource(vertexShader, 3, vs_list, NULL);
GR_Shader_CheckShaderStatus(vertexShader); glCompileShader(vertexShader);
glAttachShader(program, vertexShader);
glDeleteShader(vertexShader);
GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); if( GR_Shader_CheckShaderStatus(vertexShader) == 0 )
glShaderSource(fragmentShader, 3, fs_list, NULL); eprinterr("Failed to compile Vertex Shader!\n");
glCompileShader(fragmentShader);
GR_Shader_CheckShaderStatus(fragmentShader); glAttachShader(program, vertexShader);
glAttachShader(program, fragmentShader); glDeleteShader(vertexShader);
glDeleteShader(fragmentShader); }
{
GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 3, fs_list, NULL);
glCompileShader(fragmentShader);
if(GR_Shader_CheckShaderStatus(fragmentShader) == 0)
eprinterr("Failed to compile Fragment Shader!\n");
glAttachShader(program, fragmentShader);
glDeleteShader(fragmentShader);
}
glBindAttribLocation(program, a_position, "a_position"); glBindAttribLocation(program, a_position, "a_position");
glBindAttribLocation(program, a_texcoord, "a_texcoord"); glBindAttribLocation(program, a_texcoord, "a_texcoord");
@ -779,7 +807,8 @@ ShaderID GR_Shader_Compile(const char* source)
#endif #endif
glLinkProgram(program); glLinkProgram(program);
GR_Shader_CheckProgramStatus(program); if(GR_Shader_CheckProgramStatus(program) == 0)
eprinterr("Failed to compile link Shader!\n");
GLint sampler = 0; GLint sampler = 0;
glUseProgram(program); glUseProgram(program);

View File

@ -259,8 +259,9 @@ const char* fmv_shader =
TextureID g_FMVTexture = 0; TextureID g_FMVTexture = 0;
ShaderID g_FMVShader = 0; ShaderID g_FMVShader = 0;
extern void GR_Shader_CheckShaderStatus(GLuint shader); extern int GR_Shader_CheckShaderStatus(GLuint shader);
extern void GR_Shader_CheckProgramStatus(GLuint program); extern int GR_Shader_CheckProgramStatus(GLuint program);
extern ShaderID GR_Shader_Compile(const char* source); extern ShaderID GR_Shader_Compile(const char* source);
extern void GR_SetShader(const ShaderID& shader); extern void GR_SetShader(const ShaderID& shader);