Пример #1
0
        private int CompileShader(string shaderName, All shaderType)
        {
            string shaderPath = NSBundle.PathForResourceAbsolute(shaderName, ".glsl", "Content");
            string shaderProgram = File.ReadAllText(shaderPath);

            int shader = GL.CreateShader(shaderType);
            int length = shaderProgram.Length;

            GL.ShaderSource(shader, 1, new string[] { shaderProgram }, ref length);
            GL.CompileShader(shader);

            int compileStatus = 0;

            GL.GetShader(shader, All.CompileStatus, ref compileStatus);

            if (compileStatus == (int)All.False)
            {
                StringBuilder sb = new StringBuilder(256);
                length = 0;
                GL.GetShaderInfoLog(shader, sb.Capacity, ref length, sb);
                Console.WriteLine(sb.ToString());
                throw new InvalidOperationException();
            }

            return shader;
        }
Пример #2
0
 public static void Cull(All cullMode)
 {
     if (_cull != cullMode)
     {
         _cull = cullMode;
        // TODO  GL.Enable(_cull);
     }
 }
Пример #3
0
        // throws jjtraveler.VisitFailure
        public virtual void testAll()
        {
            Identity id = new Identity();
            Logger expected = new Logger(id, new IVisitable[]{n3, n2} );

            All  all = new All( logVisitor(id) );

            IVisitable nodeReturned = all.visit(n4);
            Assertion.AssertEquals(expected, logger);
            Assertion.AssertEquals(n4, nodeReturned);
        }
Пример #4
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="name"></param>
		/// <param name="target"></param>
		/// <param name="id"></param>
		/// <param name="width"></param>
		/// <param name="height"></param>
		/// <param name="format"></param>
		/// <param name="face"></param>
		/// <param name="level"></param>
		/// <param name="usage"></param>
		/// <param name="crappyCard"></param>
		/// <param name="writeGamma"></param>
		/// <param name="fsaa"></param>
		public GLESTextureBuffer( string basename, All targetfmt, int id, int width, int height, int format, int face, int level, BufferUsage usage, bool crappyCard, bool writeGamma, int fsaa )
			: base( 0, 0, 0, Media.PixelFormat.Unknown, usage )
		{
			_target = targetfmt;
			_textureId = id;
			_face = face;
			_level = level;
			_softwareMipmap = crappyCard;

			GLESConfig.GlCheckError( this );
			OpenGL.BindTexture( All.Texture2D, _textureId );
			GLESConfig.GlCheckError( this );

			// Get face identifier
			_faceTarget = _target;

			// TODO verify who get this
			Width = width;
			Height = height;
			Depth = 1;

			_glInternalFormat = (All)format;
			Format = GLESPixelUtil.GetClosestAxiomFormat( _glInternalFormat );

			RowPitch = Width;
			SlicePitch = Height * Width;
			sizeInBytes = PixelUtil.GetMemorySize( Width, Height, Depth, Format );

			// Set up a pixel box
			_buffer = new PixelBox( Width, Height, Depth, Format );
			if ( Width == 0 || Height == 0 || Depth == 0 )
			{
				/// We are invalid, do not allocate a buffer
				return;
			}

			// Is this a render target?
			if ( ( (int)Usage & (int)TextureUsage.RenderTarget ) != 0 )
			{
				// Create render target for each slice
				for ( int zoffset = 0; zoffset < Depth; zoffset++ )
				{
					string name = string.Empty;
					name = "rtt/" + this.GetHashCode() + "/" + basename;
					GLESSurfaceDescription target = new GLESSurfaceDescription();
					target.Buffer = this;
					target.ZOffset = zoffset;
					RenderTexture trt = GLESRTTManager.Instance.CreateRenderTexture( name, target, writeGamma, fsaa );
					_sliceTRT.Add( trt );
					Root.Instance.RenderSystem.AttachRenderTarget( _sliceTRT[ zoffset ] );
				}
			}

		}
