private void RenderShape(GraphicsDevice graphicsDevice, PrimitiveJob job) { Submesh submesh; Matrix matrix; ShapeMeshCache.GetMesh(_graphicsService, job.Shape, out submesh, out matrix); if (submesh.VertexBuffer == null) return; // This could happen for shapes without a mesh, like an InfiniteShape. Effect.World = (Matrix)matrix * Matrix.CreateScale((Vector3)job.Size.Scale) * job.Pose; Effect.CurrentTechnique.Passes[0].Apply(); var originalRasterizerState = graphicsDevice.RasterizerState; var triangleMeshShape = job.Shape as TriangleMeshShape; if (triangleMeshShape != null && triangleMeshShape.IsTwoSided && originalRasterizerState.CullMode != CullMode.None) { if (AutoRasterizerState) { // For two-sided meshes we disable back-face culling. graphicsDevice.RasterizerState = DrawWireFrame ? GraphicsHelper.RasterizerStateWireFrame : GraphicsHelper.RasterizerStateCullNone; submesh.Draw(); graphicsDevice.RasterizerState = originalRasterizerState; } else { submesh.Draw(); } } else { submesh.Draw(); } }
static void DrawGizmo(Shape src, GizmoType gizmoType) { if (SceneView.currentDrawingSceneView == null) { return; } bool drawWireframe = SceneView.currentDrawingSceneView.cameraMode == SceneView.GetBuiltinCameraMode(DrawCameraMode.Wireframe) || SceneView.currentDrawingSceneView.cameraMode == SceneView.GetBuiltinCameraMode(DrawCameraMode.TexturedWire); Color wireframeColor = Color.white; Color surfaceColor = Color.clear; if (SceneView.currentDrawingSceneView.cameraMode == SceneView.GetBuiltinCameraMode(DrawCameraMode.TexturedWire)) { surfaceColor = new Color(1, 1, 1, 0.5f); } Gizmos.matrix = src.transform.localToWorldMatrix; ShapeMeshCache cache = src.GizmoCache; cache.camera = SceneView.currentDrawingSceneView.camera; cache.RefreshMesh(); /*if (cache.strokeMesh.subMeshCount > 0 && cache.strokeMesh.vertexCount > 0) * { * Gizmos.color = surfaceColor; * Gizmos.DrawMesh(cache.strokeMesh); * * if (drawWireframe) * { * Gizmos.color = wireframeColor; * Gizmos.DrawWireMesh(cache.strokeMesh); * } * } * if (cache.fillMesh.subMeshCount > 0 && cache.fillMesh.vertexCount > 0) * { * Gizmos.color = surfaceColor; * Gizmos.DrawMesh(cache.fillMesh); * * if (drawWireframe) * { * Gizmos.color = wireframeColor; * Gizmos.DrawWireMesh(cache.fillMesh); * } * }*/ if (cache.mesh.subMeshCount > 0 && cache.mesh.vertexCount > 0) { Gizmos.color = surfaceColor; Gizmos.DrawMesh(cache.mesh); if (drawWireframe) { Gizmos.color = wireframeColor; Gizmos.DrawWireMesh(cache.mesh); } } }
public void UpdateSubmesh(IGraphicsService graphicsService, WaterNode node) { if (node.Volume == null) { return; } // We have to update the submesh if it is null or disposed. // Submesh == null --> Update // Submesh != null && VertexBuffer.IsDisposed --> Update // Submesh != null && VertexBuffer == null --> This is the EmptyShape. No updated needed. if (Submesh == null || (Submesh.VertexBuffer != null && Submesh.VertexBuffer.IsDisposed)) { ShapeMeshCache.GetMesh(graphicsService, node.Volume, out Submesh, out SubmeshMatrix); } }
void DrawShape(ShapeMeshCache shapeCache) { if (shapeCache.canvasRenderer != null) { return; } if (shapeCache.fillMaterial != null && shapeCache.mesh.subMeshCount > 0) { Graphics.DrawMesh(shapeCache.mesh, shapeCache.transform.localToWorldMatrix, shapeCache.fillMaterial, gameObject.layer, null, 0); } if (shapeCache.strokeMaterial != null && shapeCache.mesh.subMeshCount > 1) { Graphics.DrawMesh(shapeCache.mesh, shapeCache.transform.localToWorldMatrix, shapeCache.strokeMaterial, gameObject.layer, null, 1); } }
public void UpdateClipSubmesh(IGraphicsService graphicsService, LightNode node) { var clip = node.Clip; Debug.Assert(clip != null); // We have to update the submesh if it is null or disposed. // Submesh == null --> Update // Submesh != null && VertexBuffer.IsDisposed --> Update // Submesh != null && VertexBuffer == null --> This is the EmptyShape. No updated needed. if (ClipSubmesh == null || (ClipSubmesh.VertexBuffer != null && ClipSubmesh.VertexBuffer.IsDisposed)) { ShapeMeshCache.GetMesh(graphicsService, clip.Shape, out ClipSubmesh, out ClipMatrix); // Add transform of Clip. ClipMatrix = clip.Pose * Matrix.CreateScale(clip.Scale) * ClipMatrix; } }
void DrawShapeNow(ShapeMeshCache shapeCache) { if (shapeCache.canvasRenderer != null && Camera.current.cameraType != CameraType.SceneView) { return; } Profiler.BeginSample("Draw FillMaterial"); if (shapeCache.fillMaterial != null) { shapeCache.fillMaterial.SetPass(0); Graphics.DrawMeshNow(shapeCache.mesh, shapeCache.transform.localToWorldMatrix, 0); } Profiler.EndSample(); Profiler.BeginSample("Draw StrokeMaterial"); if (shapeCache.strokeMaterial != null) { shapeCache.strokeMaterial.SetPass(0); Graphics.DrawMeshNow(shapeCache.mesh, shapeCache.transform.localToWorldMatrix, 1); } Profiler.EndSample(); }
public GraphicsManager(GraphicsDevice graphicsDevice, GameWindow gameWindow, ContentManager content) { if (graphicsDevice == null) throw new ArgumentNullException("graphicsDevice"); if (content == null) throw new ArgumentNullException("content"); GraphicsDevice = graphicsDevice; graphicsDevice.DeviceResetting += OnGraphicsDeviceResetting; //graphicsDevice.DeviceReset += OnGraphicsDeviceReset; GraphicsDevice.Disposing += OnGraphicsDeviceDisposing; Content = content; RenderTargetPool = new RenderTargetPool(this); Screens = new GraphicsScreenCollection(); if (gameWindow != null) GameForm = PlatformHelper.GetForm(gameWindow.Handle); PresentationTargets = new PresentationTargetCollection(); PresentationTargets.CollectionChanged += OnPresentationTargetsChanged; EffectInterpreters = new EffectInterpreterCollection { new StockEffectInterpreter(), new DefaultEffectInterpreter(), new SceneEffectInterpreter(), #if !WINDOWS_PHONE && !XBOX360 new TerrainEffectInterpreter(), #endif new Dxsas08EffectInterpreter(), }; EffectBinders = new EffectBinderCollection { new StockEffectBinder(), new DefaultEffectBinder(this), new SceneEffectBinder(), #if !WINDOWS_PHONE && !XBOX360 new TerrainEffectBinder(), #endif }; Data = new Dictionary<string, object>(); Frame = -1; ShapeMeshCache = new ShapeMeshCache(this); }