我需要更改一个非常旧的应用程序,以便能够通过远程桌面连接工作(它只支持opengl 1.1的一个子集)。它只需要各种opengl 1。因此,我尝试使用在应用程序文件夹中放置mesa opengl32.dll文件的技巧。该应用程序只使用少量的opengl,所以使用性能较低的软件渲染器是可以的。
无论如何,我从https://wiki.qt.io/Cross_compiling_Mesa_for_Windows获得了预编译的mesa opengl32.dll文件,但我无法获得启用模板缓冲区的pixelformat/context。如果我禁用模板缓冲区使用,那么其他一切都可以工作,但如果我能弄清楚如何获得pixelformat/context与模板缓冲区启用。
这是上下文创建代码的pixelformat部分:
function gl_context_create_init(adevice_context:hdc):int;
var
pfd,pfd2:tpixelformatdescriptor;
begin
mem_zero(pfd,sizeof(pfd));
pfd.nSize:=sizeof(pfd);
pfd.nVersion:=1;
pfd.dwFlags:=PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER;
pfd.iPixelType:=PFD_TYPE_RGBA;
pfd.cColorBits:=32;
pfd.iLayerType:=PFD_MAIN_PLANE;
pfd.cStencilBits:=4;
gl_pixel_format:=choosepixelformat(adevice_context,@pfd);
if gl_pixel_format=0 then
gl_error('choosepixelformat');
if not setpixelformat(adevice_context,gl_pixel_format,@pfd) then
gl_error('setpixelformat');
describepixelformat(adevice_context,gl_pixel_format,sizeof(pfd2),pfd2);
if ((pfd.dwFlags and pfd2.dwFlags)<>pfd.dwFlags) or
(pfd.iPixelType<>pfd2.iPixelType) or
(pfd.cColorBits<>pfd2.cColorBits) or
(pfd.iLayerType<>pfd2.iLayerType) or
(pfd.cStencilBits>pfd2.cStencilBits) then
gl_error('describepixelformat');
...
end;
错误发生在行(pfd.cStencilBits>pfd2.cStencilBits),我似乎找不到一个像素格式的cStencilBits不是0通过mesa,所以我不能得到一个支持stencils的上下文。
事实证明,choosepixelformat不能选择只能通过mesa opengl32.dll提供的像素格式,然而,wglchoosepixelformat可以选择只能通过mesa提供的像素格式,所以我的问题解决了,因为我现在已经能够在使用这个旧程序的远程桌面连接时获得模板缓冲区。
我不明白的事情,但没有时间去看(如果你知道答案,请张贴在这个答案的评论),是setpixelformat和descripbepixelformat都工作得很好,像素格式只能通过台面。我希望所有3的choosepixelformat/setpixelformat/descripbepixelformat要么全部工作,要么全部不工作,但这就是它是如何。