Пример #5
0
		public EAGLView (CGRect frame, All format, All depth, bool retained) : base (frame)
		{
			CAEAGLLayer eaglLayer = (CAEAGLLayer) Layer;
			eaglLayer.DrawableProperties = new NSDictionary (
				EAGLDrawableProperty.RetainedBacking, true,
				EAGLDrawableProperty.ColorFormat, EAGLColorFormat.RGBA8
			);

			_depthFormat = depth;

			_context = (iPhoneOSGraphicsContext) ((IGraphicsContextInternal) GraphicsContext.CurrentContext).Implementation;
			CreateSurface ();
		}
Пример #6
0
		public EAGLView (RectangleF frame, All format, All depth, bool retained) : base (frame)
		{
			CAEAGLLayer eaglLayer = (CAEAGLLayer) Layer;
			eaglLayer.DrawableProperties = NSDictionary.FromObjectsAndKeys (
				new NSObject [] {NSNumber.FromBoolean (true),           EAGLColorFormat.RGBA8},
				new NSObject [] {EAGLDrawableProperty.RetainedBacking,  EAGLDrawableProperty.ColorFormat}
			);
			_format = format;
			_depthFormat = depth;

			_context = (iPhoneOSGraphicsContext) ((IGraphicsContextInternal) GraphicsContext.CurrentContext).Implementation;
			CreateSurface ();
		}
Пример #7
0
 public virtual void testAll()
 {
     Identity id = new Identity();
     All all = new All(logVisitor(id));
     Logger expected = new Logger(id, new IVisitable[] { n1, n2 });
     try
     {
         IVisitable nodeReturned = all.visit(n0);
         Assertion.AssertEquals(expected, logger);
         Assertion.AssertEquals(n0, nodeReturned);
     }
     catch (VisitFailure)
     {
         Assertion.Fail("VisitFailure should not occur!");
     }
 }
Пример #8
0
 public virtual void testOnceTopDownIsLeaf()
 {
     IVisitor isLeaf = new All(new Fail());
     OnceTopDown onceTopDown = new OnceTopDown(logVisitor(isLeaf));
     Logger expected = new Logger(isLeaf, new IVisitable[]{n0,n1,n11});
     try
     {
         IVisitable nodeReturned = onceTopDown.visit(n0);
         Assertion.AssertEquals("visit trace",expected, logger);
         Assertion.AssertEquals("return value",n0, nodeReturned);
     }
     catch (VisitFailure)
     {
         Assertion.Fail("VisitFailure should not occur!");
     }
 }
Пример #9
0
		/// <summary>
		/// </summary>
		/// <param name="format"> </param>
		/// <param name="width"> </param>
		/// <param name="height"> </param>
		/// <param name="numSamples"> </param>
		public GLESRenderBuffer( All format, int width, int height, int numSamples )
			: base( width, height, 1, GLESPixelUtil.GetClosestAxiomFormat( format ), BufferUsage.WriteOnly )
		{
			_glInternalFormat = format;
			/// Generate renderbuffer
			OpenGLOES.GenRenderbuffers( 1, ref this._renderbufferID );
			GLESConfig.GlCheckError( this );
			/// Bind it to FBO
			OpenGLOES.BindRenderbuffer( All.RenderbufferOes, this._renderbufferID );
			GLESConfig.GlCheckError( this );

			/// Allocate storage for depth buffer
			if ( numSamples <= 0 )
			{
				OpenGLOES.RenderbufferStorage( All.RenderbufferOes, format, width, height );
				GLESConfig.GlCheckError( this );
			}
		}
Пример #10
0
        public void InitWithBitmap(Bitmap image, All filter)
        {
            //TODO:  Android.Opengl.GLUtils.GetInternalFormat()

            _format = SurfaceFormat.Color;
            if(image.HasAlpha)
                _format = SurfaceFormat.Color;

            GL.GenTextures(1, ref _name);
            GL.BindTexture(All.Texture2D, _name);
            GL.TexParameter(All.Texture2D, All.TextureMinFilter, (int)filter);
            GL.TexParameter(All.Texture2D, All.TextureMagFilter, (int)filter);

            Android.Opengl.GLUtils.TexImage2D((int)All.Texture2D, 0, image, 0);

            _size = new Size(image.Width, image.Height);
            _width = image.Width;
            _height = image.Height;
            
            _maxS = _size.Width / (float)_width;
            _maxT = _size.Height / (float)_height;
        }
