- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
为了学习我自己的 Direct2D,我正在关注 this example来自 MSDN。
但是我有一个问题。调用 D2D1_SIZE_F rtSize = m_pRenderTarget->GetSize();
始终返回大小 0,0,并且在调试器中导致 DrawLine
调用异常。如果我省略 GetSize() 调用并使用有效值填充 D2D1_SIZE_F 结构,它就可以工作。
初始化渲染目标的相关代码为:
RECT rc;
GetClientRect(m_hwnd, &rc);
D2D1_SIZE_U size = D2D1::SizeU(
rc.right - rc.left,
rc.bottom - rc.top
);
// Create a Direct2D render target.
hr = m_pDirect2dFactory->CreateHwndRenderTarget(
D2D1::RenderTargetProperties(),
D2D1::HwndRenderTargetProperties(m_hwnd, size),
&m_pRenderTarget
);
我已经通过调试器验证过有效值的大小。
调用GetSize的绘图代码部分:
m_pRenderTarget->BeginDraw();
m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());
m_pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White));
D2D1_SIZE_F rtSize = m_pRenderTarget->GetSize();
// Draw a grid background.
int width = static_cast<int>(rtSize.width);
int height = static_cast<int>(rtSize.height);
for (int x = 0; x < width; x += 10)
{
m_pRenderTarget->DrawLine(
D2D1::Point2F(static_cast<FLOAT>(x), 0.0f),
D2D1::Point2F(static_cast<FLOAT>(x), rtSize.height),
m_pLightSlateGrayBrush,
0.5f
);
}
所以我的问题是为什么 GetSize() 会返回 0,0 并在稍后导致 AV?
顺便说一句:我正在使用:Windows 7 旗舰版 64 位代码:: block IDETDM-GCC-64 gcc编译器v4.8.1我在 Unicode 模式下编译 #define UNICODE
无论我编译为 32 位还是 64 位,都会出现问题(是的,我对 64 位模式做了一些小调整,以确保我有一个指向 WndProc 中应用程序对象的有效指针)
最佳答案
Why does GetSize() return 0,0 and causes an AV later on?
因为 GCC/MinGW-W64 生成的 GetSize 调用与 d2d1.dll
中实现的调用约定不匹配。 GetSize 的返回类型 D2D_SIZE_F
是一个结构体。根据Microsoft Docs有两种方法可以从函数返回结构:
User-defined types can be returned by value from global functions and static member functions. To return a user-defined type by value in RAX, it must have a length of 1, 2, 4, 8, 16, 32, or 64 bits. It must also have no user-defined constructor, destructor, or copy assignment operator. It can have no private or protected non-static data members, and no non-static data members of reference type. It can't have base classes or virtual functions. And, it can only have data members that also meet these requirements. (This definition is essentially the same as a C++03 POD type. Because the definition has changed in the C++11 standard, we don't recommend using std::is_pod for this test.) Otherwise, the caller must allocate memory for the return value and pass a pointer to it as the first argument.
当 GCC/MinGW-W64 编译文章中的示例代码时,调用者仅为调用 GetSize 设置一个参数(在 rcx
中),并期望在 rax
:
# AT&T syntax (destination operand last)
mov 0x10(%rbx),%rcx # rcx <- pointer to IRenderContext
mov (%rcx),%rax # rax <- pointer to virtual function table
callq *0x1a8(%rax) # virtual function call (expect result in rax)
在 Visual Studio 生成的代码中,调用者在调用 GetSize 之前将 rdx
设置为指向堆栈上的某个位置:
# Intel syntax (destination operand first)
mov rax,qword ptr [rsp+168h] # rax <- pointer to IRenderContext
mov rax,qword ptr [rax] # rax <- pointer to virtual function table
lea rdx,[rsp+68h] # rdx <- address of return value (hidden argument)
mov rcx,qword ptr [rsp+168h] # rcx <- this pointer (hidden argument)
call qword ptr [rax+1A8h] # virtual function call (expect result at [rdx])
在 GCC/MinGW-W64 上,rdx
中的值不是有效地址,因此当 GetSize 的实现尝试将返回值存储在内存中时,会发生访问冲突。
D2D_SIZE_F
是一个 64 位 POD 结构(只是两个 float 的结构),所以在我看来 GCC 在 rax
寄存器中返回它是正确的.我不知道是什么让 Visual Studio 使用指针返回,恐怕也不知道如何让 GCC 为兼容性做同样的事情。
关于c++ - RenderTarget->GetSize 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27888109/
为了学习我自己的 Direct2D,我正在关注 this example来自 MSDN。 但是我有一个问题。调用 D2D1_SIZE_F rtSize = m_pRenderTarget->GetSi
我试图在第一次绘制时将纹理加载到渲染目标中,然后保留内容以在每一帧绘制相同的纹理而不重新创建它。 这是我的代码,但它不起作用,只显示空纹理区域和 RenderTarget2D rTarget = nu
The HelloWorld examples from Microsoft大多数情况下使用单个 CommandAllocator,然后等到前一帧完全完成。然而,他们也说(全部大写)这不是应该做的。
我试图在运行时更改 RenderTargets,这样我就可以在运行时绘制一些元素,对其进行操作,然后最终将纹理绘制到屏幕上。问题是,如果我在运行时更改 RenderTarget,屏幕会变成紫色。这是我
我目前正在从头开始为 XNA 游戏创建一个窗口系统。我主要为 Windows 开发,但谁知道我将来可能支持哪些平台。如果您知道 native Direct3D 的这一点,请随意回答,因为性能语义应该相
这是一个很难描述的问题(我使用的是 MonoGame,Windows 8)。 我希望能够渲染一个半透明的“sprite”图像,例如 .png,而不是在屏幕上,而是在一个清晰的图像上,这样做几次,实际上
我是计算机图形学专业的大学硕士生,我在使用 three.js 访问使用 EffectComposer 创建的纹理的图像数据(像素)时遇到困难。 第一个 composer (composer) 使用线检
在 XNA 中,我需要获取对 BackBuffer 的 RenderTarget(2D) 的引用,以便将其绘制到纹理或更改其用法 到 Usage.PreserveContents,是否有任何方法允许我
XNA 菜鸟在这里,每天都在学习。我刚刚弄清楚如何使用 RenderTarget2D 将多个纹理合成一个。然而,虽然我可以将 RenderTarget2D 用作大多数用途的 Texture2D,但存在
我在 scene1plane1 上添加了半透明 texture 我将此场景1渲染到renderTarget中,而不是在放置在另一个场景2上的另一个平面2上使用renderTarget.texture。
我正在尝试使用 C++ Builder 的 TDirect2DCanvas 的 Direct2D RenderTarget 属性来对使用 GPU 的位图操作进行基准测试。与 GDI 相比,这是最令人印
我想渲染一个场景并将其显示在监视器上,同时将另一个场景渲染为纹理。我需要创建两个交换链吗?在这种情况下如何创建第二个交换链?我尝试调用 CreateSwapChainForCoreWindow 但出现
我有一个在 Win32 应用程序上运行的 C++ 小型 2D 渲染库,并使用 Direct2D 进行绘图。我调用了 BeginDraw(),完成了大量绘图,然后调用了 DrawText()。这当然是在
我有一个纹理及其 shaderresourceview,我通过将其用作 RenderTarget 来渲染场景的原始图像。 就像我之前的数百万人一样,然后我将它用作我下一个着色器的输入,这样我就可以模糊
我是一名优秀的程序员,十分优秀!