//GenericEffect lastEffect = null; #endif // private void RenderMmprList(List<ModelMeshPartRender> list) // { //#if XNA4 && WINDOWS_PHONE && USING_EMULATOR && DEBUG // if (list.Count != 0) // { // GenericEffect effectToUse = list[0].ModelMeshPart.Effect; // FlatRedBall.Content.Model.Helpers.ModelMeshPart modelMeshPart = // list[0].ModelMeshPart; // GraphicsDevice graphicsDevice = Renderer.GraphicsDevice; // // temporary to test things out: // Renderer.GraphicsDevice.RasterizerState = RasterizerState.CullNone; // // TODO: Apply lighting // if (!LightManager.EnableLighting) // { // effectToUse.LightingEnabled = false; // } // // This causes problems // // effectToUse.VertexColorEnabled = true; // /* // // TODO: ApplyColorOperation // effectToUse.EmissiveColor = Vector3.Zero; // effectToUse.DiffuseColor = Vector3.One; // */ // int indexIncrementPerModelMeshPart = modelMeshPart.PrimitiveCount * 3; // for (int i = 0; i < indexIncrementPerModelMeshPart; i++) // { // mPerInstanceIndexBuffer[i] = modelMeshPart.mIndexList[i + modelMeshPart.StartIndex]; // } // // Assumes 1 pass // if( effectToUse.GetCurrentTechnique(true).Passes.Count > 1 ) // { // throw new InvalidOperationException("The new efficient rendering system only supports effects with 1 render pass"); // } // BlendState previousState = FlatRedBallServices.GraphicsDevice.BlendState; // EffectPass effectPass; // if (lastEffect != effectToUse) // { // SpriteManager.Camera.SetDeviceViewAndProjection(effectToUse, false); // effectPass = effectToUse.GetCurrentTechnique( true ).Passes[0]; // effectPass.Apply(); // lastEffect = effectToUse; // } // int reusableIndex = 0; // VertexPositionNormalTexture tempVertex = new VertexPositionNormalTexture(); // Vector3 tempVector = new Vector3(); // Matrix matrix; // int mmprIndex = 0; // VertexPositionNormalTexture[] verticesToCopy = modelMeshPart.CpuVertices; // foreach (ModelMeshPartRender mmpr in list) // { // if (mmpr.PreCalculatedVerts != null) // { // mmpr.PreCalculatedVerts.CopyTo( // mReusableVertexList, reusableIndex); // reusableIndex += mmpr.PreCalculatedVerts.Length; // //for (int i = 0; i < verticesToCopy.Length; i++) // //{ // // mReusableVertexList[reusableIndex] = mmpr.PreCalculatedVerts[i]; // // reusableIndex++; // //} // } // else // { // matrix = mmpr.World; // for (int i = 0; i < verticesToCopy.Length; i++) // { // tempVertex = verticesToCopy[i]; // tempVector.X = tempVertex.Position.X; // tempVector.Y = tempVertex.Position.Y; // tempVector.Z = tempVertex.Position.Z; // MathFunctions.TransformVector(ref tempVector, ref matrix); // tempVertex.Position.X = tempVector.X; // tempVertex.Position.Y = tempVector.Y; // tempVertex.Position.Z = tempVector.Z; // mReusableVertexList[reusableIndex] = tempVertex; // reusableIndex++; // } // } // ushort extraAmountDestination = (ushort)(mmprIndex * indexIncrementPerModelMeshPart); // ushort extraAmountSource = (ushort)(mmprIndex * verticesToCopy.Length); // for (int i = indexIncrementPerModelMeshPart - 1; i > -1; i--) // //for (int i = 0; i < indexIncrementPerModelMeshPart; i++) // { // mReusableIndexList[i + extraAmountDestination] = (ushort)(mPerInstanceIndexBuffer[i] + extraAmountSource); // } // //graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, modelMeshPart.numVertices, modelMeshPart.startIndex, modelMeshPart.primitiveCount); // mmprIndex++; // /* // if (mmpr.RenderOverrides != null) // { // for (int i = 0; i < mmpr.RenderOverrides.Count; i++) // { // mmpr.RenderOverrides[i].Apply(ref modelMeshPart.vertexBuffer); // graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, modelMeshPart.numVertices, modelMeshPart.startIndex, modelMeshPart.primitiveCount); // } // } // */ // } // int numberOfVerts = reusableIndex; // int numberOfIndices = mmprIndex * indexIncrementPerModelMeshPart; // int numberOfPrimitives = numberOfIndices / 3; // mReusableVertexBuffer.SetData<VertexPositionNormalTexture>(mReusableVertexList, 0, numberOfVerts); // mReusableIndexBuffer.SetData<ushort>(mReusableIndexList, 0, numberOfIndices); // FlatRedBallServices.GraphicsDevice.SetVertexBuffer(mReusableVertexBuffer); // FlatRedBallServices.GraphicsDevice.Indices = mReusableIndexBuffer; // graphicsDevice.DrawIndexedPrimitives( // PrimitiveType.TriangleList, 0, 0, numberOfVerts, 0, numberOfPrimitives); // FlatRedBallServices.GraphicsDevice.SetVertexBuffer(null); // FlatRedBallServices.GraphicsDevice.Indices = null; // FlatRedBallServices.GraphicsDevice.BlendState = previousState; // } //#else // throw new NotImplementedException(); //#endif // } private void DrawModelOrAddToSortedDictionary(Camera camera, RenderMode renderMode, PositionedModel model) { if (model.Visible && (camera.CameraModelCullMode == CameraModelCullMode.None || camera.IsModelInView(model))) { if (model.AnimationController == null && model.CustomModel != null && AllowQuickRender) { #if XNA4 Matrix transformationMatrixFlippedAsNeeded = model.TransformationMatrix; foreach (FlatRedBall.Content.Model.Helpers.ModelMesh mesh in model.CustomModel.Meshes) { foreach (FlatRedBall.Content.Model.Helpers.ModelMeshPart meshPart in mesh.MeshParts) { // It's okay if we call this over and over, // it has a bool which it uses internally to // make sure there isn't unnecessary copying of // verts. meshPart.ResetVertexBuffer(); ModelMeshPartRender mmpr = new ModelMeshPartRender(); mmpr.ModelMeshPart = meshPart; if (model.RenderOverrides != null && model.RenderOverrides.ContainsKey(meshPart)) { mmpr.RenderOverrides = model.RenderOverrides[meshPart]; } mmpr.World = transformationMatrixFlippedAsNeeded; if (!model.IsAutomaticallyUpdated) { mmpr.PreCalculatedVerts = model.mPrecalculatedVertices[meshPart]; } if (mSortedModelMeshes.ContainsKey(meshPart)) { mSortedModelMeshes[meshPart].Add(mmpr); } else { List<ModelMeshPartRender> newList = new List<ModelMeshPartRender>(); newList.Add(mmpr); mSortedModelMeshes.Add(meshPart, newList); } } } #endif } else { DrawModel(camera, model, renderMode); } } }