Пример #11
0
        int LoadShader(All type, string source)
        {
            int shader = GL.CreateShader (type);
            if (shader == 0)
                throw new InvalidOperationException ("Unable to create shader");

            int length = 0;
            GL.ShaderSource (shader, 1, new string [] {source}, (int[])null);
            GL.CompileShader (shader);

            int compiled = 0;
            GL.GetShader (shader, All.CompileStatus, ref compiled);
            if (compiled == 0) {
                length = 0;
                GL.GetShader (shader, All.InfoLogLength, ref length);
                if (length > 0) {
                    var log = new StringBuilder (length);
                    GL.GetShaderInfoLog (shader, length, ref length, log);
                    Log.Debug ("GL2", "Couldn't compile shader: " + log.ToString ());
                }

                GL.DeleteShader (shader);
                throw new InvalidOperationException ("Unable to compile shader of type : " + type.ToString ());
            }

            return shader;
        }
Пример #12
0
		public ESImage(NSImage image, All filter)
		{			
			// By default set the scale to 1.0f
			texture = new ESTexture2D(image,filter);
			Initialize(1.0f/*TODO image.CurrentScale*/);
		}
Пример #13
0
 public ESImage(Bitmap image, All filter)
 {
     // By default set the scale to 1.0f
     texture = new ESTexture2D(image, filter);
     Initialize(1.0f);
 }
Пример #14
0
 public static T Find(UInt32 userdata)
 {
     return(All.FirstOrDefault(i => i.userdata == userdata));
 }
Пример #15
0
 public IList <Part> WithName(string name)
 {
     return(All.Where(part => part.Name == name).ToList());
 }
Пример #16
0
 public ESTexture2D(CGImage cgImage, All filter)
 {
     InitWithCGImage (cgImage, filter);
 }
Пример #17
0
 public CheckBox CheckBox(Regex elementId)
 {
     return(All.CheckBox(elementId));
 }
Пример #18
0
 public Element Element(Predicate <Element> predicate)
 {
     return(All.Element(predicate));
 }
Пример #19
0
 public Element Element(Constraint findBy)
 {
     return(All.Element(findBy));
 }
Пример #20
0
 public Element Element(Regex elementId)
 {
     return(All.Element(elementId));
 }
Пример #21
0
 public Element Element(string elementId)
 {
     return(All.Element(elementId));
 }
Пример #22
0
 public CheckBox CheckBox(Constraint findBy)
 {
     return(All.CheckBox(findBy));
 }
Пример #23
0
 public CheckBox CheckBox(Predicate <CheckBox> predicate)
 {
     return(All.CheckBox(predicate));
 }
Пример #24
0
        public Analyze Analyze(string host, Publish publish, StartNew startNew, FromCache fromCache, int? maxHours, All all, IgnoreMismatch ignoreMismatch)
        {
            var analyzeModel = new Analyze();

            // Checking host is valid before continuing
            if (!_urlValidation.IsValid(host))
            {
                analyzeModel.HasErrorOccurred = true;
                analyzeModel.Errors.Add(new Error { message = "Host does not pass preflight validation. No Api call has been made." });
                return analyzeModel;
            }

            // Building request model
            var requestModel = _requestModelFactory.NewAnalyzeRequestModel(ApiUrl, "analyze", host, publish.ToString().ToLower(), startNew.ToString().ToLower(),
                fromCache.ToString().ToLower(), maxHours, all.ToString().ToLower(), ignoreMismatch.ToString().ToLower());

            try
            {
                var webResponse = _apiProvider.MakeGetRequest(requestModel);
                analyzeModel = _responsePopulation.AnalyzeModel(webResponse, analyzeModel);
            }
            catch (Exception ex)
            {
                analyzeModel.HasErrorOccurred = true;
                analyzeModel.Errors.Add(new Error { message = ex.ToString() });
            }

            // Checking if errors have occoured either from ethier api or wrapper
            if (analyzeModel.Errors.Count != 0 && !analyzeModel.HasErrorOccurred) { analyzeModel.HasErrorOccurred = true; }

            return analyzeModel;
        }
