简体   繁体   English

SDL2:如何在不清除屏幕的情况下进行渲染

[英]SDL2: How to render without clearing the screen

I'm trying to make a SDL2 adapter for a graphics library. 我正在尝试为图形库制作SDL2适配器。 I believe this library assumes that all the things it draws in the screens stay in the screen as long as it never draws something in top of it. 我相信该库假定它在屏幕上绘制的所有内容都保留在屏幕上,只要它从不在其顶部绘制任何内容即可。 (See the end of the question for details about this) (有关此问题的详细信息,请参阅问题的结尾)

What would be the best way to do it? 最好的方法是什么?

I've come across multiple solutions, including: 我遇到了多种解决方案,包括:

  • Hardware rendering without calling SDL_RenderClear . 无需调用SDL_RenderClear 硬件渲染 The problem with this is that SDL uses a double buffer, so the contents can end up in either of them, and I end up seing only a subset of the render at a time. 问题在于SDL使用了一个双缓冲区,因此内容可以在其中任何一个中结束,而我最终一次仅选择渲染的一个子集。
  • Software rendering , in which if I'm understanding SDL correctly, it would mean having a surface that I mapped to a texture, so I can render the texture, and I would edit the pixels field of the surface in main memory. 软件渲染 ,如果我正确地理解了SDL,则意味着将表面映射到纹理,这样我就可以渲染纹理,然后在主内存中编辑表面的pixels字段。 This would be very slow, and also as the library expects everything rendered instantly and has no notion of frames would mean to send the data to the gpu every time there's an update (even single pixels). 这将非常慢,并且由于库希望所有内容均立即呈现且没有帧的概念,因此每次更新(甚至单个像素)都将数据发送到gpu。

I'm probably missing something about SDL2 and definitely about the library ( Adafruit-GFX-Library ). 我可能缺少有关SDL2的东西,也肯定缺少有关库( Adafruit-GFX-Library )的东西。 What does transaction api means in this context? 在这种情况下, transaction api是什么意思? I've not been able to find any information about it, and I feel like it could be something important. 我找不到任何有关它的信息,我觉得这可能很重要。

In my understanding of SDL2 and general rendering application programming, SDL2 is designed that you draw a complete frame every time, meaning you would clear your "current window" either by OpenGL API calls 在我对SDL2和常规渲染应用程序编程的理解中,SDL2的设计目的是每次绘制一个完整的框架,这意味着您可以通过OpenGL API调用清除“当前窗口”

glClearColor(0, 1.0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);

which clears the current OpenGL context ie frame buffer, of which you would have 2 or by using the SDL2 renderer which I am not familiar with. 这将清除当前的OpenGL上下文,即帧缓冲区,您将拥有其中的2个或使用我不熟悉的SDL2渲染器。 Then you would swap the buffers, and repeat. 然后,您将交换缓冲区,然后重复。 (Which fits perfectly with this architecture proposal I am relying on ) (这完全符合我所依赖的此体系结构建议

So either you would have to replay the draw commands from your library for the second frame somehow, or you could also disable the double frame buffering, at least for the OpenGL backend, by 因此,要么必须以某种方式从库中重放绘制命令以获取第二帧,要么也可以至少通过OpenGL后端禁用双帧缓冲,

SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);

(For the other OpenGL SDL2 setup code see this GitHub repository with a general helper class of mine (有关其他OpenGL SDL2设置代码,请参阅此GitHub存储库以及我的常规帮助程序类

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM