※ [本文转录自 C_and_CPP 看板 #1MnbOvZX ]
作者: ResolaQQ (ResolaQQ) 看板: C_and_CPP
标题: [问题] SDL2 RenderPresent 的叙述看不太懂
时间: Fri Feb 19 07:39:34 2016
额外使用到的函数库(Library Used): (Ex: OpenGL, ...)
SDL2
问题(Question):
SDL_RenderPresent 的叙述如下
SDL's rendering functions operate on a backbuffer; that is, calling a rendering
function such as SDL_RenderDrawLine() does not directly put a line on the
screen, but rather updates the backbuffer. As such, you compose your entire
scene and present the composed backbuffer to the screen as a complete picture.
Therefore, when using SDL's rendering API, one does all drawing intended for
the frame, and then calls this function once per frame to present the final
drawing to the user.
The backbuffer should be considered invalidated after each present; do not
assume that previous contents will exist between frames. You are strongly
encouraged to call SDL_RenderClear() to initialize the backbuffer before
starting each new frame's drawing, even if you plan to overwrite every pixel.
我不太理解文中的 backbuffer 是指什么,像底下这应该是错误的
SDL_RenderClear(renderer) // 清除绘图内容
SDL_RenderDrawLine(renderer, 0, 0, 100, 100) // 画条斜线从 (0,0) 到 (100,100)
SDL_RenderPresent(renderer) // 显示到萤幕上
SDL_RenderPresent(renderer) // 错误,显示到萤幕上后,绘图内容应该被假设为无效
但底下这个有没有问题呢?我就不确定了
SDL_SetRenderTarget(renderer, texture) // 把绘图目标设定到 texture 上
SDL_RenderDrawLine(renderer, 0, 0, 100, 100) // 画条斜线从 (0,0) 到 (100,100)
SDL_SetRenderTarget(renderer, NULL) // 把绘图目标设定回默认值
SDL_RenderCopy(renderer, texture, NULL, NULL) // 把 texture 的内容拷贝进去
SDL_RenderPresent(renderer) // 显示到萤幕上
SDL_RenderCopy(renderer, texture, NULL, NULL) // 这时候,texture 是有效的吗?
SDL_RenderPresent(renderer) // 是否可以这样把之前绘制过的图形再次显示出来?
texture 似乎是一小块显示卡的内存
不知道叙述里的 backbuffer 有没有包含 texture?
还是仅止于默认的绘图目标?