本文介绍了像&QUOT的函数glReadPixels"在DirectX / SharpDX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一种方式来阅读在一个mousepoint像素的颜色。在OpenGL它被调用绘制场景后函数glReadPixels(或它的一部分)来完成。我想作一个简单的颜色选择常规的背景下,为identifing一个形状/在三维空间线条。

I'm searching for a way to read a pixels color at the mousepoint. In OpenGL it was done by calling the function "glReadPixels" after drawing the scene (or parts of it). I want to make a simple color picking routine in the background, for identifing a shapes / lines in 3D Space.

那么,有没有其他等效方法/功能/建议的?做同样的SharpDX(的DirectX10 / DirectX11的)

So, is there any equivalent method/function/suggestion for doing the same in SharpDX (DirectX10 / DirectX11) ?

推荐答案

这是完全可能的Direct3D11:只需按以下步骤操作:

This is perfectly possible with Direct3D11: simply follow these steps:


  • 使用的从源纹理复制一部分暂存纹理(要回读像素面积,相同格式的大小,但ResourceUsage.Staging)

  • 从使用device.map的/ UNMAP该分段的纹理像素。

  • Use DeviceContext.CopySubResourceRegion to copy part from the source texture to a staging texture (size of the pixel area you want to readback, same format, but with ResourceUsage.Staging)
  • Retrieve the pixel from this staging texture using Device.Map/UnMap.

有足够的讨论关于围绕净这个话题(例如:)

There is plenty of discussion about this topic around the net (for example: "Reading one pixel from texture to CPU in DX11")

这篇关于像&QUOT的函数glReadPixels"在DirectX / SharpDX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 22:59