mirror of
https://github.com/libretro/RetroArch
synced 2025-03-30 07:20:36 +00:00
some common error routine, and more stringent error checking.
This commit is contained in:
parent
d30ce0e867
commit
7b5969cb55
2
gfx/gl.c
2
gfx/gl.c
@ -49,6 +49,8 @@
|
|||||||
#include "shader_glsl.h"
|
#include "shader_glsl.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "gl_common.h"
|
||||||
|
|
||||||
static const GLfloat vertexes[] = {
|
static const GLfloat vertexes[] = {
|
||||||
0, 0, 0,
|
0, 0, 0,
|
||||||
0, 1, 0,
|
0, 1, 0,
|
||||||
|
59
gfx/gl_common.h
Normal file
59
gfx/gl_common.h
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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
|
@ -34,6 +34,8 @@
|
|||||||
#define GL_GLEXT_PROTOTYPES
|
#define GL_GLEXT_PROTOTYPES
|
||||||
#include <GL/glext.h>
|
#include <GL/glext.h>
|
||||||
|
|
||||||
|
#include "gl_common.h"
|
||||||
|
|
||||||
static PFNGLCREATEPROGRAMPROC pglCreateProgram = NULL;
|
static PFNGLCREATEPROGRAMPROC pglCreateProgram = NULL;
|
||||||
static PFNGLUSEPROGRAMPROC pglUseProgram = NULL;
|
static PFNGLUSEPROGRAMPROC pglUseProgram = NULL;
|
||||||
static PFNGLCREATESHADERPROC pglCreateShader = NULL;
|
static PFNGLCREATESHADERPROC pglCreateShader = NULL;
|
||||||
@ -49,6 +51,8 @@ static PFNGLUNIFORM2FVPROC pglUniform2fv = NULL;
|
|||||||
static PFNGLUNIFORM4FVPROC pglUniform4fv = NULL;
|
static PFNGLUNIFORM4FVPROC pglUniform4fv = NULL;
|
||||||
static PFNGLGETSHADERIVPROC pglGetShaderiv = NULL;
|
static PFNGLGETSHADERIVPROC pglGetShaderiv = NULL;
|
||||||
static PFNGLGETSHADERINFOLOGPROC pglGetShaderInfoLog = NULL;
|
static PFNGLGETSHADERINFOLOGPROC pglGetShaderInfoLog = NULL;
|
||||||
|
static PFNGLGETPROGRAMIVPROC pglGetProgramiv = NULL;
|
||||||
|
static PFNGLGETPROGRAMINFOLOGPROC pglGetProgramInfoLog = NULL;
|
||||||
|
|
||||||
static bool glsl_enable = false;
|
static bool glsl_enable = false;
|
||||||
static GLuint gl_program;
|
static GLuint gl_program;
|
||||||
@ -154,6 +158,20 @@ static void print_shader_log(GLuint obj)
|
|||||||
SSNES_LOG("Shader log: %s\n", info_log);
|
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)
|
bool gl_glsl_init(const char *path)
|
||||||
{
|
{
|
||||||
// Load shader functions.
|
// Load shader functions.
|
||||||
@ -172,13 +190,15 @@ bool gl_glsl_init(const char *path)
|
|||||||
pglUniform4fv = SDL_GL_GetProcAddress("glUniform4fv");
|
pglUniform4fv = SDL_GL_GetProcAddress("glUniform4fv");
|
||||||
pglGetShaderiv = SDL_GL_GetProcAddress("glGetShaderiv");
|
pglGetShaderiv = SDL_GL_GetProcAddress("glGetShaderiv");
|
||||||
pglGetShaderInfoLog = SDL_GL_GetProcAddress("glGetShaderInfoLog");
|
pglGetShaderInfoLog = SDL_GL_GetProcAddress("glGetShaderInfoLog");
|
||||||
|
pglGetProgramiv = SDL_GL_GetProcAddress("glGetProgramiv");
|
||||||
|
pglGetProgramInfoLog = SDL_GL_GetProcAddress("glGetProgramInfoLog");
|
||||||
|
|
||||||
SSNES_LOG("Checking GLSL shader support ...\n");
|
SSNES_LOG("Checking GLSL shader support ...\n");
|
||||||
bool shader_support = pglCreateProgram && pglUseProgram && pglCreateShader
|
bool shader_support = pglCreateProgram && pglUseProgram && pglCreateShader
|
||||||
&& pglDeleteShader && pglShaderSource && pglCompileShader && pglAttachShader
|
&& pglDeleteShader && pglShaderSource && pglCompileShader && pglAttachShader
|
||||||
&& pglDetachShader && pglLinkProgram && pglGetUniformLocation
|
&& pglDetachShader && pglLinkProgram && pglGetUniformLocation
|
||||||
&& pglUniform1i && pglUniform2fv && pglUniform4fv
|
&& pglUniform1i && pglUniform2fv && pglUniform4fv
|
||||||
&& pglGetShaderiv && pglGetShaderInfoLog;
|
&& pglGetShaderiv && pglGetShaderInfoLog && pglGetProgramiv && pglGetProgramInfoLog;
|
||||||
|
|
||||||
if (!shader_support)
|
if (!shader_support)
|
||||||
{
|
{
|
||||||
@ -218,8 +238,12 @@ bool gl_glsl_init(const char *path)
|
|||||||
{
|
{
|
||||||
pglLinkProgram(gl_program);
|
pglLinkProgram(gl_program);
|
||||||
pglUseProgram(gl_program);
|
pglUseProgram(gl_program);
|
||||||
|
print_linker_log(gl_program);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!gl_check_error())
|
||||||
|
return false;
|
||||||
|
|
||||||
glsl_enable = true;
|
glsl_enable = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user