如何在处理2.x时启用VSync同步? [英] How to enable VSync synchronization in processing 2.x?

查看:157
本文介绍了如何在处理2.x时启用VSync同步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前,在处理1.x时,我使用以下代码启用VSync同步:

Previously, in processing 1.x, I used the following code to enable VSync synchronization:

void enableVSync()
{
    frameRate(-1);
    GL pgl = (PGraphicsOpenGL)g;
    gl = pgl.beginGL();
    gl.setSwapInterval(1);
    pgl.endGL();
}

这在处理2.x时不起作用我似乎无法了解它应该如何工作,甚至是否应该在处理2.x时工作。

This does not work in processing 2.x and I can't seem to find out how or even if it is supposed to work in processing 2.x.

编辑:

尺寸(500,500); 切换到尺寸(500,500,P2D); ,似乎有所帮助。它现在看起来像处理后备缓冲区中的所有绘图并将其切换到VSync的前缓冲区。

By switching from size(500, 500); to size(500, 500, P2D);, it seems to help. It now looks like processing does all the drawing in a back buffer and switches it to the front buffer at the VSync.

然而,绘制( )函数仍然与vsync异步,即使我看不到任何撕裂,每当跳过或抽出两次帧时仍然会出现运动卡顿。

However, the draw() function is still asynchronous with the vsync and even though I don't see any tearing anymore, there's still motion stuttering whenever a frame is skipped or drawn twice.

推荐答案

事实证明, frameRate()实际上在 PJOGL 中运行 setSwapInterval()虽然有一些关于值集的奇怪逻辑( github )。解决方法是:

Turns out, frameRate() in PJOGL actually runs setSwapInterval() though with some strange logic regarding the value set (github). A workaround for this is:

void setup()
{
    setup(500, 500, P2D);
    frameRate(-1);                                      // set unlimited frame rate
    ((PJOGL)PGraphicsOpenGL.pgl).gl.setSwapInterval(1); // enable waiting for vsync
                                                        // before swapping back/front buffers
}

编辑:

对于处理3,我使用以下内容:

For Processing 3, I use the following:

import java.awt.*;
import javax.media.opengl.glu.GLU;

void setup()
{
    frameRate(-1);
    beginPGL();
    GLU.getCurrentGL().getGL2().setSwapInterval(1);
    endPGL();
}

编辑2:

对于Processing 3.2,以下似乎有效:

For Processing 3.2, the following seems to work:

void setup()
{
  fullScreen(P3D);
  frameRate(1000);
  PJOGL pgl = (PJOGL)beginPGL();
  pgl.gl.setSwapInterval(1);
  endPGL();
}

这篇关于如何在处理2.x时启用VSync同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