Ejemplo n.º 1
0
		public ToeGraphicsContext(IResourceManager resourceManager)
		{
			this.resourceManager = resourceManager;
			this.debugMaterial = new Material(this.resourceManager)
				{ ColEmissive = Color.FromArgb(255, 255, 255, 255), SpecularPower = 0 };
			GraphicsContext.ShareContexts = true;
			var currentContext = GraphicsContext.CurrentContext;
			if (currentContext != null)
			{
				currentContext.MakeCurrent(null);
			}
			//EventWaitHandle context_ready = new EventWaitHandle(false, EventResetMode.AutoReset);

			//this.resourceContextThread = new Thread(
			//	() =>
			//		{
			this.window = new NativeWindow();
			GraphicsContext.ShareContexts = true;
			this.context = new GraphicsContext(GraphicsMode.Default, this.window.WindowInfo);
			this.context.MakeCurrent(this.window.WindowInfo);

			this.window.ProcessEvents();
			//context_ready.Set();
			//while (this.window.Exists)
			//{
			//    this.window.ProcessEvents();

			//    // Perform your processing here

			//    Thread.Sleep(1); // Limit CPU usage, if necessary
			//}
			//});
			//this.resourceContextThread.IsBackground = true;
			//this.resourceContextThread.Start();

			//context_ready.WaitOne();
		}
Ejemplo n.º 2
0
		private Material ConvertMaterial(IMaterial src)
		{
			var dst = new Material(this.resourceManager);
			dst.Name = src.Name;
			dst.DepthWriteEnable = true;
			if (src.Effect.Ambient != null)
			{
				dst.ColAmbient = src.Effect.Ambient.GetColor();
			}
			switch (src.Effect.CullMode)
			{
				case Utils.Mesh.CullMode.Front:
					dst.CullMode = CullMode.FRONT;
					break;
				case Utils.Mesh.CullMode.Back:
					dst.CullMode = CullMode.BACK;
					break;
				case Utils.Mesh.CullMode.None:
					dst.CullMode = CullMode.NONE;
					break;
				default:
					throw new ArgumentOutOfRangeException();
			}
			var diffuse = src.Effect.Diffuse;
			if (diffuse != null)
			{
				switch (diffuse.Type)
				{
					case ColorSourceType.SolidColor:
					case ColorSourceType.Function:
						dst.ColDiffuse = diffuse.GetColor();
						break;
					case ColorSourceType.Image:
						var emb = ((ImageColorSource)diffuse).Image as EmbeddedImage;
						if (emb != null)
						{
							dst.Texture0.Resource = new Texture
								{ Image = new Image((ushort)emb.Width, (ushort)emb.Height, emb.Pitch, ImageFormat.ABGR_8888, emb.GetRawData()) };
						}
						else
						{
							var fileReference = diffuse.GetImagePath();
							if (!string.IsNullOrEmpty(fileReference))
							{
								if (File.Exists(fileReference))
								{
									dst.Texture0.FileReference = fileReference;
								}
							}
						}
						break;
					default:
						throw new ArgumentOutOfRangeException();
				}
			}
			return dst;
		}
Ejemplo n.º 3
0
		public void SetMaterial(Material m)
		{
			this.material = m;
			if (this.material == null)
			{
				GL.UseProgram(0);
				GL.ActiveTexture(TextureUnit.Texture1);
				GL.Disable(EnableCap.Texture2D);
				GL.ActiveTexture(TextureUnit.Texture0);
				GL.Disable(EnableCap.Texture2D);
			}
			this.ApplyMaterialCommonFixedPipeline();
		}
Ejemplo n.º 4
0
		private MatAnim EnsureAnim(Material material)
		{
			if (material.MatAnim == null)
			{
				material.MatAnim = new MatAnim();
			}
			return material.MatAnim;
		}