| 858 | } |
| 859 | |
| 860 | void DXRenderDevice::PhysSetRenderState(RenderState* renderState) |
| 861 | { |
| 862 | DXRenderState* dxRenderState = (DXRenderState*)renderState; |
| 863 | DXShader* dxShader = (DXShader*)renderState->mShader; |
| 864 | |
| 865 | if (renderState->mTopology != mPhysRenderState->mTopology) |
| 866 | { |
| 867 | D3D_PRIMITIVE_TOPOLOGY topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; |
| 868 | if (dxRenderState->mTopology == Topology3D_LineLine) |
| 869 | topology = D3D_PRIMITIVE_TOPOLOGY_LINELIST; |
| 870 | mD3DDeviceContext->IASetPrimitiveTopology(topology); |
| 871 | } |
| 872 | |
| 873 | if ((renderState->mShader != mPhysRenderState->mShader) && (renderState->mShader != NULL)) |
| 874 | { |
| 875 | mD3DDeviceContext->PSSetSamplers(0, 1, renderState->mTexWrap ? &mD3DWrapSamplerState : &mD3DDefaultSamplerState); |
| 876 | mD3DDeviceContext->IASetInputLayout(dxShader->mD3DLayout); |
| 877 | mD3DDeviceContext->VSSetShader(dxShader->mD3DVertexShader, NULL, 0); |
| 878 | mD3DDeviceContext->PSSetShader(dxShader->mD3DPixelShader, NULL, 0); |
| 879 | |
| 880 | if (dxShader->mHas2DPosition) |
| 881 | { |
| 882 | HRESULT result = NULL; |
| 883 | |
| 884 | if (mMatrix2DBuffer == NULL) |
| 885 | { |
| 886 | D3D11_BUFFER_DESC matrixBufferDesc; |
| 887 | matrixBufferDesc.Usage = D3D11_USAGE_DYNAMIC; |
| 888 | matrixBufferDesc.ByteWidth = sizeof(float[4]); |
| 889 | matrixBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; |
| 890 | matrixBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; |
| 891 | matrixBufferDesc.MiscFlags = 0; |
| 892 | matrixBufferDesc.StructureByteStride = 0; |
| 893 | |
| 894 | // Create the constant buffer pointer so we can access the vertex shader constant buffer from within this class. |
| 895 | result = mD3DDevice->CreateBuffer(&matrixBufferDesc, NULL, &mMatrix2DBuffer); |
| 896 | if (FAILED(result)) |
| 897 | { |
| 898 | return; |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | // Lock the constant buffer so it can be written to. |
| 903 | D3D11_MAPPED_SUBRESOURCE mappedResource; |
| 904 | result = mD3DDeviceContext->Map(mMatrix2DBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); |
| 905 | if (FAILED(result)) |
| 906 | { |
| 907 | return; |
| 908 | } |
| 909 | |
| 910 | // Get a pointer to the data in the constant buffer. |
| 911 | float* dataPtr = (float*) mappedResource.pData; |
| 912 | dataPtr[0] = (float) mCurRenderTarget->mWidth; |
| 913 | dataPtr[1] = (float) mCurRenderTarget->mHeight; |
| 914 | dataPtr[2] = 0; |
| 915 | dataPtr[3] = 0; |
| 916 | |
| 917 | // Unlock the constant buffer. |
no outgoing calls
no test coverage detected