Пример #25
0
		/// <summary>
		/// </summary>
		/// <param name="attachment"> </param>
		/// <param name="zOffset"> </param>
		public override void BindToFramebuffer( All attachment, int zOffset )
		{
			Utilities.Contract.Requires( zOffset < Depth );
			OpenGLOES.FramebufferRenderbuffer( All.FramebufferOes, attachment, All.RenderbufferOes, this._renderbufferID );
			GLESConfig.GlCheckError( this );
		}
Пример #26
0
 public Element ElementWithTag(string tagName, Constraint findBy, params string[] inputTypes)
 {
     return(All.ElementWithTag(tagName, findBy, inputTypes));
 }
Пример #27
0
 public ESTexture2D(IntPtr data, SurfaceFormat pixelFormat, int width, int height, Size size, All filter)
 {
     InitWithData (data, pixelFormat, width, height, size, filter);
 }
Пример #28
0
 public ElementCollection ElementsWithTag(string tagName, params string[] inputTypes)
 {
     return(All.ElementsWithTag(tagName, inputTypes));
 }
Пример #29
0
 public static Player Find(System.Predicate <Player> predicate)
 {
     return(All.Find(predicate));
 }
Пример #30
0
 public FileUpload FileUpload(string elementId)
 {
     return(All.FileUpload(elementId));
 }
Пример #31
0
 public static Player Find(string name)
 {
     return(All.Find(x => x.Name == name));
 }
Пример #32
0
 public FileUpload FileUpload(Regex elementId)
 {
     return(All.FileUpload(elementId));
 }
Пример #33
0
 public ESImage(Bitmap image, float imageScale, All filter)
 {
     texture = new ESTexture2D(image, filter);
     Initialize(imageScale);
 }
Пример #34
0
 public FileUpload FileUpload(Constraint findBy)
 {
     return(All.FileUpload(findBy));
 }
Пример #35
0
 public static List <Player> FindAll(System.Predicate <Player> predicate)
 {
     return(All.FindAll(predicate));
 }
Пример #36
0
 public ESImage(Bitmap image, All filter)
 {
     // By default set the scale to 1.0f
     texture = new ESTexture2D(image, filter);
     Initialize(1.0f);
 }
Пример #37
0
 public ESTexture2D(Bitmap image, All filter)
 {
     InitWithBitmap(image, filter);
 }
Пример #38
0
        private void SetupTexture(IntPtr data, All filter)
        {
            GL.GenTextures(1, ref name);
            GL.BindTexture(All.Texture2D, name);
            GL.TexParameter(All.Texture2D, All.TextureMinFilter, (int)filter);
            GL.TexParameter(All.Texture2D, All.TextureMagFilter, (int)filter);

            GL.TexImage2D(All.Texture2D, 0, (int)All.Rgba, (int)potWidth, (int)potHeight, 0, All.Rgba, All.UnsignedByte, data);
        }
Пример #39
0
        public Analyze AutomaticAnalyze(string host, Publish publish, StartNew startNew, FromCache fromCache, int? maxHours, All all, IgnoreMismatch ignoreMismatch,
			int maxWaitInterval, int sleepInterval)
        {
            var startTime = DateTime.UtcNow;
            var sleepIntervalMilliseconds = sleepInterval * 1000;
            var apiPassCount = 1;
            var analyzeModel = Analyze(host, publish, startNew, fromCache, maxHours, all, ignoreMismatch);

            // Ignoring cache settings after first request to prevent loop
            startNew = StartNew.Ignore;

            // Shouldn't have to check status header as HasErrorOccurred should be enough
            while (analyzeModel.HasErrorOccurred == false && analyzeModel.status != "READY" && (DateTime.UtcNow - startTime).TotalSeconds < maxWaitInterval)
            {
                Thread.Sleep(sleepIntervalMilliseconds);
                apiPassCount++;
                analyzeModel = Analyze(host, publish, startNew, fromCache, null, all, ignoreMismatch);
            }

            analyzeModel.Wrapper.ApiPassCount = apiPassCount;

            return analyzeModel;
        }
