我不明白为什么这段代码工作,直到我不使用Optirun
//Initialize GLUT and OpenGL
void ViewPort::startVideo(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(XWIN, YWIN);
glutCreateWindow("Titolo");
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_TEXTURE_CUBE_MAP);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
//OpenGL INFO
printf("GL_VERSION: %sn", glGetString(GL_VERSION));
printf("GL_RENDERER: %sn", glGetString(GL_RENDERER));
printf("GL_VENDOR: %sn", glGetString(GL_VENDOR));
shadow = new ShadowMap(256 * SHADOW_QUALITY, 256 * SHADOW_QUALITY);
}
/*...*/
ShadowMap::ShadowMap(int w, int h) {
this->h = h;
this->w = w;
shadowShader = new Shader("./basicShader.vs", "./shadowShader.fs");
// Create the cube map
glGenTextures(1, &shadowCubeID);
glBindTexture(GL_TEXTURE_CUBE_MAP, shadowCubeID);
if (int err = glGetError())
cerr << "glDebug: " << gluErrorString(err) << " shadow map" << endl;
for (unsigned int i = 0; i < 6; i++) {
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_DEPTH_COMPONENT, w, w, 0,
GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
if (int err = glGetError())
cerr << "glDebug: " << gluErrorString(err) << " shadow map" << endl;
}
//now i render to the shadowFBO
glGenFramebuffers(1, &shadowFBO);
glBindFramebuffer(GL_FRAMEBUFFER, shadowFBO);
//disable read and write from color buffer
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X,
shadowCubeID, 0);
errorCheckFBO();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
}
错误(无效操作)是当我用glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + I,…)创建立方体地图的六个面的每个人时。我唯一能想到的是与OpenGL版本有一些不兼容。
程序工作时打印的OpenGL信息如下:
GL_VERSION: 3.0 Mesa 10.1.3
GL_RENDERER: Mesa DRI Intel(R) Haswell Mobile
GL_VENDOR: Intel Open Source Technology Center
当它不工作时:
GL_VERSION: 2.1 Mesa 10.1.3
GL_RENDERER: Gallium 0.4 on llvmpipe (LLVM 3.4, 256 bits)
GL_VENDOR: VMware, Inc.
我怎样才能绕过这个问题?(抱歉我的英文不好)
opengl2.1不支持立方体贴图深度纹理。来自规范:
只有当目标为TEXTURE_1D, TEXTURE_2D, PROXY_TEXTURE_1D或PROXY_TEXTURE_2D时,纹理图像规范命令才支持基本内部格式为DEPTH_COMPONENT的纹理。将此格式与任何其他目标结合使用将导致INVALID_OPERATION错误。
3.0规范中的相应段落更改为:
纹理图像规范命令只支持基本内部格式为DEPTH_COMPONENT或DEPTH_STENCIL的纹理,如果目标为TEXTURE_1D, TEXTURE_2D, TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D, PROXY_TEXTURE_1D_ARRAY, PROXY_TEXTURE_2D_ARRAY或PROXY_TEXTURE_CUBE_MAP。将这些格式与任何其他目标结合使用将导致INVALID_OPERATION错误。
基于此,立方体贴图深度纹理是OpenGL 3.0及更高版本的一个特性。