official java documentation给出了如何使用BufferStrategy的示例:
// Render single frame
do {
// The following loop ensures that the contents of the drawing buffer
// are consistent in case the underlying surface was recreated
do {
// Get a new graphics context every time through the loop
// to make sure the strategy is validated
Graphics graphics = strategy.getDrawGraphics();
// Render to graphics
// ...
// Dispose the graphics
graphics.dispose();
// Repeat the rendering if the drawing buffer contents
// were restored
} while (strategy.contentsRestored());
// Display the buffer
strategy.show();
// Repeat the rendering if the drawing buffer was lost
} while (strategy.contentsLost());
然而,我无法完全掌握这里发生的事情,因为文档对样本来说很安静。
从这段代码示例中我得到了以下概念:在图形对象上调用多个方法时,底层视频内存(VRAM)可能会丢失并在中途恢复。必须重复整个渲染过程。我没有得到的,为什么在策略实例上调用show之后会检查丢失的内容?