Пример #40
0
        public void InitWithData(IntPtr data, SurfaceFormat pixelFormat, int width, int height, Size size, All filter)
        {
            GL.GenTextures(1,ref _name);
            GL.BindTexture(All.Texture2D, _name);
            GL.TexParameter(All.Texture2D, All.TextureMinFilter, (int) filter);
            GL.TexParameter(All.Texture2D, All.TextureMagFilter, (int) filter);

            int sz = 0;

            switch(pixelFormat) {
                case SurfaceFormat.Color /*kTexture2DPixelFormat_RGBA8888*/:
                case SurfaceFormat.Dxt1:
                case SurfaceFormat.Dxt3:
                    sz = 4;
                    GL.TexImage2D(All.Texture2D, 0, (int) All.Rgba, (int) width, (int) height, 0, All.Rgba, All.UnsignedByte, data);
                    break;
                case SurfaceFormat.Bgra4444 /*kTexture2DPixelFormat_RGBA4444*/:
                    sz = 2;
                    GL.TexImage2D(All.Texture2D, 0, (int) All.Rgba, (int) width, (int) height, 0, All.Rgba, All.UnsignedShort4444, data);
                    break;
                case SurfaceFormat.Bgra5551 /*kTexture2DPixelFormat_RGB5A1*/:
                    sz = 2;
                    GL.TexImage2D(All.Texture2D, 0, (int) All.Rgba, (int) width, (int) height, 0, All.Rgba, All.UnsignedShort5551, data);
                    break;
                case SurfaceFormat.Alpha8 /*kTexture2DPixelFormat_A8*/:
                    sz = 1;
                    GL.TexImage2D(All.Texture2D, 0, (int) All.Alpha, (int) width, (int) height, 0, All.Alpha, All.UnsignedByte, data);
                    break;
                default:
                    throw new NotSupportedException("Texture format");;
            }

            _size = size;
            _width = width;
            _height = height;
            _format = pixelFormat;
            _maxS = size.Width / (float)width;
            _maxT = size.Height / (float)height;
        }
Пример #41
0
 /// <summary>
 /// Read kalder blot LINQ-metoden Find på den collection
 /// som All returnerer, og giver kriteriet for udvælgelse
 /// af det rette objekt med.
 /// </summary>
 /// <param name="id">Id for det objekt vi gerne vi læse</param>
 /// <returns>Objektet som matcher det givne id (eller null)</returns>
 public override T Read(int id)
 {
     return(All.Find(obj => (obj.GetId() == id)));
 }
