Exemplo n.º 1
0
		public Texture (Stream stream, TextureSettings settings = null, bool leaveOpen = true) {
			byte[] data = PngLoader.Decode(stream, out _size, out _format);
			this.Initialize(data, settings);

			if (!leaveOpen)
				stream.Dispose();
		}
Exemplo n.º 2
0
		public Sprite (Stream stream, TextureSettings settings, Vector4 rect, bool relativeRect, Vector4 color, bool flipV = true) {
			var tex = new Texture(stream, settings);
			_material = new SpriteMaterial(new SpriteShader(), tex);
			
			if (rect == Vector4.Zero)
				rect = new Vector4(0, 0, tex.Size.Width, tex.Size.Height);
			else if (relativeRect) {
				rect.X *= tex.Size.Width;
				rect.Y *= tex.Size.Height;
				rect.Z *= tex.Size.Width;
				rect.W *= tex.Size.Height;
			}
			
			_size = new Vector2(rect.Z - rect.X, rect.W - rect.Y);

			_vbuffer = new VertexBuffer(VertexFormat.PositionColorUV);
			_vbuffer.Data = new [] {
				rect.X, rect.Y, 0f, color.X, color.Y, color.Z, color.W, 0f, flipV ? 1f : 0f,
				rect.Z, rect.Y, 0f, color.X, color.Y, color.Z, color.W, 1f, flipV ? 1f : 0f,
				rect.Z, rect.W, 0f, color.X, color.Y, color.Z, color.W, 1f, flipV ? 0f : 1f,
				rect.X, rect.W, 0f, color.X, color.Y, color.Z, color.W, 0f, flipV ? 0f : 1f
			};
			_vbuffer.Commit ();
			
			_ibuffer = new IndexBuffer();
			_ibuffer.Data = new [] { 0, 1, 2, 2, 3, 0 };
			_ibuffer.Commit ();
			
			_ioffset = 0;
			_icount = 6;
			
			_ownResources = true;
		}
Exemplo n.º 3
0
        public Sprite(Stream stream, TextureSettings settings, Vector4 rect, bool relativeRect, Vector4 color, bool flipV = true)
        {
            var tex = new Texture(stream, settings);

            _material = new SpriteMaterial(new SpriteShader(), tex);

            if (rect == Vector4.Zero)
            {
                rect = new Vector4(0, 0, tex.Size.Width, tex.Size.Height);
            }
            else if (relativeRect)
            {
                rect.X *= tex.Size.Width;
                rect.Y *= tex.Size.Height;
                rect.Z *= tex.Size.Width;
                rect.W *= tex.Size.Height;
            }

            _size = new Vector2(rect.Z - rect.X, rect.W - rect.Y);

            _vbuffer      = new VertexBuffer(VertexFormat.PositionColorUV);
            _vbuffer.Data = new [] {
                rect.X, rect.Y, 0f, color.X, color.Y, color.Z, color.W, 0f, flipV ? 1f : 0f,
                rect.Z, rect.Y, 0f, color.X, color.Y, color.Z, color.W, 1f, flipV ? 1f : 0f,
                rect.Z, rect.W, 0f, color.X, color.Y, color.Z, color.W, 1f, flipV ? 0f : 1f,
                rect.X, rect.W, 0f, color.X, color.Y, color.Z, color.W, 0f, flipV ? 0f : 1f
            };
            _vbuffer.Commit();

            _ibuffer      = new IndexBuffer();
            _ibuffer.Data = new [] { 0, 1, 2, 2, 3, 0 };
            _ibuffer.Commit();

            _ioffset = 0;
            _icount  = 6;

            _ownResources = true;
        }
Exemplo n.º 4
0
		public Texture (string path, TextureSettings settings = null)
			: this(Assets.ResolveStream(path), settings, false)
		{
		}
Exemplo n.º 5
0
		public Texture (Size size, TextureSettings settings = null, PixelFormat format = PixelFormat.Rgba) {
			_size = size;
			_format = format;

			this.Initialize(null, settings);
		}
Exemplo n.º 6
0
 public Texture(int width, int height, TextureSettings settings = null,
                 #if __MOBILE__
                All format = All.Rgba
Exemplo n.º 7
0
 public Sprite(String path, TextureSettings settings = null)
     : this(path, settings, Vector4.Zero, false, Vector4.One)
 {
 }
Exemplo n.º 8
0
 public Sprite(String path, TextureSettings settings, Vector4 rect, bool relativeRect = false)
     : this(path, settings, rect, relativeRect, Vector4.One)
 {
 }
Exemplo n.º 9
0
 public Sprite(String path, TextureSettings settings, Vector4 rect, bool relativeRect, Vector4 color, bool flipV = true)
     : this(Assets.ResolveStream(path), settings, rect, relativeRect, color, flipV)
 {
 }
Exemplo n.º 10
0
		public Sprite (Stream stream, TextureSettings settings, Vector4 rect, bool relativeRect = false)
			: this(stream, settings, rect, relativeRect, Vector4.One)
		{
		}
Exemplo n.º 11
0
 public Sprite(Stream stream, TextureSettings settings, Vector4 rect, bool relativeRect = false)
     : this(stream, settings, rect, relativeRect, Vector4.One)
 {
 }
Exemplo n.º 12
0
		public Sprite (String path, TextureSettings settings = null)
			: this(path, settings, Vector4.Zero, false, Vector4.One)
		{
		}
Exemplo n.º 13
0
		public Sprite (String path, TextureSettings settings, Vector4 rect, bool relativeRect = false)
			: this(path, settings, rect, relativeRect, Vector4.One)
		{
		}
Exemplo n.º 14
0
		public Sprite (String path, TextureSettings settings, Vector4 rect, bool relativeRect, Vector4 color, bool flipV = true)
			: this(Assets.ResolveStream(path), settings, rect, relativeRect, color, flipV)
		{
		}
Exemplo n.º 15
0
		public Sprite (Stream stream, TextureSettings settings = null)
			: this(stream, settings, Vector4.Zero, false, Vector4.One)
		{
		}
Exemplo n.º 16
0
		void Initialize (byte[] buf, TextureSettings settings) {
			_settings = settings ?? new TextureSettings();

			ThreadContext.Current.EnsureGLContext();

			// upload the texture into a texture buffer
			_handle = (uint)GL.GenTexture();

			GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
			GL.ActiveTexture(TextureUnit.Texture0);
			GL.BindTexture(TextureTarget.Texture2D, _handle);
			if (buf == null)
				GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, _size.Width, _size.Height, 0, _format, PixelType.UnsignedByte, IntPtr.Zero);
			else {
				GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, _size.Width, _size.Height,
					0, _format, PixelType.UnsignedByte, buf);
				if (_settings.MinFilter == TextureFilter.Trilinear)
					GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
			}
			GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)_settings.MagFilter);
			GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)_settings.MinFilter);
			GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)_settings.WrapS);
			GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)_settings.WrapT);
			GL.BindTexture(TextureTarget.Texture2D, 0);

			_texelSize = new Vector2(1f / _size.Width, 1f / _size.Height);
			
			Interlocked.Increment(ref _textureCount);
		}
Exemplo n.º 17
0
 public Sprite(Stream stream, TextureSettings settings = null)
     : this(stream, settings, Vector4.Zero, false, Vector4.One)
 {
 }