void DebugRenderer::RenderPrimitivesData(Camera* camera) { ID3D11DeviceContext* context = GraphicsManager::Get()->GetImmidiateContext(); _ASSERT(camera); Matrix view = camera->GetView(); Matrix projection = camera->GetProjection(); effectResource->GetEffect()->SetParam("View", view); effectResource->GetEffect()->SetParam("Projection", projection); for(U32 i = 0; i < NumPrimitives; ++i) { if (!(temporaryInstanceData[i].empty() && permanentInstanceData[i].empty())) { primitivesData[i]->Bind(VertexChannelType::Geometry); effectResource->GetEffect()->Bind("Debug", "Instancing", "Pass0"); } if (!temporaryInstanceData[i].empty()) { instanceBuffer->SetData(temporaryInstanceData[i]); instanceBuffer->Bind(0, VertexData::InstanceChannelSlot); context->DrawIndexedInstanced(primitivesData[i]->GetIndexCount(), temporaryInstanceData[i].size(), 0, 0, 0); } if (!permanentInstanceData[i].empty()) { instanceBuffer->SetData(permanentInstanceData[i]); instanceBuffer->Bind(0, VertexData::InstanceChannelSlot); context->DrawIndexedInstanced(primitivesData[i]->GetIndexCount(), permanentInstanceData[i].size(), 0, 0, 0); } } }
void ComplexTree::draw(ID3D11Device* device, const GameTime& gameTime) { ID3D11DeviceContext* deviceContext; device->GetImmediateContext(&deviceContext); ID3D11Buffer* buffers[2] = { trunkMesh.GetVB11(0, 0), instanceBuffer }; unsigned strides[2] = { trunkMesh.GetVertexStride(0,0), sizeof(Vector3) }; unsigned offsets[2] = {0}; deviceContext->IASetInputLayout(inputLayout); deviceContext->IASetVertexBuffers(0, 2, buffers, strides, offsets); deviceContext->IASetIndexBuffer(trunkMesh.GetIB11(0), trunkMesh.GetIBFormat11(0), 0); Camera& camera = vegetationRendering.getCamera(); const Light& light = vegetationRendering.getLight(); D3D11_VIEWPORT viewport; unsigned numViewports = 1; deviceContext->RSGetViewports(&numViewports, &viewport); evGSCulling->SetBool(vegetationRendering.isGSCullingEnabled()); evShowSavedCulling->SetBool(vegetationRendering.showSaved()); evSavedViewProjection->SetMatrix(vegetationRendering.getSavedViewMatrix() * vegetationRendering.getSavedProjectionMatrix()); evCameraPosition->SetFloatVector(camera.getPosition()); evLightVector->SetFloatVector(Vector3(light.Direction.x, light.Direction.y, light.Direction.z)); evAmbientLight->SetFloatVector(Vector3(light.Ambient.r, light.Ambient.g, light.Ambient.b)); evDiffuseLight->SetFloatVector(Vector3(light.Diffuse.r, light.Diffuse.g, light.Diffuse.b)); evSpecularLight->SetFloatVector(Vector3(light.Specular.r, light.Specular.g, light.Specular.b)); evShininess->SetFloat(TREE_SHININESS); evWorld->SetMatrix(world); evViewProjection->SetMatrix(camera.getView() * camera.getProjection(TREE_NEAR_PLANE, TREE_FAR_PLANE)); for(unsigned i = 0; i < trunkMesh.GetNumSubsets(0); ++i) { SDKMESH_SUBSET* subset = trunkMesh.GetSubset(0, i); //D3D11_PRIMITIVE_TOPOLOGY primitiveType = trunkMesh.GetPrimitiveType11((SDKMESH_PRIMITIVE_TYPE)subset->PrimitiveType); deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST); SDKMESH_MATERIAL* material = trunkMesh.GetMaterial(subset->MaterialID); if(material) evTrunkTexture->SetResource(material->pDiffuseRV11); pass->Apply(0, deviceContext); deviceContext->DrawIndexedInstanced((unsigned)subset->IndexCount, drawInstanceCount, (unsigned)subset->IndexStart, (int)subset->VertexStart,0); //deviceContext->DrawIndexed((unsigned)subset->IndexCount, (unsigned)subset->IndexStart, (int)subset->VertexStart); } /*deviceContext->IASetInputLayout(inputLayoutLOD1); unsigned stride = sizeof(float) * 3; unsigned offset = 0; deviceContext->IASetVertexBuffers(0, 1, &instanceBuffer, &stride, &offset); deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST); evWorld->SetMatrix(Matrix::createScale(Vector3(9))); passLOD1->Apply(0, deviceContext); deviceContext->Draw(INSTANCE_COUNT, 0);*/ deviceContext->Release(); }
/** Draws a single pipeline-state */ void D3D11GraphicsEngineQueued::DrawPipelineState(const PipelineState* state) { if (Engine::GAPI->GetRendererState()->RendererSettings.DisableDrawcalls) return; ID3D11DeviceContext* context = GetDeferredContextByThread(); switch(state->BaseState.DrawCallType) { case PipelineState::DCT_DrawTriangleList: context->Draw(state->BaseState.NumVertices, 0); break; case PipelineState::DCT_DrawIndexed: context->DrawIndexed(state->BaseState.NumIndices, state->BaseState.IndexOffset, 0); break; case PipelineState::DCT_DrawIndexedInstanced: context->DrawIndexedInstanced(state->BaseState.NumIndices, state->BaseState.NumInstances, 0, 0, state->BaseState.InstanceOffset); break; } }
void BufferedPrimitiveRenderer::RenderTempNoAANoDepth() { ID3D11DeviceContext* deviceContext = lowLevelGraphics->GetDeviceContext(); vector<InstanceData> instanceData[NumDebugPrimitiveTypes]; for(U32 i = 0; i < _countof(temporaryPrimitives); ++i) { for(auto j = 0; j < temporaryPrimitives[i].size(); ++j) { const BufferedPrimitive& bufferedPrimitive = temporaryPrimitives[i][j]; if (!bufferedPrimitive.antiAliased && !bufferedPrimitive.depthEnabled) { instanceData[i].push_back(InstanceData(bufferedPrimitive.transform, bufferedPrimitive.color)); } } } for(U32 i = 0; i < _countof(instanceData); ++i) { if (!instanceData[i].empty()) { primitivesData[i]->Bind(deviceContext, VertexChannelType::Geometry); instanceBuffer->SetData(deviceContext, instanceData[i]); instanceBuffer->Bind(deviceContext, 0, Mesh::InstanceChannelSlot); deviceContext->DrawIndexedInstanced(primitivesData[i]->GetIndexCount(), instanceData[i].size(), 0, 0, 0); } } }
void Terrain::draw(ID3D11Device* device, const GameTime& gameTime) { ID3D11DeviceContext* deviceContext; device->GetImmediateContext(&deviceContext); deviceContext->IASetInputLayout(inputLayout); deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); unsigned strides[2] = { sizeof(TerrainVertex), sizeof(TerrainInstance) }; unsigned offsets[2] = { 0, 0 }; ID3D11Buffer* buffers[2] = { vertexBuffer, instanceBuffer }; deviceContext->IASetVertexBuffers(0, 2, buffers, strides, offsets); deviceContext->IASetIndexBuffer(indexBuffer, DXGI_FORMAT_R32_UINT, 0); Camera& camera = vegetationRendering.getCamera(); evWorld->SetMatrix(world); evViewProjection->SetMatrix(camera.getView() * camera.getProjection()); pass->Apply(0, deviceContext); deviceContext->DrawIndexedInstanced(4, INSTANCE_COUNT, 0, 0, 0); //deviceContext->DrawInstanced(4, INSTANCE_COUNT, 0, 0); deviceContext->Release(); }