Linux帧缓冲区图形和VSync [英] Linux framebuffer graphics and VSync

查看:142
本文介绍了Linux帧缓冲区图形和VSync的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C上制作了一个适用于linux framebuffer的游戏。到目前为止,我有一个红色的100x100正方形,与鼠标一起移动,就像一个指针。我实现了双缓冲,并且它可以正常工作(方块不闪烁)。问题是,水平地发生了很多撕裂事件。我的意思是,当方格在x轴上移动时,就像是水平分开的,其中一部分比另一部分更容易前进。如果我继续移动它,这个翻录会在广场上从上到下慢慢传播。



我相信这是因为硬件在我复制时读取帧缓冲区双缓冲区进入主缓冲区。



我试图用FBIO_WAITFORVSYNC ioctl解决问题,但没有成功。



我有什么想法可以在framebuffer上做VSync?请在您的解释中添加详细信息,因为这是我第一次在基于Linux的操作系统上编程这样的东西,所以我可能无法理解。



这是我的代码:< http://bastebin.com/KJ4iaVEL

方案

这不是做双缓冲的正确方法。你是正确的做后台缓冲区的所有绘画,但是你做一个memcpy将数据传送到前台。在复制过程中很容易发生屏幕刷新。



为了正确执行此操作,您只需将切换到数据指针;不要复制数据本身。使用Linux framebuffer设备,可以通过具有比实际屏幕大两倍的虚拟屏幕来完成此操作,并使用偏移量变量来设置您是显示上半部还是下半部。您可以使用 FBIOGET_VSCREENINFO FBIOPUT_VSCREENINFO FBIOPAN_DISPLAY 来查询大小和设置偏移量。 code> ioctl 调用。



本页简要介绍一些相关细节: http://www.ummon.eu/Linux/API/Devices/framebuffer.html



所有相关的数据结构位于 linux / fb.h 头文件中。


I'm making a game in C that works on the linux framebuffer. So far I have a red 100x100 square that moves in tandem with the mouse, just like a pointer. I have implemented double buffering and it works correctly (the square doesn't flicker). The problem is, there is quite a lot of tearing happening horizontally. What I mean by that is, when the square moves on the x axis, it's like it is divided horizontally, and one part of it advances slithgly more than the other. This "rip" slowly propagates from top to bottom on the square if i keep moving it.

I believe it happens because the hardware reads the framebuffer during the moment when I copy the double buffer into the main buffer.

I have tried to combat the problem with the FBIO_WAITFORVSYNC ioctl, but no success.

Any ideas how I could do VSync on the framebuffer? Please add detail to your explanations as this is the first time I am programming such stuff on a Linux based OS so I might not understand otherwise.

Here is my code: http://pastebin.com/KJ4iaVEL

解决方案

This isn't the correct way to do double-buffering. You're right to do all the painting on a back-buffer, but then you do a memcpy to transfer the data to the front. A screen refresh could easily happen during the copy.

To do this properly, you should only have to switch a pointer to the data; not copy the data itself. With the Linux framebuffer device, this is done by having a "virtual" screen that is twice as large as the physical screen, and using an offset variable to set whether you're showing the top or bottom half. You can query the size and set offset using the FBIOGET_VSCREENINFO, FBIOPUT_VSCREENINFO, and FBIOPAN_DISPLAY ioctl calls.

This page briefly gives some details about this: http://www.ummon.eu/Linux/API/Devices/framebuffer.html

All the relevant data structures are in the linux/fb.h header file.

这篇关于Linux帧缓冲区图形和VSync的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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