void GeometryShaderData::PreDraw(ID3D11Device1& device, ID3D11DeviceContext1& context) { ASSERT(mShader); context.GSSetShader(mShader, nullptr, 0); // Set constant buffers ID3D11Buffer* const cBuffers[] = { mCBuffer.mBuffer }; mCBuffer.CopyDataToBuffer(device); context.GSSetConstantBuffers(0, ARRAYSIZE(cBuffers), cBuffers); }
void VertexShaderData::PostDraw(ID3D11DeviceContext1& context) { context.IASetInputLayout(nullptr); context.VSSetShader(nullptr, nullptr, 0); ID3D11Buffer* vertexBuffers[] = { nullptr }; const unsigned int stride[] = { 0 }; const unsigned int offset[] = { 0 }; context.IASetVertexBuffers(0, 1, vertexBuffers, stride, offset); ID3D11Buffer* const cBuffers[] = { nullptr }; context.VSSetConstantBuffers(0, ARRAYSIZE(cBuffers), cBuffers); }
bool CDXVAContext::CreateSurfaces(D3D11_VIDEO_DECODER_DESC format, unsigned int count, unsigned int alignment, ID3D11VideoDecoderOutputView **surfaces) const { HRESULT hr = S_OK; ID3D11Device* pDevice = g_Windowing.Get3D11Device(); ID3D11DeviceContext1* pContext = g_Windowing.GetImmediateContext(); unsigned bindFlags = D3D11_BIND_DECODER; if (g_Windowing.IsFormatSupport(format.OutputFormat, D3D11_FORMAT_SUPPORT_SHADER_SAMPLE)) bindFlags |= D3D11_BIND_SHADER_RESOURCE; CD3D11_TEXTURE2D_DESC texDesc(format.OutputFormat, FFALIGN(format.SampleWidth, alignment), FFALIGN(format.SampleHeight, alignment), count, 1, bindFlags); ID3D11Texture2D *texture = nullptr; if (FAILED(pDevice->CreateTexture2D(&texDesc, NULL, &texture))) { CLog::LogF(LOGERROR, "failed creating decoder texture array."); return false; } D3D11_VIDEO_DECODER_OUTPUT_VIEW_DESC vdovDesc; vdovDesc.DecodeProfile = format.Guid; vdovDesc.Texture2D.ArraySlice = 0; vdovDesc.ViewDimension = D3D11_VDOV_DIMENSION_TEXTURE2D; float clearColor[] = { 0.0625f, 0.5f, 0.5f, 1.0f }; // black color in YUV size_t i; for (i = 0; i < count; ++i) { vdovDesc.Texture2D.ArraySlice = D3D11CalcSubresource(0, i, texDesc.MipLevels); hr = m_service->CreateVideoDecoderOutputView(texture, &vdovDesc, &surfaces[i]); if (FAILED(hr)) { CLog::LogF(LOGERROR, "failed creating surfaces."); break; } pContext->ClearView(surfaces[i], clearColor, nullptr, 0); } SAFE_RELEASE(texture); if (FAILED(hr)) { for (size_t j = 0; j < i; ++j) SAFE_RELEASE(surfaces[j]); } return SUCCEEDED(hr); }
void VertexShaderData::Draw(ID3D11DeviceContext1& context) { ASSERT(mInputLayout); ASSERT(mShader); ASSERT(mVertexBuffer); ASSERT(mVertexCount > 0); context.Draw(mVertexCount, 0); }
void VertexShaderData::PreDraw(ID3D11Device1& device, ID3D11DeviceContext1& context) { ASSERT(mInputLayout); ASSERT(mShader); ASSERT(mVertexBuffer); ASSERT(mVertexCount > 0); context.IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); context.IASetInputLayout(mInputLayout); context.VSSetShader(mShader, nullptr, 0); const unsigned int stride = sizeof(VertexData); const unsigned int offset = 0; context.IASetVertexBuffers(0, 1, &mVertexBuffer, &stride, &offset); // Set constant buffers ID3D11Buffer* const cBuffers[] = { mCBuffer.mBuffer }; mCBuffer.CopyDataToBuffer(device); context.VSSetConstantBuffers(0, ARRAYSIZE(cBuffers), cBuffers); }
void Drawer::Draw(ID3D11Device1& device, ID3D11DeviceContext1& context, const XMMATRIX& view, const XMMATRIX& proj) { const XMMATRIX world = XMLoadFloat4x4(&mWorld); XMStoreFloat4x4(&mVertexShaderData.WorldViewProjection(), XMMatrixTranspose(world * view * proj)); context.RSSetState(GlobalResources::gInstance->NoCullRS()); mVertexShaderData.PreDraw(device, context); mPixelShaderData.PreDraw(device, context); mVertexShaderData.Draw(context); mVertexShaderData.PostDraw(context); mPixelShaderData.PostDraw(context); }
void GeometryShaderData::PostDraw(ID3D11DeviceContext1& context) { context.GSSetShader(nullptr, nullptr, 0); ID3D11Buffer* const cBuffers[] = { nullptr }; context.GSSetConstantBuffers(0, ARRAYSIZE(cBuffers), cBuffers); }
void PixelShaderData::PostDraw(ID3D11DeviceContext1& context) { context.PSSetShader(nullptr, nullptr, 0); }
void PixelShaderData::PreDraw(ID3D11Device1& /*device*/, ID3D11DeviceContext1& context) { ASSERT(mShader); context.PSSetShader(mShader, nullptr, 0); }
void BBWin8Game::CreateD3dDevice(){ CoreWindow ^window=CoreWindow::GetForCurrentThread(); int width=DipsToPixels( window->Bounds.Width ); int height=DipsToPixels( window->Bounds.Height ); #if WINDOWS_8 switch( DisplayProperties::CurrentOrientation ){ case DisplayOrientations::Portrait: case DisplayOrientations::PortraitFlipped: std::swap( width,height ); break; } #endif UINT creationFlags=D3D11_CREATE_DEVICE_BGRA_SUPPORT; #ifdef _DEBUG creationFlags|=D3D11_CREATE_DEVICE_DEBUG; #endif #if WINDOWS_8 D3D_FEATURE_LEVEL featureLevels[]={ D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_9_3, D3D_FEATURE_LEVEL_9_2, D3D_FEATURE_LEVEL_9_1 }; #elif WINDOWS_PHONE_8 D3D_FEATURE_LEVEL featureLevels[]={ D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_9_3 }; #endif ID3D11Device *device; ID3D11DeviceContext *context; DXASS( D3D11CreateDevice( 0, D3D_DRIVER_TYPE_HARDWARE, 0, creationFlags, featureLevels, ARRAYSIZE(featureLevels), D3D11_SDK_VERSION, &device, &_featureLevel, &context ) ); DXASS( device->QueryInterface( __uuidof( ID3D11Device1 ),(void**)&_d3dDevice ) ); DXASS( context->QueryInterface( __uuidof( ID3D11DeviceContext1 ),(void**)&_d3dContext ) ); device->Release(); context->Release(); //create swap chain if( _swapChain ){ DXASS( _swapChain->ResizeBuffers( 2,width,height,DXGI_FORMAT_B8G8R8A8_UNORM,0 ) ); }else{ #if WINDOWS_8 DXGI_SWAP_CHAIN_DESC1 swapChainDesc={0}; swapChainDesc.Width=width; swapChainDesc.Height=height; swapChainDesc.Format=DXGI_FORMAT_B8G8R8A8_UNORM; swapChainDesc.Stereo=false; swapChainDesc.SampleDesc.Count=1; swapChainDesc.SampleDesc.Quality=0; swapChainDesc.BufferUsage=DXGI_USAGE_RENDER_TARGET_OUTPUT; swapChainDesc.BufferCount=2; swapChainDesc.Scaling=DXGI_SCALING_NONE; swapChainDesc.SwapEffect=DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; swapChainDesc.Flags=0; #elif WINDOWS_PHONE_8 DXGI_SWAP_CHAIN_DESC1 swapChainDesc={0}; swapChainDesc.Width=width; swapChainDesc.Height=height; swapChainDesc.Format=DXGI_FORMAT_B8G8R8A8_UNORM; swapChainDesc.Stereo=false; swapChainDesc.SampleDesc.Count=1; swapChainDesc.SampleDesc.Quality=0; swapChainDesc.BufferUsage=DXGI_USAGE_RENDER_TARGET_OUTPUT; swapChainDesc.BufferCount=1; swapChainDesc.Scaling=DXGI_SCALING_STRETCH; swapChainDesc.SwapEffect=DXGI_SWAP_EFFECT_DISCARD; swapChainDesc.Flags=0; #endif IDXGIDevice1 *dxgiDevice; DXASS( _d3dDevice->QueryInterface( __uuidof( IDXGIDevice1 ),(void**)&dxgiDevice ) ); IDXGIAdapter *dxgiAdapter; DXASS( dxgiDevice->GetAdapter( &dxgiAdapter ) ); IDXGIFactory2 *dxgiFactory; DXASS( dxgiAdapter->GetParent( __uuidof( IDXGIFactory2 ),(void**)&dxgiFactory ) ); DXASS( dxgiFactory->CreateSwapChainForCoreWindow( _d3dDevice,(IUnknown*)window,&swapChainDesc,0,&_swapChain ) ); DXASS( dxgiDevice->SetMaximumFrameLatency( 1 ) ); dxgiFactory->Release(); dxgiAdapter->Release(); dxgiDevice->Release(); } // Create a render target view of the swap chain back buffer. // ID3D11Texture2D *backBuffer; DXASS( _swapChain->GetBuffer( 0,__uuidof( ID3D11Texture2D ),(void**)&backBuffer ) ); DXASS( _d3dDevice->CreateRenderTargetView( backBuffer,0,&_renderTargetView ) ); backBuffer->Release(); /* // Create a depth stencil view // D3D11_TEXTURE2D_DESC dsdesc; ZEROMEM( dsdesc ); dsdesc.Width=width; dsdesc.Height=height; dsdesc.MipLevels=1; dsdesc.ArraySize=1; dsdesc.Format=DXGI_FORMAT_D24_UNORM_S8_UINT; dsdesc.SampleDesc.Count=1; dsdesc.SampleDesc.Quality=0; dsdesc.Usage=D3D11_USAGE_DEFAULT; dsdesc.BindFlags=D3D11_BIND_DEPTH_STENCIL; dsdesc.CpuAccessFlags=0; dsdesc.MiscFlags=0; ID3D11Texture2D *depthStencil; DXASS( _d3dDevice->CreateTexture2D( &dsdesc,0,&depthStencil ) ); DXASS( _d3dDevice->CreateDepthStencilView( depthStencil,0,&_depthStencilView ) ); depthStencil->Release(); */ D3D11_VIEWPORT viewport={ 0,0,width,height,0,1 }; _d3dContext->RSSetViewports( 1,&viewport ); }
void DeviceGraphicsDX11Geometry::drawRange (const DTuint first_tri, const DTuint num) { // If there are VBO's DeviceGraphicsDX11Renderer *renderer = checkedCast<DeviceGraphicsDX11Renderer*>(System::getRenderer()); ID3D11DeviceContext1 *context = renderer->getD3D11Context(); ID3D11Buffer* buffers[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT] = {NULL}; UINT strides[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT] = {0}; UINT offsets[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT] = {0}; // If there are VBO's if (_normal_stream) { buffers[ShaderResource::ATTRIB_NORMAL] = _normal_stream->getBuffer(); if (_normal_stream->getFormat() == DeviceGraphicsDX11DataStream::FMT_3_FLOAT) strides[ShaderResource::ATTRIB_NORMAL] = sizeof(DTfloat) * 3; else if (_normal_stream->getFormat() == DeviceGraphicsDX11DataStream::FMT_2_FLOAT) strides[ShaderResource::ATTRIB_NORMAL] = sizeof(DTfloat) * 2; else if (_normal_stream->getFormat() == DeviceGraphicsDX11DataStream::FMT_4_FLOAT) strides[ShaderResource::ATTRIB_NORMAL] = sizeof(DTfloat) * 4; } if (_color_stream) { buffers[ShaderResource::ATTRIB_COLOR] = _color_stream->getBuffer(); if (_color_stream->getFormat() == DeviceGraphicsDX11DataStream::FMT_4_FLOAT) strides[ShaderResource::ATTRIB_COLOR] = sizeof(DTfloat) * 4; else if (_color_stream->getFormat() == DeviceGraphicsDX11DataStream::FMT_3_FLOAT) strides[ShaderResource::ATTRIB_COLOR] = sizeof(DTfloat) * 3; else if (_color_stream->getFormat() == DeviceGraphicsDX11DataStream::FMT_4_BYTE) strides[ShaderResource::ATTRIB_COLOR] = sizeof(DTubyte) * 4; } if (_weights_strength_stream) { buffers[ShaderResource::ATTRIB_WEIGHTS_STRENGTH] = _weights_strength_stream->getBuffer(); if (_weights_strength_stream->getFormat() == DeviceGraphicsDX11DataStream::FMT_4_FLOAT) strides[ShaderResource::ATTRIB_WEIGHTS_STRENGTH] = sizeof(DTfloat) * 4; } if (_weights_index_stream) { buffers[ShaderResource::ATTRIB_WEIGHTS_INDEX] = _weights_index_stream->getBuffer(); if (_weights_index_stream->getFormat() == DeviceGraphicsDX11DataStream::FMT_4_USHORT) strides[ShaderResource::ATTRIB_WEIGHTS_INDEX] = sizeof(DTushort) * 4; } DTint num_units = min2(4,System::getRenderer()->getNumTextureUnits()); for (DTint unit = 0; unit < num_units; ++unit) { if (_texcoord_stream[unit]) { buffers[ShaderResource::ATTRIB_TEXCOORD0+unit] = _texcoord_stream[unit]->getBuffer(); if (_texcoord_stream[unit]->getFormat() == DeviceGraphicsDX11DataStream::FMT_2_FLOAT) strides[ShaderResource::ATTRIB_TEXCOORD0+unit] = sizeof(DTfloat) * 2; else if (_texcoord_stream[unit]->getFormat() == DeviceGraphicsDX11DataStream::FMT_3_FLOAT) strides[ShaderResource::ATTRIB_TEXCOORD0+unit] = sizeof(DTfloat) * 3; else if (_texcoord_stream[unit]->getFormat() == DeviceGraphicsDX11DataStream::FMT_4_FLOAT) strides[ShaderResource::ATTRIB_TEXCOORD0+unit] = sizeof(DTfloat) * 4; } } if (_vertex_stream) { buffers[ShaderResource::ATTRIB_POSITION] = _vertex_stream->getBuffer(); if (_vertex_stream->getFormat() == DeviceGraphicsDX11DataStream::FMT_3_FLOAT) strides[ShaderResource::ATTRIB_POSITION] = sizeof(DTfloat) * 3; else if (_vertex_stream->getFormat() == DeviceGraphicsDX11DataStream::FMT_2_FLOAT) strides[ShaderResource::ATTRIB_POSITION] = sizeof(DTfloat) * 2; else if (_vertex_stream->getFormat() == DeviceGraphicsDX11DataStream::FMT_4_FLOAT) strides[ShaderResource::ATTRIB_POSITION] = sizeof(DTfloat) * 4; } // Bind the streams context->IASetVertexBuffers(0,ShaderResource::NUM_ATTRIBS,buffers,strides,offsets); // draw if there is an index stream if (_index_stream) { context->IASetIndexBuffer(_index_stream->getBuffer(), DXGI_FORMAT_R16_UINT, 0); context->DrawIndexed(num*3,first_tri*3,0); } }