Beispiel #1
0
		private void Render(VertexBufferRenderData vertexBufferRenderData, VertexSourceType vertexSourceType, int startIndex, int endIndex)
		{
			BeginMode mode;
			switch (vertexSourceType)
			{
				case VertexSourceType.TriangleList:
					mode = BeginMode.Triangles;
					break;
				case VertexSourceType.TriangleStrip:
					mode = BeginMode.TriangleStrip;
					break;
				case VertexSourceType.QuadList:
					mode = BeginMode.Quads;
					break;
				default:
					throw new ArgumentOutOfRangeException();
			}


			OpenTKHelper.Assert();

			int step = 32678;
			for (int i = startIndex; i < endIndex; i += step)
			{
				var count = endIndex - i;
				if (count > step) count = step;
				GL.DrawArrays(mode, startIndex, count);
			}

			OpenTKHelper.Assert();
		}
Beispiel #2
0
		private void RenderMesh(Mesh mesh)
		{
			var vertexBufferRenderData = mesh.ContextData as VertexBufferRenderData;
			if (vertexBufferRenderData == null)
			{
				mesh.ContextData = vertexBufferRenderData = new VertexBufferRenderData(mesh, mesh.Surfaces);
			}
			int index = 0;
			foreach (var surface in mesh.Surfaces)
			{
				var mtl = surface.Material.Resource as Material;
				if (mtl == null && !string.IsNullOrEmpty(surface.Material.NameReference))
				{
					//TODO: fix naming
					mtl =
						this.resourceManager.FindResource(
							surface.Material.Type, Hash.Get(mesh.Name + "/" + surface.Material.NameReference)) as Material;
				}
				this.SetMaterial(mtl);

				var p = this.ApplyMaterialShader(mesh);
				vertexBufferRenderData.Enable(p);
				this.Render(vertexBufferRenderData, surface.VertexSourceType, index, index + surface.Count);
				index += surface.Count;
				vertexBufferRenderData.Disable(p);
			}
		}
Beispiel #3
0
		public void Render(IMesh mesh)
		{
			if (mesh == null)
			{
				return;
			}

			if (!this.frustum.CheckSphere(mesh.BoundingSphereCenter.ToVector(), mesh.BoundingSphereR))
			{
				return;
			}

			var vertexBufferRenderData = mesh.RenderData as VertexBufferRenderData;
			if (vertexBufferRenderData == null)
			{
				mesh.RenderData = vertexBufferRenderData = new VertexBufferRenderData(mesh, mesh.Submeshes);
			}

			IEnumerable<ISubMesh> submeshes;
			if (this.vsdProvider != null && this.vsdProvider.Level == mesh)
			{
				submeshes = this.vsdProvider.GetVisibleSubMeshes();
			}
			else
			{
				submeshes = mesh.Submeshes;
			}
			int index = 0;
			foreach (var surface in submeshes)
			{
				//if (!this.frustum.CheckSphere(surface.BoundingSphereCenter, surface.BoundingSphereR))
				//{
				//    continue;
				//}

				this.SetMaterial(surface.Material);

				var p = this.ApplyMaterialShader(mesh);
				if (p == null)
				{
					return;
				}
				vertexBufferRenderData.Enable(p);

				this.Render(vertexBufferRenderData, surface.VertexSourceType, index, surface.Count + index);
				index += surface.Count;
			}
		}