Пример #42
0
        public void InitWithData(IntPtr data, SurfaceFormat pixelFormat, int width, int height, Size size, All filter)
        {
            GL.GenTextures (1, out _name);
            GL.BindTexture (TextureTarget.Texture2D, _name);
            GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)filter);
            GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)filter);

            int sz = 0;

            switch (pixelFormat) {
            case SurfaceFormat.Color /*kTexture2DPixelFormat_RGBA8888*/:
            case SurfaceFormat.Dxt1:
            case SurfaceFormat.Dxt3:
                sz = 4;
                GL.TexImage2D (TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)width, (int)height, 0, MonoMac.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, data);
                break;
            case SurfaceFormat.Bgra4444 /*kTexture2DPixelFormat_RGBA4444*/:
                sz = 2;
                GL.TexImage2D (TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)width, (int)height, 0, MonoMac.OpenGL.PixelFormat.Rgba, PixelType.UnsignedShort4444, data);
                break;
            case SurfaceFormat.Bgra5551 /*kTexture2DPixelFormat_RGB5A1*/:
                sz = 2;
                GL.TexImage2D (TextureTarget.Texture2D, 0,  PixelInternalFormat.Rgba, (int)width, (int)height, 0, MonoMac.OpenGL.PixelFormat.Rgba, PixelType.UnsignedShort5551, data);
                break;
            case SurfaceFormat.Alpha8 /*kTexture2DPixelFormat_A8*/:
                sz = 1;
                GL.TexImage2D (TextureTarget.Texture2D, 0, PixelInternalFormat.Alpha, (int)width, (int)height, 0, MonoMac.OpenGL.PixelFormat.Alpha, PixelType.UnsignedByte, data);
                break;
            default:
                throw new NotSupportedException ("Texture format");
                ;
            }

            _size = size;
            _width = width;
            _height = height;
            _format = pixelFormat;
            _maxS = size.Width / (float)width;
            _maxT = size.Height / (float)height;

            _pixelData = data;
            //IntPtr pData = texture.texture.PixelData;
            //			int size3 = (_width * _height) * 4;
            //			byte[] _pixelInfo = new byte[size3];
            //
            //			Marshal.Copy(data, _pixelInfo, 0, size3);
            //_pixelInfo = data;
        }
Пример #43
0
 public FileUpload FileUpload(Predicate <FileUpload> predicate)
 {
     return(All.FileUpload(predicate));
 }
Пример #44
0
 public CheckBox CheckBox(string elementId)
 {
     return(All.CheckBox(elementId));
 }
Пример #45
0
 public BlendFunc(All src, All dst)
     : this()
 {
     Src = src;
     Dst = dst;
 }
Пример #46
0
 public Form Form(string elementId)
 {
     return(All.Form(elementId));
 }
Пример #47
0
 public ESImage(Bitmap image, float imageScale, All filter)
 {
     texture = new ESTexture2D(image, filter);
     Initialize(imageScale);
 }
Пример #48
0
 public Form Form(Regex elementId)
 {
     return(All.Form(elementId));
 }
Пример #49
0
        public ESTexture2D(UIImage uiImage, All filter)
        {
            CGImage image = uiImage.CGImage;
            if(uiImage == null)
                throw new ArgumentNullException("uiImage");

            // TODO: could use this to implement lower-bandwidth textures
            //bool hasAlpha = (image.AlphaInfo == CGImageAlphaInfo.First || image.AlphaInfo == CGImageAlphaInfo.Last
            //		|| image.AlphaInfo == CGImageAlphaInfo.PremultipliedFirst || image.AlphaInfo == CGImageAlphaInfo.PremultipliedLast);

            // Image dimentions:
            logicalSize = new Point((int)uiImage.Size.Width, (int)uiImage.Size.Height);

            pixelWidth = uiImage.CGImage.Width;
            pixelHeight = uiImage.CGImage.Height;

            // Round up the target texture width and height to powers of two:
            potWidth = pixelWidth;
            potHeight = pixelHeight;
            if(( potWidth & ( potWidth-1)) != 0) { int w = 1; while(w <  potWidth) { w *= 2; }  potWidth = w; }
            if((potHeight & (potHeight-1)) != 0) { int h = 1; while(h < potHeight) { h *= 2; } potHeight = h; }

            // Scale down textures that are too large...
            CGAffineTransform transform = CGAffineTransform.MakeIdentity();
            while((potWidth > 1024) || (potHeight > 1024))
            {
                potWidth /= 2;    // Note: no precision loss - it's a power of two
                potHeight /= 2;
                pixelWidth /= 2;  // Note: precision loss - assume possibility of dropping a pixel at each step is ok
                pixelHeight /= 2;
                transform.Multiply(CGAffineTransform.MakeScale(0.5f, 0.5f));
            }

            RecalculateRatio();

            lock(textureLoadBufferLockObject)
            {
                CreateTextureLoadBuffer();

                unsafe
                {
                    fixed(byte* data = textureLoadBuffer)
                    {
                        var colorSpace = CGColorSpace.CreateDeviceRGB();
                        var context = new CGBitmapContext(new IntPtr(data), potWidth, potHeight,
                                8, 4 * potWidth, colorSpace, CGImageAlphaInfo.PremultipliedLast);

                        context.ClearRect(new RectangleF(0, 0, potWidth, potHeight));
                        context.TranslateCTM(0, potHeight - pixelHeight); // TODO: this does not play nice with the precision-loss above (keeping half-pixel to the edge)

                        if(!transform.IsIdentity)
                            context.ConcatCTM(transform);

                        context.DrawImage(new RectangleF(0, 0, image.Width, image.Height), image);
                        SetupTexture(new IntPtr(data), filter);

                        context.Dispose();
                        colorSpace.Dispose();
                    }
                }
            }
        }
