无法编译 GL ES 2.0 Shader
我在 GLES2 之上完成了一个简单的 API。一切看起来都正常,但是 GL_COMPILE_STATUS
的状态是 GL_FALSE
。
我有一个像这样的结构:
typedef struct MyGLShader__
{
GLuint uiHandle;
GLenum eType;
const char *pcSource;
} MyGLShader;
我以这种方式初始化它并使用我的函数创建一个着色器:
MyGLShader shader = {0, GL_VERTEX_SHADER, MY_VERTEX_SHADER_SOURCE};
shader_create(&shader);
该函数应该创建着色器:
MyStatus shader_create(MyGLShader *pShader)
{
MyStatus eStatus;
pShader->uiHandle = glCreateShader(pShader->eType);
MY_GL_VALIDATE("glCreateShader");
glShaderSource(pShader->uiHandle, 1, &pShader->pcSource, NULL);
MY_GL_VALIDATE("glShaderSource");
glCompileShader(pShader->uiHandle);
eStatus = shader_check(pShader);
if (eStatus != MY_STATUS_OK)
{
return eStatus;
}
return MY_STATUS_OK;
}
在调用 shader_check()
之前它不会遇到任何问题:
static MyStatus shader_check(MyGLShader *pShader)
{
GLint status;
LOGI("Checking shader compilation status...");
glGetShaderiv(pShader->uiHandle, GL_COMPILE_STATUS, &status);
if (status != GL_TRUE)
{
LOGE("Shader compilation has failed");
shader_log_infolog(pShader);
return MY_STATUS_ERROR;
}
return MY_STATUS_OK;
}
它偶然发现:if (status != GL_TRUE)
。
之后,当它尝试打印 shader_log_infolog
中的信息日志时:
static void shader_log_infolog(
MyGLShader *pShader, MyStatus eStatus)
{
char acbuffer[INFO_LENGTH];
glGetShaderInfoLog(pShader->uiHandle, INFO_LENGTH, NULL, (char *) &acbuffer);
LOGE("Shader Log: %s", acbuffer)
}
它不会打印任何日志,即它只打印
着色器日志:
任何想法我在初始化时可能做错了什么。 MY_GL_VALIDATE
使用 glGetError()
检查 gl 错误,我可以确认它工作正常。
更新
这是着色器源定义:
#define MY_VERTEX_SHADER_SOURCE \
\
" \
attribute vec4 a_Position; \
\
void main() { \
gl_Position = a_Position; \
} \
\
"
I've done a simple API on top of GLES2. Everything seems OK, but the state of GL_COMPILE_STATUS
is GL_FALSE
.
I've got a structure like this:
typedef struct MyGLShader__
{
GLuint uiHandle;
GLenum eType;
const char *pcSource;
} MyGLShader;
I initialize it this way and create a shader using a function of mine:
MyGLShader shader = {0, GL_VERTEX_SHADER, MY_VERTEX_SHADER_SOURCE};
shader_create(&shader);
This function should be creating the shader:
MyStatus shader_create(MyGLShader *pShader)
{
MyStatus eStatus;
pShader->uiHandle = glCreateShader(pShader->eType);
MY_GL_VALIDATE("glCreateShader");
glShaderSource(pShader->uiHandle, 1, &pShader->pcSource, NULL);
MY_GL_VALIDATE("glShaderSource");
glCompileShader(pShader->uiHandle);
eStatus = shader_check(pShader);
if (eStatus != MY_STATUS_OK)
{
return eStatus;
}
return MY_STATUS_OK;
}
It goes without trouble until it calls shader_check()
:
static MyStatus shader_check(MyGLShader *pShader)
{
GLint status;
LOGI("Checking shader compilation status...");
glGetShaderiv(pShader->uiHandle, GL_COMPILE_STATUS, &status);
if (status != GL_TRUE)
{
LOGE("Shader compilation has failed");
shader_log_infolog(pShader);
return MY_STATUS_ERROR;
}
return MY_STATUS_OK;
}
Which stumbles on: if (status != GL_TRUE)
.
After that, when it tries to print the infolog in shader_log_infolog
:
static void shader_log_infolog(
MyGLShader *pShader, MyStatus eStatus)
{
char acbuffer[INFO_LENGTH];
glGetShaderInfoLog(pShader->uiHandle, INFO_LENGTH, NULL, (char *) &acbuffer);
LOGE("Shader Log: %s", acbuffer)
}
It doesn't print any log, i.e. it only prints
Shader Log:
Any ideas what I may be doing wrong with the initialization. MY_GL_VALIDATE
checks for gl errors using glGetError()
and I can confirm it works fine.
UPDATE
Here's the Shader source definition:
#define MY_VERTEX_SHADER_SOURCE \
\
" \
attribute vec4 a_Position; \
\
void main() { \
gl_Position = a_Position; \
} \
\
"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我忘记设置 EGL 以使用 GLES2。它使用的是 GLES1 的默认值。奇怪的是,驱动程序并没有抱怨在 GLES1 环境中使用 GLES2 功能。
I had forgotten to setup the EGL to use GLES2. It was using the defaults which are for GLES1. Strangely enough, the drivers didn't complain for using GLES2 functions in a GLES1 context.