/** * Allocate the render data necessary to render this node. * * This method allocates the Triangles data used by the TrianglesCommand * in the rendering pipeline. */ void PolygonNode::generateRenderData() { clearRenderData(); allocTriangles(_polygon); updateColor(); updateTextureCoords(); }
int Layer_D3D::sendDrawCalls() { // Sort draw calls per material (shader/texture) for (std::vector<RenderData>::const_iterator iter = m_renderData.cbegin(); iter != m_renderData.cend(); ++iter) { const RenderData &renderData = *iter; std::vector<MaterialData>::const_iterator matIter = std::find(m_sortedMaterialData.cbegin(), m_sortedMaterialData.cend(), renderData.materialData); if (matIter == m_sortedMaterialData.cend()) { m_sortedMaterialData.push_back(renderData.materialData); } CallData &callData = m_sortedRenderData[renderData.materialData]; if (renderData.materialData.shader) { callData.instances.push_back(renderData.instanceData); } if (renderData.primitiveData.drawer) { callData.primitives.push_back(renderData.primitiveData); } } GPU_BEGIN_EVENT("Layer_D3D::sendDrawCalls"); for (std::vector<MaterialData>::const_iterator iter = m_sortedMaterialData.cbegin(); iter != m_sortedMaterialData.cend(); ++iter) { const MaterialData &material = *iter; CallData &callData = m_sortedRenderData[material]; UINT instanceCount = callData.instances.size(); if (instanceCount > 0) { g_context.m_pDeviceContext->OMSetDepthStencilState(g_context.m_pDepthStencilState, 0); material.shader->bind(); material.shader->updateUniforms(); material.texture->bind(); if (m_pQuadVertexBuffer->getMaxInstanceCount() < instanceCount) { m_pQuadVertexBuffer->resetMaxInstanceCount(instanceCount); } m_pQuadVertexBuffer->copyInstanceFromBuffer(callData.instances.data(), sizeof(InstanceData) * instanceCount); m_pQuadVertexBuffer->copyInstancesToGPU(); m_pQuadVertexBuffer->bind(); g_context.m_pDeviceContext->DrawInstanced(4, instanceCount, 0, 0); } // Primitives should go over image sprites g_context.m_pDeviceContext->OMSetDepthStencilState(g_context.m_pNoDepthTestState, 0); for (std::vector<PrimitiveData>::const_iterator iter = callData.primitives.cbegin(); iter != callData.primitives.cend(); ++iter) { const PrimitiveData &primData = *iter; if (primData.drawer) { primData.drawer->drawAll(primData.offset); } } } GPU_END_EVENT(); int spriteCount = m_renderData.size(); clearRenderData(); return spriteCount; }