Пример #50
0
 public Form Form(Constraint findBy)
 {
     return(All.Form(findBy));
 }
Пример #51
0
 public ESTexture2D(UIImage uiImage, All filter)
 {
     InitWithCGImage(uiImage.CGImage,filter);
 }
Пример #52
0
 public Form Form(Predicate <Form> predicate)
 {
     return(All.Form(predicate));
 }
Пример #53
0
        private void InitWithCGImage(CGImage image, All filter)
        {
            int	width, height, i;
            CGContext context = null;
            IntPtr data;
            CGColorSpace colorSpace;
            IntPtr tempData;
            bool hasAlpha;
            CGImageAlphaInfo info;
            CGAffineTransform transform;
            Size imageSize;
            SurfaceFormat pixelFormat;
            //bool sizeToFit = false;

            if (image == null) {
                throw new ArgumentException (" NSImage is invalid! " );
            }

            info = image.AlphaInfo;
            hasAlpha = ((info == CGImageAlphaInfo.PremultipliedLast) || (info == CGImageAlphaInfo.PremultipliedFirst) || (info == CGImageAlphaInfo.Last) || (info == CGImageAlphaInfo.First) ? true : false);

            if (image.ColorSpace != null) {
                if (hasAlpha) {
                    pixelFormat = SurfaceFormat.Color;
                } else {
                    pixelFormat = SurfaceFormat.Color;
                }
            } else {
                pixelFormat = SurfaceFormat.Alpha8;
            }

            imageSize = new Size (image.Width,image.Height);
            transform = CGAffineTransform.MakeIdentity ();
            width = imageSize.Width;

            // Take out the width and height adjustments for power of 2
            //  If not then GetData and SetData is messed up.

            // The Mac opengl version supports non power of 2 textures
            // so we do not have to make them so
            //			if ((width != 1) && ((width & (width - 1)) != 0)) {
            //				i = 1;
            //				while ((sizeToFit ? 2 * i : i) < width)
            //					i *= 2;
            //				width = i;
            //			}

            height = imageSize.Height;

            // The Mac opengl version supports non power of 2 textures
            // so we do not have to make them so
            //			if ((height != 1) && ((height & (height - 1)) != 0)) {
            //				i = 1;
            //				while ((sizeToFit ? 2 * i : i) < height)
            //					i *= 2;
            //				height = i;
            //			}
            // TODO: kMaxTextureSize = 1024
            //			while ((width > 1024) || (height > 1024)) {
            //				width /= 2;
            //				height /= 2;
            //				transform = CGAffineTransform.MakeScale (0.5f, 0.5f);
            //				imageSize.Width /= 2;
            //				imageSize.Height /= 2;
            //			}

            float size = Math.Max(width,height);
            if(size > 1024)
            {
                float ratio = 1024 / size;
                width = (int)(width * ratio);
                height = (int)(height * ratio);
                transform = CGAffineTransform.MakeScale(ratio, ratio);
                imageSize.Width = (int)(imageSize.Width * ratio);
                imageSize.Height = (int)(imageSize.Height * ratio);;
            }

            switch (pixelFormat) {
            case SurfaceFormat.Color:
                colorSpace = CGColorSpace.CreateDeviceRGB ();
                data = Marshal.AllocHGlobal (height * width * 4);
                context = new CGBitmapContext (data, width, height, 8, 4 * width, colorSpace,CGImageAlphaInfo.PremultipliedLast);
                colorSpace.Dispose ();
                break;
            case SurfaceFormat.Alpha8:
                data = Marshal.AllocHGlobal (height * width);
                context = new CGBitmapContext (data, width, height, 8, width, null, CGImageAlphaInfo.Only);
                break;
            default:
                throw new NotSupportedException ("Invalid pixel format");
            }

            context.ClearRect (new RectangleF (0,0,width,height));
            context.TranslateCTM (0, height - imageSize.Height);

            if (!transform.IsIdentity) {
                context.ConcatCTM (transform);
            }

            context.DrawImage (new RectangleF (0, 0, image.Width, image.Height), image);

            //Convert "RRRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRRGGGGGGBBBBB"
            /*
            if(pixelFormat == SurfaceFormat.Rgb32) {
                tempData = Marshal.AllocHGlobal(height * width * 2);

                int d32;
                short d16;
                int inPixel32Count=0,outPixel16Count=0;
                for(i = 0; i < width * height; ++i, inPixel32Count+=sizeof(int))
                {
                    d32 = Marshal.ReadInt32(data,inPixel32Count);
                    short R = (short)((((d32 >> 0) & 0xFF) >> 3) << 11);
                    short G = (short)((((d32 >> 8) & 0xFF) >> 2) << 5);
                    short B = (short)((((d32 >> 16) & 0xFF) >> 3) << 0);
                    d16 = (short)  (R | G | B);
                    Marshal.WriteInt16(tempData,outPixel16Count,d16);
                    outPixel16Count += sizeof(short);
                }
                Marshal.FreeHGlobal(data);
                data = tempData;
            }
            */

            InitWithData (data, pixelFormat, width, height, imageSize, filter);

            context.Dispose ();
            Marshal.FreeHGlobal (data);
        }
