Example #1
0
void ModelMeshPartPayload::render(RenderArgs* args) const {
    PerformanceTimer perfTimer("ModelMeshPartPayload::render");

    if (!_model->_readyWhenAdded || !_model->_isVisible) {
        return; // bail asap
    }

    gpu::Batch& batch = *(args->_batch);

    ShapeKey key = getShapeKey();
    if (!key.isValid()) {
        return;
    }

    // render the part bounding box
#ifdef DEBUG_BOUNDING_PARTS
    {
        AABox partBounds = getPartBounds(_meshIndex, partIndex);
        bool inView = args->_viewFrustum->boxInFrustum(partBounds) != ViewFrustum::OUTSIDE;
        
        glm::vec4 cubeColor;
        if (isSkinned) {
            cubeColor = glm::vec4(0.0f, 1.0f, 1.0f, 1.0f);
        } else if (inView) {
            cubeColor = glm::vec4(1.0f, 0.0f, 1.0f, 1.0f);
        } else {
            cubeColor = glm::vec4(1.0f, 1.0f, 0.0f, 1.0f);
        }
        
        Transform transform;
        transform.setTranslation(partBounds.calcCenter());
        transform.setScale(partBounds.getDimensions());
        batch.setModelTransform(transform);
        DependencyManager::get<GeometryCache>()->renderWireCube(batch, 1.0f, cubeColor);
    }
#endif //def DEBUG_BOUNDING_PARTS
    
    auto locations =  args->_pipeline->locations;
    assert(locations);

    // Bind the model transform and the skinCLusterMatrices if needed
    _model->updateClusterMatrices(_transform.getTranslation(), _transform.getRotation());
    bindTransform(batch, locations);
    
    //Bind the index buffer and vertex buffer and Blend shapes if needed
    bindMesh(batch);
    
    // apply material properties
    bindMaterial(batch, locations);
        
        
    // TODO: We should be able to do that just in the renderTransparentJob
    if (key.isTranslucent() && locations->lightBufferUnit >= 0) {
        PerformanceTimer perfTimer("DLE->setupTransparent()");
            
        DependencyManager::get<DeferredLightingEffect>()->setupTransparent(args, locations->lightBufferUnit);
    }
    if (args) {
        args->_details._materialSwitches++;
    }
    
    // Draw!
    {
        PerformanceTimer perfTimer("batch.drawIndexed()");
        drawCall(batch);
    }
    
    if (args) {
        const int INDICES_PER_TRIANGLE = 3;
        args->_details._trianglesRendered += _drawPart._numIndices / INDICES_PER_TRIANGLE;
    }
}