TA的每日心情 | 开心 2019-11-11 10:36 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
GLSL教程
译:FreeSouth
调试手段
Shader调试是非常困难的,没有像printf这种函数,而且可能永远都不会有。你也可以使用一些工具来设计shader,那也是可行的。所幸的是现实中也有一些函数可以来判断是否编译和链接成功。
可以查看编译状态的函数,OpenGL2.0语法:
________________________________________
void glGetShaderiv(GLuint object, GLenum type, int *param);
参数:
object - the handler to the object. Either a shader or a program
type - GL_COMPILE_STATUS.
param - the return value, GL_TRUE if OK, GL_FALSE otherwise.
________________________________________
链接状态的函数:
________________________________________
void glGetProgramiv(GLuint object, GLenum type, int *param);
参数:
object - the handler to the object. Either a shader or a program
type - GL_LINK_STATUS.
param - the return value, GL_TRUE if OK, GL_FALSE otherwise.
________________________________________
ARB中使用下面的函数来查看编译和链接状态,区别在参数:
________________________________________
oid glGetObjectParameterivARB(GLhandleARB object, GLenum type, int *param);
参数:
object - the handler to the object. Either a shader or a program
type - GL_OBJECT_LINK_STATUS_ARB or GL_OBJECT_COMPILE_STATUS_ARB.
param - the return value, 1 for OK, 0 for problems.
________________________________________
关于第二个参数type,有很多操作,但是这里不一一例举,可以到3Dlabs网站上查看详情。
当错误发生时,可以使用InfoLog来查看更多信息。这个Log存放的一些在编译和链接阶段错误和告警信息。甚至可以捕捉到shader在运行时一具体的硬件的信息,比如硬件不支持什么什么了等等。不幸的是对于InfoLog没有什么统一的规则,不同的硬件与驱动产生的InfoLog也会不同。
可以使用下面的函数来得到shader和program的InfoLog,OpenGL2.0:
________________________________________
void glGetShaderInfoLog(GLuint object, int maxLen, int *len, char *log);
void glGetProgramInfoLog(GLuint object, int maxLen, int *len, char *log);
参数:
object - the handler to the object. Either a shader or a program
maxLen - The maximum number of chars to retrieve from the InfoLog.
len - returns the actual length of the retrieved InfoLog.
log - The log itself.
________________________________________
ARB一个函数就搞定了:
________________________________________
void glGetInfoLogARB(GLhandleARB object, int maxLen, int *len, char *log);
参数:
object - the handler to the object. Either a shader or a program
maxLen - The maximum number of chars to retrieve from the InfoLog.
len - returns the actual length of the retrieved InfoLog.
log - The log itself.
________________________________________
GLSL在这点上显得有点小强,你可以利用下面的函数来得到你收到的Log的长度信息:
________________________________________
void glGetShaderiv(GLuint object, GLenum type, int *param);
void glGetProgramiv(GLuint object, GLenum type, int *param);
参数:
object - the handler to the object. Either a shader or a program
type - GL_INFO_LOG_LENGTH.
param - the return value, the length of the InfoLog.
________________________________________
ARB扩展:
________________________________________
void glGetObjectParameterivARB(GLhandleARB object, GLenum type, int *param);
参数:
object - the handler to the object. Either a shader or a program
type - GL_OBJECT_INFO_LOG_LENGTH_ARB.
param - the return value, the length of the InfoLog.
________________________________________
OpenGL 2.0使用下面的函数来打印InfoLog的内容:
________________________________________
void printShaderInfoLog(GLuint obj)
{
int infologLength = 0;
int charsWritten = 0;
char *infoLog;
glGetShaderiv(obj, GL_INFO_LOG_LENGTH,&infologLength);
if (infologLength > 0)
{
infoLog = (char *)malloc(infologLength);
glGetShaderInfoLog(obj, infologLength, &charsWritten, infoLog);
printf("%s\n",infoLog);
free(infoLog);
}
}
void printProgramInfoLog(GLuint obj)
{
int infologLength = 0;
int charsWritten = 0;
char *infoLog;
glGetProgramiv(obj, GL_INFO_LOG_LENGTH,&infologLength);
if (infologLength > 0)
{
infoLog = (char *)malloc(infologLength);
glGetProgramInfoLog(obj, infologLength, &charsWritten, infoLog);
printf("%s\n",infoLog);
free(infoLog);
}
}
________________________________________
ARB则使用下面的函数:
________________________________________
void printInfoLog(GLhandleARB obj)
{
int infologLength = 0;
int charsWritten = 0;
char *infoLog;
glGetObjectParameterivARB(obj, GL_OBJECT_INFO_LOG_LENGTH_ARB,
&infologLength);
if (infologLength > 0)
{
infoLog = (char *)malloc(infologLength);
glGetInfoLogARB(obj, infologLength, &charsWritten, infoLog);
printf("%s\n",infoLog);
free(infoLog);
}
}
________________________________________
原文地址:http://www.lighthouse3d.com/opengl/glsl/index.php?oglinfo
调试手段.pdf
(189.63 KB, 下载次数: 692)
|
|