Пример #54
0
 public Label Label(string elementId)
 {
     return(All.Label(elementId));
 }
Пример #55
0
 public ESTexture2D(NSImage nsImage, All filter)
 {
     // TODO InitWithCGImage(nsImage,filter);
     CGImage image = nsImage.AsCGImage (RectangleF.Empty, null, null);
     InitWithCGImage (image, filter);
 }
Пример #56
0
 public Label Label(Regex elementId)
 {
     return(All.Label(elementId));
 }
Пример #57
0
		public EAGLView (CGRect frame, All format)
			: this (frame, format, 0, false)
		{
		}
Пример #58
0
 public Label Label(Constraint findBy)
 {
     return(All.Label(findBy));
 }
Пример #59
0
        public static object RealTargets(IParameters buildParameters)
        {
            var version = buildParameters.Required<string>("version");

            var git = new GitCheckout {
                Repository = "git://github.com/refractalize/bounce.git",
                Directory = "tmp2",
            };
            var solution = new VisualStudioSolution {
                SolutionPath = "Bounce.sln",
            };
            var frameworkProject = solution.Projects["Bounce.Framework"];

            var downloadsDir = new CleanDirectory {
                Path = "Downloads",
            };

            var frameworkZip = new ZipFile {
                Directory = frameworkProject.WhenBuilt(() => Path.GetDirectoryName(frameworkProject.OutputFile.Value)),
                ZipFileName = downloadsDir.Files[version.WhenBuilt(() => string.Format("Bounce.Framework.{0}.zip", version.Value))],
            };

            var downloads = new All(frameworkZip, new GitTag {Directory = ".", Tag = version.WhenBuilt(() => "v" + version.Value)});

            return new {
                Tests = new NUnitTests {
                    DllPaths = solution.Projects.Select(p => p.OutputFile),
                },
                Downloads = downloads,
            };
        }
Пример #60
0
 public Label Label(Predicate <Label> predicate)
 {
     return(All.Label(predicate));
 }