1

我有一些为 Linux 编写的代码,我需要重新实现这些代码,以便它可以在 Windows 和 Linux 上运行。它目前是 X-Windows、GLX 和 OpenGL 2.1,我正在使用 SDL2 和使用 GLEW 的兼容 OpenGL 扩展(它仍在旧的(Centos 5.3)Linux 平台以及带有 6 年旧显卡的最新 Windows 上运行)。

我被困在如何替换 glXMakeContextCurrent 上。这当前用于选择读取和绘制像素缓冲区 (GLXPbuffer) 并与上下文关联。我一直在研究使用像素缓冲区对象来替换 GLXPbuffers 但不知道如何使用此类技术复制 glXMakeContextCurrent 的功能,或者是否有更好的方法来做到这一点。

现有代码对其进行设置,使其呈现为 GLXPbuffer,然后使用 glCopyPixels 使用指定的上下文从一个可绘制对象(一个 GLXPbuffer)复制到另一个(另一个 GLXPbuffer),并在 glXMakeContextCurrent 调用中指定 Draw 和 Read Drawables 和 Context . 这是一个主要是 2D 的 OpenGL 应用程序。

在不使用 GLX 的情况下如何实现这一点,即它可以在 Windows(以及 Linux)上运行?

这是一个代码段,显示了当前代码的作用:

Display       *dpy;
GLXContext    osr_ctx;
GLXPbuffer    pbuf2, osr_pbuf;

void sel_drc( GLXDrawable dst, GLXDrawable src, SDL_GLContext ctx )
{
       if ( !src )
       {
              if ( !glXMakeCurrent( dpy, dst, ctx ) )
              {
                     Error( "glXMakeCurrent" );
              }
       }
       else
       {
              if ( !glXMakeContextCurrent( dpy, dst, src, ctx ) )
              {
                     Error( "glXMakeContextCurrent" );
              }
       }
}
// Display dpy is set up elsewhere.
// GLXContext and GLXPbuffers get created elsewhere and stored in osr_ctx, pbuf2, osr_pbuf
// The Display and GLXContexts are to be replaced by their SDL2 equivalents.
// GLXPbuffers are currently planned to be Pixel Buffer Objects:
//  GLuint pboIds[2];
//  glGenBuffers(2, pboIds);
//  glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pboIds[0]);
//  glBufferData(GL_PIXEL_UNPACK_BUFFER, DATA_SIZE, 0, GL_STREAM_DRAW);
//  etc.
//
sel_drc( osr_pbuf, pbuf2, osr_ctx );
glRasterPos2f( 0.1, 0.1 );
glCopyPixels ( 0, 0, 576, 576, GL_COLOR );
4

1 回答 1

1

看起来一个简单的,虽然可能是低性能的解决方案是使用 Framebuffer 对象并使用 glBlitFramebuffer 在它们之间进行 blit:

GLuint fboId;                       // ID of FBO
glBindFramebuffer(GL_READ_FRAMEBUFFER, fboId);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBlitFramebuffer(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT,
                  0, 0, screenWidth, screenHeight,
                  GL_COLOR_BUFFER_BIT,
                  GL_LINEAR);
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);

这相当于在两个帧缓冲区对象之间进行复制。在这种情况下,代码从 FBO (fboId) 复制到默认帧缓冲区 (0)。

此代码来自: http: //www.songho.ca/opengl/gl_fbo.html

似乎渲染到纹理然后将四边形渲染到具有该纹理绑定的目标帧缓冲区中会更快。但是,这种 glBlitFramebuffer 方法接近于现有的代码结构,可能不会比目前使用的 glCopyPixels 差。

于 2014-06-25T14:32:06.920 回答