为什么DirectX全屏应用程序会显示黑色屏幕截图? [英] Why do DirectX fullscreen applications give black screenshots?

查看:117
本文介绍了为什么DirectX全屏应用程序会显示黑色屏幕截图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可能知道,尝试以GDI方式(使用 BitBlt())捕获DirectX全屏应用程序会得到黑色屏幕截图。

You may know that trying to capture DirectX fullscreen applications the GDI way (using BitBlt()) gives a black screenshot.

我的问题很简单,但找不到任何答案:为什么?我的意思是从技术上讲,为什么它会给出黑色的屏幕截图?

My question is rather simple but I couldn't find any answer: why? I mean technically, why does it give a black screenshot?

我在这里阅读DirectX教程: http://www.directxtutorial.com/Lesson.aspx?lessonid=9-4-1 。它的写法是:

I'm reading a DirectX tutorial here: http://www.directxtutorial.com/Lesson.aspx?lessonid=9-4-1. It's written:


[...]函数BeginScene()[...]进行了称为锁定的操作,其中视频RAM被锁定,授予您对该内存的独占访问权限。

[...] the function BeginScene() [...] does something called locking, where the buffer in the video RAM is 'locked', granting you exclusive access to this memory.

这是原因吗? VRAM已锁定,因此GDI无法访问它,并且屏幕截图为黑色?
还是还有其他原因?像DirectX一样直接与图形卡对话,而GDI无法得到图形卡?

Is this the reason? VRAM is locked so GDI can't access it and it gives a black screenshot? Or is there another reason? Like DirectX directly "talks" to the graphic card and GDI doesn't get it?

谢谢。

推荐答案

原因很简单:性能。

想法是尽可能地在GPU上渲染场景,而与CPU不同步。您使用CPU将渲染缓冲区发送到GPU(顶点,索引,着色器等),由于它们很小,因此总体来说确实很便宜,然后您就可以做任何您想做的事情,物理操作,多人同步等。GPU可以处理

The idea is to render a scene as much as possible on the GPU out of lock-step with the CPU. You use the CPU to send the rendering buffers to the GPU (vertex, indices, shaders etc), which is overall really cheap because they're small, then you do whatever you want, physics, multiplayer sync etc. The GPU can just crunch the data and render it on its own.

如果需要在窗口上绘制场景,则必须中断GPU,要求提供渲染缓冲区字节( LockRect ),为窗口请求图形对象(对GPU的干扰更大),渲染它并释放每个锁。通过与GPU不同步在GPU上渲染,您刚刚失去了任何收获。更糟糕的是,当您想到所有不同的CPU内核由于忙于渲染而闲置时(更像是等待缓冲区传输)。

If you require the scene to be drawn on the window, you have to interrupt the GPU, ask for the rendering buffer bytes (LockRect), ask for the graphics object for the window (more interference with the GPU), render it and free every lock. You just lost any sort of gain you had by rendering on the GPU out of sync with the CPU. Even worse when you think of all the different CPU cores just sitting idle because you're busy "rendering" (more like waiting on buffer transfers).

所以图形驱动程序要做的是用神奇的颜色绘制渲染区域,并告诉GPU场景的位置,GPU负责将场景覆盖在基于魔术色像素的显示屏幕(一种多遍像素着色器,当第一个纹理具有特定颜色的 x ,<$时,从第二个纹理获取c $ c> y ,但并不慢)。您会完全脱离同步渲染,但是当您要求操作系统提供其视频内存时,您会得到场景所处位置的魔幻色彩,因为这正是它实际使用的颜色。

So what graphics drivers do is they paint the rendering area with a magic color and tell the GPU the position of the scene, and the GPU takes care of overlaying the scene over the displayed screen based on the magic color pixels (sort of a multi-pass pixel shader that takes from the 2nd texture when the 1st texture has a certain color for x,y, but not that slow). You get completely out of sync rendering, but when you ask the OS for its video memory, you get the magic color where the scene is because that's what it actually uses.

参考: http://en.wikipedia.org/wiki/Hardware_overlay

这篇关于为什么DirectX全屏应用程序会显示黑色屏幕截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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