我对片段着色器有疑问。 在我的GL中的变换反馈的情况下,顶点着色器仅在程序中使用而没有任何片段着色器,并且它适用于NVIDIA(GeForce940M)但不适用于我的Intel HD 5500(glerror GL_INVALID_OPERATION,0x0502,glBeginTransformFeedback)。 英特尔高清显卡需要片段着色器吗?或者在NVIDIA和Intel HD之间有不同的设置?
我的简单代码的主要部分是显示问题(忽略GL init。):
.
.
.
GLuint countQuery;
glGenQueries(1, &countQuery);
const std::string init_Vertex_Code =
"#version 330 core \n"
"\n "
"layout (location = 0) in vec4 vPos; \n "
"layout (location = 1) in vec4 vColor; \n "
"layout (location = 2) in vec4 vNorm; \n "
"out vec4 vPos0; \n "
"out vec4 vColor0; \n "
"out vec4 vNorm0; \n "
"void main() \n "
"{ \n "
"vPos0 = vPos; \n "
"vColor0 = vColor; \n "
"vColor0.y = 0; \n "
"vColor0.z = 1; \n "
"vNorm0 = vNorm; \n "
"} \n ";
//initProgram
GLenum initProgram;
initProgram = glCreateProgram();
GLhandleARB shader = glCreateShader(GL_VERTEX_SHADER);
const char* source = init_Vertex_Code.c_str();
glShaderSource(shader, 1, &source, NULL);
glCompileShader(shader);
glAttachShader(initProgram, shader);
glLinkProgram(initProgram);
//initBuffer
std::pair<GLuint, GLuint> vbos;
const int bufferSize = 512 * 512 * sizeof(float) * 3;
float * vertices = new float[bufferSize];
glGenBuffers(1, &vbos.first);
glBindBuffer(GL_ARRAY_BUFFER, vbos.first);
glBufferData(GL_ARRAY_BUFFER, bufferSize, &vertices[0], GL_STREAM_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
//initFeedback
const bool NVIDIA = false; //true for NV, false for Intel
glUseProgram(initProgram);
if (NVIDIA){
const int locInit[3] =
{
glGetVaryingLocationNV(initProgram, "vPos0"),
glGetVaryingLocationNV(initProgram, "vColor0"),
glGetVaryingLocationNV(initProgram, "vNorm0"),
};
glTransformFeedbackVaryingsNV(initProgram, 3, locInit, GL_INTERLEAVED_ATTRIBS);
}
else{
const GLchar* feedbackVaryings[] = { "vPos0", "vColor0", "vNorm0" };
glTransformFeedbackVaryings(initProgram, 3, feedbackVaryings, GL_INTERLEAVED_ATTRIBS);
}
glGenTransformFeedbacks(1, &vbos.second);
glEnable(GL_RASTERIZER_DISCARD);
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, vbos.second);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, vbos.first);
glBeginTransformFeedback(GL_POINTS);
printf("glBeginTransformFeedback success!\n");
glEndTransformFeedback();
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
glDisable(GL_RASTERIZER_DISCARD);
glUseProgram(0);
glDeleteBuffers(1, &vbos.first);
glDeleteTransformFeedbacks(1, &vbos.second);
glDeleteQueries(1, &countQuery);
基于ogl-samples'gl-410-transform-feadback-object的完整项目的压缩文件是here。