void DebugSphere::draw(AglMatrix pWorld, bool pWireframe) { if (pWireframe) m_deviceContext->RSSetState(DX11Application::mWireframeState); SimpleShader* ss = ShaderManager::GetInstance()->GetSimpleShader(); ss->SetMatrixBuffer(pWorld, Camera::GetInstance()->GetViewMatrix(), Camera::GetInstance()->GetProjectionMatrix(), false); m_deviceContext->VSSetShader(ss->GetVertexShader().Data, 0, 0); m_deviceContext->PSSetShader(ss->GetPixelShader().Data, 0, 0); m_deviceContext->HSSetShader(NULL, 0, 0); m_deviceContext->DSSetShader(NULL, 0, 0); m_deviceContext->IASetInputLayout(ss->GetInputLayout()); UINT stride = sizeof(VertexPC); UINT offset = 0; m_deviceContext->IASetVertexBuffers(0, 1, &m_vb, &stride, &offset); m_deviceContext->IASetIndexBuffer(m_ib, DXGI_FORMAT_R32_UINT, 0); m_deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); m_deviceContext->DrawIndexed(m_indexCount, 0, 0); m_deviceContext->RSSetState(DX11Application::mRasterState); }
// Callbacks to draw things in world space, left-hand space, and right-hand // space. void RenderView( size_t eye //< Which eye we are rendering , const osvr::renderkit::RenderInfo& renderInfo //< Info needed to render , ID3D11RenderTargetView* renderTargetView, ID3D11DepthStencilView* depthStencilView) { // Make sure our pointers are filled in correctly. The config file selects // the graphics library to use, and may not match our needs. if (renderInfo.library.D3D11 == nullptr) { std::cerr << "SetupDisplay: No D3D11 GraphicsLibrary, this should not happen" << std::endl; return; } auto context = renderInfo.library.D3D11->context; auto device = renderInfo.library.D3D11->device; float projectionD3D[16]; float viewD3D[16]; XMMATRIX identity = XMMatrixIdentity(); // Set up to render to the textures for this eye context->OMSetRenderTargets(1, &renderTargetView, depthStencilView); // Set the viewport to cover the fraction of our render buffer that // this eye is responsible for. This is always the same width and // height but shifts over by one width for each eye. CD3D11_VIEWPORT viewport( static_cast<float>(eye * renderInfo.viewport.width), 0, static_cast<float>(renderInfo.viewport.width), static_cast<float>(renderInfo.viewport.height)); context->RSSetViewports(1, &viewport); // Make a grey background. Only clear for the first eye, // because clear in DirectX 10 and 11 does not respect the // boundaries of the viewport. FLOAT colorRgba[4] = {0.3f, 0.3f, 0.3f, 1.0f}; if (eye == 0) { context->ClearRenderTargetView(renderTargetView, colorRgba); context->ClearDepthStencilView( depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); } osvr::renderkit::OSVR_PoseState_to_D3D(viewD3D, renderInfo.pose); osvr::renderkit::OSVR_Projection_to_D3D(projectionD3D, renderInfo.projection); XMMATRIX _projectionD3D(projectionD3D), _viewD3D(viewD3D); // draw room simpleShader.use(device, context, _projectionD3D, _viewD3D, identity); roomCube.draw(device, context); }
void DrawRightHand( void* userData //< Passed into AddRenderCallback , osvr::renderkit::GraphicsLibrary library //< Graphics library context to use , osvr::renderkit::RenderBuffer buffers //< Buffers to use , osvr::renderkit::OSVR_ViewportDescription viewport //< Viewport we're rendering into , OSVR_PoseState pose //< OSVR ModelView matrix set by RenderManager , osvr::renderkit::OSVR_ProjectionMatrix projection //< Projection matrix set by RenderManager , OSVR_TimeValue deadline //< When the frame should be sent to the screen ) { // Make sure our pointers are filled in correctly. The config file selects // the graphics library to use, and may not match our needs. if (library.D3D11 == nullptr) { std::cerr << "DrawRightHand: No D3D11 GraphicsLibrary, this should not happen" << std::endl; return; } if (buffers.D3D11 == nullptr) { std::cerr << "DrawRightHand: No D3D11 RenderBuffer, this should not happen" << std::endl; return; } auto context = library.D3D11->context; auto device = library.D3D11->device; auto renderTargetView = buffers.D3D11->colorBufferView; float projectionD3D[16]; float viewD3D[16]; XMMATRIX identity = XMMatrixIdentity(); osvr::renderkit::OSVR_PoseState_to_D3D(viewD3D, pose); osvr::renderkit::OSVR_Projection_to_D3D(projectionD3D, projection); XMMATRIX _projectionD3D(projectionD3D), _viewD3D(viewD3D); // draw right hand simpleShader.use(device, context, _projectionD3D, _viewD3D, identity); handCube.draw(device, context); }
// Callbacks to draw things in world space, left-hand space, and right-hand // space. void RenderView( const osvr::renderkit::RenderInfo& renderInfo //< Info needed to render , ID3D11RenderTargetView* renderTargetView, ID3D11DepthStencilView* depthStencilView) { // Make sure our pointers are filled in correctly. The config file selects // the graphics library to use, and may not match our needs. if (renderInfo.library.D3D11 == nullptr) { std::cerr << "SetupDisplay: No D3D11 GraphicsLibrary, this should not happen" << std::endl; return; } auto context = renderInfo.library.D3D11->context; auto device = renderInfo.library.D3D11->device; float projectionD3D[16]; float viewD3D[16]; XMMATRIX identity = XMMatrixIdentity(); // Set up to render to the textures for this eye context->OMSetRenderTargets(1, &renderTargetView, depthStencilView); // Set up the viewport we're going to draw into. CD3D11_VIEWPORT viewport(static_cast<float>(renderInfo.viewport.left), static_cast<float>(renderInfo.viewport.lower), static_cast<float>(renderInfo.viewport.width), static_cast<float>(renderInfo.viewport.height)); context->RSSetViewports(1, &viewport); // Make a grey background FLOAT colorRgba[4] = {0.3f, 0.3f, 0.3f, 1.0f}; context->ClearRenderTargetView(renderTargetView, colorRgba); context->ClearDepthStencilView( depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); osvr::renderkit::OSVR_PoseState_to_D3D(viewD3D, renderInfo.pose); osvr::renderkit::OSVR_Projection_to_D3D(projectionD3D, renderInfo.projection); XMMATRIX xm_projectionD3D(projectionD3D), xm_viewD3D(viewD3D); // draw room simpleShader.use(device, context, xm_projectionD3D, xm_viewD3D, identity); roomCube.draw(device, context); }
// Callbacks to draw things in world space, left-hand space, and right-hand // space. void RenderView( const OSVR_RenderInfoD3D11& renderInfo //< Info needed to render , ID3D11RenderTargetView* renderTargetView, ID3D11DepthStencilView* depthStencilView) { auto context = renderInfo.library.context; auto device = renderInfo.library.device; float projectionD3D[16]; float viewD3D[16]; XMMATRIX identity = XMMatrixIdentity(); // Set up to render to the textures for this eye context->OMSetRenderTargets(1, &renderTargetView, depthStencilView); // Set up the viewport we're going to draw into. CD3D11_VIEWPORT viewport(static_cast<float>(renderInfo.viewport.left), static_cast<float>(renderInfo.viewport.lower), static_cast<float>(renderInfo.viewport.width), static_cast<float>(renderInfo.viewport.height)); context->RSSetViewports(1, &viewport); // Make a grey background FLOAT colorRgba[4] = {0.3f, 0.3f, 0.3f, 1.0f}; context->ClearRenderTargetView(renderTargetView, colorRgba); context->ClearDepthStencilView( depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); OSVR_PoseState_to_D3D(viewD3D, renderInfo.pose); OSVR_Projection_to_D3D(projectionD3D, renderInfo.projection); XMMATRIX xm_projectionD3D(projectionD3D), xm_viewD3D(viewD3D); // draw room simpleShader.use(device, context, xm_projectionD3D, xm_viewD3D, identity); roomCube.draw(device, context); }
void bindAtlas(SimpleShader &shader) { TEX::bind(atlas.gl.tex); shader.setTexSize(atlas.size); }