vs D3D11 调试 错误信息显示

16 篇文章 0 订阅
8 篇文章 0 订阅

D3D11 程序调用经常碰到莫名其妙的错误。错误码一般就是E_INVALIDARG。具体原因大概是为了对外尽量减少暴露  以及 利用返回错误来避免一些低效的程序操作。
但是调试时发现其实是有错误信息显示的,如下:

经过一番查找,这个日志的输出与D3D device 创建时有关。

UINT createDeviceFlags = 0;
#ifdef _DEBUG
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; //设置该参数,能显示错误日志
#endif
hr = D3D11CreateDevice( nullptr, g_driverType, nullptr, createDeviceFlags, featureLevels, numFeatureLevels, D3D11_SDK_VERSION, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext );

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 D3D11 中实现视频按比例播放显示的方法如下: 1. 首先,获取视频的原始宽度和高度,以及视频播放区域的宽度和高度。 2. 计算出视频的宽高比和播放区域的宽高比,如果两者不相等,则需要进行缩放操作。 3. 计算出缩放后的视频宽度和高度,以及视频顶点的左上角坐标。 4. 在 D3D11 中创建一个纹理并将视频帧数据拷贝到纹理中。 5. 在 D3D11 中创建一个顶点缓冲区并设置顶点坐标和纹理坐标。 6. 在 D3D11 中创建一个着色器并设置纹理采样器。 7. 在 D3D11 中绘制顶点缓冲区中的数据。 下面是一个简单的示例代码: ```c++ // 获取视频的原始宽度和高度 int videoWidth = ...; int videoHeight = ...; // 获取视频播放区域的宽度和高度 int renderWidth = ...; int renderHeight = ...; // 计算视频的宽高比和播放区域的宽高比 float videoAspectRatio = (float)videoWidth / (float)videoHeight; float renderAspectRatio = (float)renderWidth / (float)renderHeight; // 计算缩放后的视频宽度和高度 int scaledWidth = videoWidth; int scaledHeight = videoHeight; if (videoAspectRatio != renderAspectRatio) { if (videoAspectRatio > renderAspectRatio) { scaledHeight = (int)((float)renderWidth / videoAspectRatio); scaledWidth = renderWidth; } else { scaledWidth = (int)((float)renderHeight * videoAspectRatio); scaledHeight = renderHeight; } } // 计算视频顶点的左上角坐标 int posX = (renderWidth - scaledWidth) / 2; int posY = (renderHeight - scaledHeight) / 2; // 在 D3D11 中创建一个纹理并将视频帧数据拷贝到纹理中 ID3D11Texture2D* pTexture = nullptr; D3D11_TEXTURE2D_DESC textureDesc = {}; textureDesc.Width = scaledWidth; textureDesc.Height = scaledHeight; textureDesc.MipLevels = 1; textureDesc.ArraySize = 1; textureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; textureDesc.SampleDesc.Count = 1; textureDesc.Usage = D3D11_USAGE_DYNAMIC; textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; D3D11_SUBRESOURCE_DATA textureData = {}; textureData.pSysMem = ...; // 视频帧数据 pDevice->CreateTexture2D(&textureDesc, &textureData, &pTexture); // 在 D3D11 中创建一个顶点缓冲区并设置顶点坐标和纹理坐标 struct Vertex { float position[3]; float texcoord[2]; }; Vertex vertices[] = { { { (float)posX, (float)posY, 0.0f }, { 0.0f, 0.0f } }, { { (float)(posX + scaledWidth), (float)posY, 0.0f }, { 1.0f, 0.0f } }, { { (float)posX, (float)(posY + scaledHeight), 0.0f }, { 0.0f, 1.0f } }, { { (float)(posX + scaledWidth), (float)(posY + scaledHeight), 0.0f }, { 1.0f, 1.0f } } }; D3D11_BUFFER_DESC vertexBufferDesc = {}; vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT; vertexBufferDesc.ByteWidth = sizeof(vertices); vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; D3D11_SUBRESOURCE_DATA vertexBufferData = {}; vertexBufferData.pSysMem = vertices; ID3D11Buffer* pVertexBuffer = nullptr; pDevice->CreateBuffer(&vertexBufferDesc, &vertexBufferData, &pVertexBuffer); // 在 D3D11 中创建一个着色器并设置纹理采样器 ID3D11VertexShader* pVertexShader = ...; ID3D11PixelShader* pPixelShader = ...; ID3D11InputLayout* pInputLayout = ...; ID3D11SamplerState* pSamplerState = ...; // 在 D3D11 中绘制顶点缓冲区中的数据 UINT stride = sizeof(Vertex); UINT offset = 0; pContext->IASetVertexBuffers(0, 1, &pVertexBuffer, &stride, &offset); pContext->IASetInputLayout(pInputLayout); pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); pContext->VSSetShader(pVertexShader, nullptr, 0); pContext->PSSetShader(pPixelShader, nullptr, 0); pContext->PSSetShaderResources(0, 1, &pTextureSRV); pContext->PSSetSamplers(0, 1, &pSamplerState); pContext->Draw(4, 0); ``` 注意,上述代码中的变量和函数需要根据具体情况进行调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值