我正在使用 Qt5 和 QGLWidget 类来呈现像素的实时流。我遇到了一些性能问题,想设置一个像素缓冲区来执行异步数据传输。
我正在尝试以老式方式绑定纹理,但它呈现为空白。当我回到我的 Qt5 代码时,一切正常。
有人知道如何让标准 OpenGL 版本工作吗?
在职的
void glStream::reserveTextures()
{
displayBuff = (GLubyte*) calloc(numGLFrames*widthGL*heightGL,
sizeof(GLubyte));
QImage mySurface(&displayBuff[displayStart],widthGL,heightGL,
QImage::Format_Indexed8);
textures[0]=bindTexture(mySurface,GL_TEXTURE_2D,GL_LUMINANCE);
glBindTexture(GL_TEXTURE_2D,0);
glECheck();//no errors
}
不工作
void glStream::reserveTextures()
{
displayBuff = (GLubyte*) calloc(numGLFrames*widthGL*heightGL,sizeof(GLubyte));
glGenTextures(1,&textures[0]);
glBindTexture(GL_TEXTURE_2D,textures[0]);
glTexImage2D(GL_TEXTURE_2D,0,GL_LUMINANCE,widthGL,heightGL,0,GL_LUMINANCE,
GL_UNSIGNED_BYTE,&displayBuff[displayStart]);
glBindTexture(GL_TEXTURE_2D,0);
glECheck();//no errors
}
更新功能
glECheck();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
program1.bind();
program1.setUniformValue("texture", 0);
program1.enableAttributeArray(vertexAttr1);
program1.enableAttributeArray(vertexTexr1);
program1.setAttributeArray(vertexAttr1, vertices.constData());
program1.setAttributeArray(vertexTexr1, texCoords.constData());
glBindTexture(GL_TEXTURE_2D, textures[0]);
glECheck();
glDrawArrays(GL_TRIANGLES, 0, vertices.size());
glBindTexture(GL_TEXTURE_2D,0);
program1.disableAttributeArray(vertexTexr1);
program1.disableAttributeArray(vertexAttr1);
program1.release();
glECheck();
着色器
QGLShader *fshader1 = new QGLShader(QGLShader::Fragment, this);
const char *fsrc1 =
"uniform sampler2D texture;\n"
"varying mediump vec4 texc;\n"
"void main(void)\n"
"{\n"
" gl_FragColor = texture2D(texture, texc.st);\n"
"}\n";
fshader1->compileSourceCode(fsrc1);
program1.addShader(fshader1);