diff --git a/gfx/gl.c b/gfx/gl.c
index 0da8603efc..01212a2294 100644
--- a/gfx/gl.c
+++ b/gfx/gl.c
@@ -49,6 +49,8 @@
#include "shader_glsl.h"
#endif
+#include "gl_common.h"
+
static const GLfloat vertexes[] = {
0, 0, 0,
0, 1, 0,
diff --git a/gfx/gl_common.h b/gfx/gl_common.h
new file mode 100644
index 0000000000..ac315ea10c
--- /dev/null
+++ b/gfx/gl_common.h
@@ -0,0 +1,59 @@
+/* SSNES - A Super Ninteno Entertainment System (SNES) Emulator frontend for libsnes.
+ * Copyright (C) 2010 - Hans-Kristian Arntzen
+ *
+ * Some code herein may be based on code found in BSNES.
+ *
+ * SSNES is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Found-
+ * ation, either version 3 of the License, or (at your option) any later version.
+ *
+ * SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with SSNES.
+ * If not, see .
+ */
+
+#ifndef __GL_COMMON_H
+#define __GL_COMMON_H
+
+#include "general.h"
+
+static inline bool gl_check_error(void)
+{
+ int error = glGetError();
+ switch (error)
+ {
+ case GL_INVALID_ENUM:
+ SSNES_ERR("GL: Invalid enum.\n");
+ break;
+ case GL_INVALID_VALUE:
+ SSNES_ERR("GL: Invalid value.\n");
+ break;
+ case GL_INVALID_OPERATION:
+ SSNES_ERR("GL: Invalid operation.\n");
+ break;
+ case GL_STACK_OVERFLOW:
+ SSNES_ERR("GL: Stack overflow. (wtf)\n");
+ break;
+ case GL_STACK_UNDERFLOW:
+ SSNES_ERR("GL: Stack underflow. (:v)\n");
+ break;
+ case GL_OUT_OF_MEMORY:
+ SSNES_ERR("GL: Out of memory. Harhar.\n");
+ break;
+ case GL_TABLE_TOO_LARGE:
+ SSNES_ERR("GL: Table too large. Big tables scare you! :(\n");
+ break;
+ case GL_NO_ERROR:
+ return true;
+ break;
+ default:
+ SSNES_ERR("Non specified error :v\n");
+ }
+
+ return false;
+}
+
+#endif
diff --git a/gfx/shader_glsl.c b/gfx/shader_glsl.c
index a9e93a47e6..45510a0ff8 100644
--- a/gfx/shader_glsl.c
+++ b/gfx/shader_glsl.c
@@ -34,6 +34,8 @@
#define GL_GLEXT_PROTOTYPES
#include
+#include "gl_common.h"
+
static PFNGLCREATEPROGRAMPROC pglCreateProgram = NULL;
static PFNGLUSEPROGRAMPROC pglUseProgram = NULL;
static PFNGLCREATESHADERPROC pglCreateShader = NULL;
@@ -49,6 +51,8 @@ static PFNGLUNIFORM2FVPROC pglUniform2fv = NULL;
static PFNGLUNIFORM4FVPROC pglUniform4fv = NULL;
static PFNGLGETSHADERIVPROC pglGetShaderiv = NULL;
static PFNGLGETSHADERINFOLOGPROC pglGetShaderInfoLog = NULL;
+static PFNGLGETPROGRAMIVPROC pglGetProgramiv = NULL;
+static PFNGLGETPROGRAMINFOLOGPROC pglGetProgramInfoLog = NULL;
static bool glsl_enable = false;
static GLuint gl_program;
@@ -154,6 +158,20 @@ static void print_shader_log(GLuint obj)
SSNES_LOG("Shader log: %s\n", info_log);
}
+static void print_linker_log(GLuint obj)
+{
+ int info_len = 0;
+ int max_len;
+
+ pglGetProgramiv(obj, GL_INFO_LOG_LENGTH, &max_len);
+
+ char info_log[max_len];
+ pglGetProgramInfoLog(obj, max_len, &info_len, info_log);
+
+ if (info_len > 0)
+ SSNES_LOG("Linker log: %s\n", info_log);
+}
+
bool gl_glsl_init(const char *path)
{
// Load shader functions.
@@ -172,13 +190,15 @@ bool gl_glsl_init(const char *path)
pglUniform4fv = SDL_GL_GetProcAddress("glUniform4fv");
pglGetShaderiv = SDL_GL_GetProcAddress("glGetShaderiv");
pglGetShaderInfoLog = SDL_GL_GetProcAddress("glGetShaderInfoLog");
+ pglGetProgramiv = SDL_GL_GetProcAddress("glGetProgramiv");
+ pglGetProgramInfoLog = SDL_GL_GetProcAddress("glGetProgramInfoLog");
SSNES_LOG("Checking GLSL shader support ...\n");
bool shader_support = pglCreateProgram && pglUseProgram && pglCreateShader
&& pglDeleteShader && pglShaderSource && pglCompileShader && pglAttachShader
&& pglDetachShader && pglLinkProgram && pglGetUniformLocation
&& pglUniform1i && pglUniform2fv && pglUniform4fv
- && pglGetShaderiv && pglGetShaderInfoLog;
+ && pglGetShaderiv && pglGetShaderInfoLog && pglGetProgramiv && pglGetProgramInfoLog;
if (!shader_support)
{
@@ -218,8 +238,12 @@ bool gl_glsl_init(const char *path)
{
pglLinkProgram(gl_program);
pglUseProgram(gl_program);
+ print_linker_log(gl_program);
}
+ if (!gl_check_error())
+ return false;
+
glsl_enable = true;
return true;
}