internal iPhoneOSGraphicsContext(ContextHandle handle, IWindowInfo window, IGraphicsContext sharedContext, int major, int minor, GraphicsContextFlags flags) { // ignore mode, window iPhoneOSGraphicsContext shared = sharedContext as iPhoneOSGraphicsContext; EAGLRenderingAPI version = 0; if (major == 1 && minor == 1) version = EAGLRenderingAPI.OpenGLES1; else if (major == 2 && minor == 0) version = EAGLRenderingAPI.OpenGLES2; else if (major == 3 && minor == 0) version = EAGLRenderingAPI.OpenGLES3; else throw new ArgumentException (string.Format("Unsupported GLES version {0}.{1}.", major, minor)); if (handle.Handle == IntPtr.Zero) { EAGLContext = shared != null && shared.EAGLContext != null ? new EAGLContext(version, shared.EAGLContext.ShareGroup) : new EAGLContext(version); contextHandle = new ContextHandle(EAGLContext.Handle); } else { EAGLContext = (EAGLContext) Runtime.GetNSObject (handle.Handle); contextHandle = handle; } }
public void ClearCurrentContext() { if (!EAGLContext.SetCurrentContext(null)) { Console.WriteLine("Failed to clear current context!"); } }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. if (View is GLKView) { EAGLContext.SetCurrentContext(((GLKView)View).Context); _videoMesh = new VideoMesh(this); string mediaBundlePath = NSBundle.MainBundle.BundlePath + "/media.bundle"; NSBundle mediaBundle = new NSBundle(mediaBundlePath); _videoMesh.InitMesh(mediaBundle.PathForResource("pikkart_video", "mp4"), mediaBundle.PathForResource("pikkart_keyframe", "png"), 0, false, null); } UITapGestureRecognizer tapGesture = new UITapGestureRecognizer((obj) => { playOrPauseVideo(); }); View.AddGestureRecognizer(tapGesture); string[] dbNames = { "" }; PKTCloudRecognitionInfo info = new PKTCloudRecognitionInfo(dbNames); PKTRecognitionOptions options = new PKTRecognitionOptions(PKTRecognitionStorage.PKTLOCAL, PKTRecognitionMode.PKTRECOGNITION_CONTINUOS_SCAN, info); ApplyCameraGlOrientation(UIApplication.SharedApplication.StatusBarOrientation); StartRecognition(options, this); }
void SetupGL() { EAGLContext.SetCurrentContext(context); LoadShaders(); effect = new GLKBaseEffect(); effect.Light0.Enabled = true; effect.Light0.DiffuseColor = new Vector4(1.0f, 0.4f, 0.4f, 1.0f); GL.Enable(EnableCap.DepthTest); GL.Oes.GenVertexArrays(1, out vertexArray); GL.Oes.BindVertexArray(vertexArray); GL.GenBuffers(1, out vertexBuffer); GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBuffer); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(cubeVertexData.Length * sizeof(float)), cubeVertexData, BufferUsage.StaticDraw); GL.EnableVertexAttribArray((int)GLKVertexAttrib.Position); GL.VertexAttribPointer((int)GLKVertexAttrib.Position, 3, VertexAttribPointerType.Float, false, 24, new IntPtr(0)); GL.EnableVertexAttribArray((int)GLKVertexAttrib.Normal); GL.VertexAttribPointer((int)GLKVertexAttrib.Normal, 3, VertexAttribPointerType.Float, false, 24, new IntPtr(12)); GL.Oes.BindVertexArray(0); }
protected virtual void DestroyFrameBuffer() { AssertValid(); AssertContext(); EAGLContext oldContext = EAGLContext.CurrentContext; if (!GraphicsContext.IsCurrent) { MakeCurrent(); } DeleteBuffers(); if (oldContext != EAGLContext) { EAGLContext.SetCurrentContext(oldContext); } else { EAGLContext.SetCurrentContext(null); } GraphicsContext.Dispose(); GraphicsContext = null; gl = null; }
/// <summary> /// Runs all pending actions. Must be called from the main thread. /// </summary> internal static void Run() { AssertMainThread(); #if IOS lock (BackgroundContext) { // Make the context current on this thread if it is not already if (!Object.ReferenceEquals(EAGLContext.CurrentContext, BackgroundContext)) { EAGLContext.SetCurrentContext(BackgroundContext); } #endif lock (_actionList) { foreach (Action action in _actionList) { action.Invoke(); } _actionList.Clear(); } #if IOS // Must flush the GL calls so the GPU asset is ready for the main context to use it GL.Flush(); GL.CheckError(); } #endif }
public override void ViewDidLoad() { base.ViewDidLoad(); context = new EAGLContext(EAGLRenderingAPI.OpenGLES3); if (context == null) { context = new EAGLContext(EAGLRenderingAPI.OpenGLES2); if (context == null) { throw new Exception("Unable to create OpenGL ES2 Context"); } Window.SetObsoleteMode(); } view = (GLKView)View; view.Context = context; view.DrawableDepthFormat = GLKViewDrawableDepthFormat.Format24; EAGLContext.SetCurrentContext(context); window = new Window(view); GameSetup(window); }
/// <summary> /// Subview のレイアウト時のコールバック /// /// SafeArea 周りのパラメータがこのタイミングで取得出来るようになるので /// ViewDidLoad() で行なっていた処理を移動 /// </summary> public override void ViewWillLayoutSubviews() { DebugLogViewer.WriteLine("ViewWillLayoutSubviews()"); base.ViewWillLayoutSubviews(); #endif m_Context = new EAGLContext(EAGLRenderingAPI.OpenGLES2); if (m_Context == null) { DebugLogViewer.WriteLine("Failed to create ES context"); } var view = (GLKView)View; view.Context = m_Context; view.DrawableColorFormat = GLKViewDrawableColorFormat.RGBA8888; view.DrawableDepthFormat = GLKViewDrawableDepthFormat.Format24; // フレームバッファがバインドされていないので、 // フレームバッファ関連のOpenGL関数を使うにはこの方法で事前にバインドしておく view.BindDrawable(); DebugLogViewer.WriteLine(string.Format("View.Drawable ({0}, {1})", view.DrawableWidth, view.DrawableHeight)); DebugLogViewer.WriteLine(string.Format("view.Bounds {0}", view.Bounds)); SetupGL(); m_Activity = new GLGameTest(); m_Activity.OnSurfaceCreated(view); RegisterTouchEvent(m_Activity); }
public static CIContext FromContext (EAGLContext eaglContext, CIContextOptions options) { if (options == null) return FromContext (eaglContext); return FromContext (eaglContext, options.Dictionary); }
/// <summary> /// Runs all pending actions. Must be called from the UI thread. /// </summary> internal static void Run() { EnsureUIThread(); #if IOS lock (BackgroundContext) { // Make the context current on this thread if it is not already if (!Object.ReferenceEquals(EAGLContext.CurrentContext, BackgroundContext)) { EAGLContext.SetCurrentContext(BackgroundContext); } #endif lock (actions) { foreach (Action action in actions) { action(); } actions.Clear(); } #if IOS // Must flush the GL calls so the GPU asset is ready for the main context to use it GL.Flush(); GraphicsExtensions.CheckGLError(); } #endif }
public override void ViewDidLoad() { base.ViewDidLoad(); #if _SAMPLE context = new EAGLContext(EAGLRenderingAPI.OpenGLES2); #endif #if _ENGINE context = new EAGLContext(EAGLRenderingAPI.OpenGLES3); #endif if (context == null) { Debug.WriteLine("Failed to create ES context"); } var view = (GLKView)View; view.Context = context; view.DrawableDepthFormat = GLKViewDrawableDepthFormat.Format24; #if _ENGINE view.MultipleTouchEnabled = true; int scaling = (int)UIScreen.MainScreen.Scale; if (scaling > 1) { view.ContentScaleFactor = (nfloat)1.5; } #endif SetupGL(); }
// Constructor(s) public GLSignatureView(CGRect frame, NewSignatureViewController root) : base(frame) { nsvc = root; this.EnableSetNeedsDisplay = true; this.BackgroundColor = UIColor.Yellow; // set up OpenGL context this.context = new EAGLContext(EAGLRenderingAPI.OpenGLES2); this.Context = this.context; if (this.context != null) { this.DrawableDepthFormat = GLKViewDrawableDepthFormat.Format24; // Turn on antialiasing this.DrawableMultisample = GLKViewDrawableMultisample.Sample4x; // More OpenGL setup this.SetupGL(); // set up gesture recognizers panner = new UIPanGestureRecognizer(this, new ObjCRuntime.Selector("GLSignatureViewPan:")); panner.MaximumNumberOfTouches = panner.MinimumNumberOfTouches = 1; this.AddGestureRecognizer(panner); tapper = new UITapGestureRecognizer(this, new ObjCRuntime.Selector("GLSignatureViewTap:")); this.AddGestureRecognizer(tapper); } else { throw new Exception("Failed to create OpenGL ES2 context"); } }
public virtual void Render() { if (glContext == null) { PrepareGLContexts(); } EAGLContext.SetCurrentContext(glContext); // create the surface if (renderTarget.Width == 0 || renderTarget.Height == 0) { renderTarget = SKGLDrawable.CreateRenderTarget(); } using (var surface = SKSurface.Create(context, renderTarget)) { // draw on the surface DrawInSurface(surface, renderTarget); SKDelegate?.DrawInSurface(surface, renderTarget); surface.Canvas.Flush(); } // flush the SkiaSharp context to the GL context context.Flush(); // present the GL buffers glContext.PresentRenderBuffer(Gles.GL_RENDERBUFFER); EAGLContext.SetCurrentContext(null); }
public override void DidReceiveMemoryWarning() { EAGLContext.SetCurrentContext(context); Closing(); EAGLContext.SetCurrentContext(null); base.DidReceiveMemoryWarning(); }
protected override void OnElementChanged(ElementChangedEventArgs <OpenGLView> e) { if (e.OldElement != null) { e.OldElement.DisplayRequested -= Display; } if (e.NewElement != null) { var context = new EAGLContext(EAGLRenderingAPI.OpenGLES2); var glkView = new GLKView(RectangleF.Empty) { Context = context, DrawableDepthFormat = GLKViewDrawableDepthFormat.Format24, Delegate = new Delegate(e.NewElement) }; SetNativeControl(glkView); e.NewElement.DisplayRequested += Display; SetupRenderLoop(false); } base.OnElementChanged(e); }
private void CreateFrameBuffer(CAEAGLLayer eaglLayer) { int oldRenderbuffer = 1; gl.GetInteger(All.RenderbufferBindingOes, out oldRenderbuffer); gl.GenRenderbuffers(1, out renderbuffer); gl.BindRenderbuffer(All.RenderbufferOes, renderbuffer); if (!EAGLContext.RenderBufferStorage((uint)All.RenderbufferOes, eaglLayer)) { gl.DeleteRenderbuffers(1, ref renderbuffer); renderbuffer = 0; gl.BindRenderbuffer(All.RenderbufferBindingOes, oldRenderbuffer); throw new InvalidOperationException("Error with EAGLContext.RenderBufferStorage!"); } gl.BindFramebuffer(All.FramebufferOes, framebuffer); gl.FramebufferRenderbuffer(All.FramebufferOes, All.ColorAttachment0Oes, All.RenderbufferOes, renderbuffer); Size newSize = new Size( (int)Math.Round(eaglLayer.Bounds.Size.Width), (int)Math.Round(eaglLayer.Bounds.Size.Height)); Size = newSize; gl.Viewport(0, 0, newSize.Width, newSize.Height); gl.Scissor(0, 0, newSize.Width, newSize.Height); }
public override void ViewDidLoad() { base.ViewDidLoad(); // Code to start the Xamarin Test Cloud Agent #if ENABLE_TEST_CLOUD //Xamarin.Calabash.Start(); #endif context = new EAGLContext(EAGLRenderingAPI.OpenGLES3); if (context == null) { Debug.WriteLine("Failed to create ES context"); } Typography.FontManagement.InstalledTypefaceCollectionExtensions.CustomSystemFontListLoader = LoadFonts; var view = (GLKView)View; view.Context = context; view.DrawableDepthFormat = GLKViewDrawableDepthFormat.Format24; _view_width = (int)view.Frame.Width; _view_height = (int)view.Frame.Height; SetupGL(); }
void SetupGL() { EAGLContext.SetCurrentContext(context); _customApp = new CustomApp(); _max = Math.Max(_view_width * 2, _view_height * 2); _customApp.Setup(_view_width * 2, _view_height * 2); }
private void PrepareGLContexts() { // create GL context glContext = new EAGLContext(EAGLRenderingAPI.OpenGLES2); EAGLContext.SetCurrentContext(glContext); // create render buffer Gles.glGenRenderbuffers(1, ref renderBuffer); Gles.glBindRenderbuffer(Gles.GL_RENDERBUFFER, renderBuffer); glContext.RenderBufferStorage(Gles.GL_RENDERBUFFER, this); // create frame buffer Gles.glGenFramebuffers(1, ref framebuffer); Gles.glBindFramebuffer(Gles.GL_FRAMEBUFFER, framebuffer); Gles.glFramebufferRenderbuffer(Gles.GL_FRAMEBUFFER, Gles.GL_COLOR_ATTACHMENT0, Gles.GL_RENDERBUFFER, renderBuffer); // get the bits for SkiaSharp var glInterface = GRGlInterface.Create(); context = GRContext.CreateGl(glInterface); // finished EAGLContext.SetCurrentContext(null); recreateSurface = true; }
public override void ViewWillLayoutSubviews() { base.ViewWillLayoutSubviews(); EAGLContext context = new EAGLContext(EAGLRenderingAPI.OpenGLES2); GraphicsView.Context = context; GraphicsView.SetNeedsDisplay(); }
/// <summary> /// ICreate an ES 2.0 context /// </summary> /// <param name='context'> /// Context. /// </param> /// <param name='drawable'> /// Drawable. /// </param> public void InitWithContext(EAGLContext context, CAEAGLLayer drawable) { GL.GenFramebuffers(1, out m_defaultFBOName); // Create default framebuffer object. The backing will be allocated for the current layer in resizeFromLayer GL.GenRenderbuffers(1, out m_colorRenderbuffer); GL.BindFramebuffer(FramebufferTarget.Framebuffer, m_defaultFBOName); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, m_colorRenderbuffer); m_context = context; // This call associates the storage for the current render buffer with the EAGLDrawable (our CAEGLLAyer) // allowing us to draw into a buffer that will later be rendered to the screen wherever the layer is //(which correspondes with our) view. m_context.RenderBufferStorage((uint)All.Renderbuffer, drawable); GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferSlot.ColorAttachment0, RenderbufferTarget.Renderbuffer, m_colorRenderbuffer); int backingWidth; int backingHeight; GL.GetRenderbufferParameter(RenderbufferTarget.Renderbuffer, RenderbufferParameterName.RenderbufferWidth, out backingWidth); GL.GetRenderbufferParameter(RenderbufferTarget.Renderbuffer, RenderbufferParameterName.RenderbufferHeight, out backingHeight); GL.GenRenderbuffers(1, out m_depthRenderbuffer); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, m_depthRenderbuffer); GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferInternalFormat.DepthComponent16, backingWidth, backingHeight); GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferSlot.DepthAttachment, RenderbufferTarget.Renderbuffer, m_depthRenderbuffer); var frameBufferError = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer); if(frameBufferError != FramebufferErrorCode.FramebufferComplete) { throw new ApplicationException("Failed to make complete framebuffer object: " + frameBufferError); } InitWithDefaultFBO(m_defaultFBOName); }
public override void MovedToWindow() { base.MovedToWindow(); if (Window == null) { Log.Info("MapView.MovedToWindow: null"); lock (this) { if (_active) { _baseMapView.OnSurfaceDestroyed(); if (EAGLContext.CurrentContext == Context) { EAGLContext.SetCurrentContext(null); } _active = false; _surfaceCreated = false; } } } else { Log.Info("MapView.MovedToWindow: nonnull"); SetNeedsDisplay(); } }
public override void WillMoveToWindow(UIWindow newWindow) { base.WillMoveToWindow(newWindow); if (newWindow == null) { Log.Info("MapView.WillMoveToWindow: null"); } else { Log.Info("MapView.WillMoveToWindow: nonnull"); lock (this) { if (!_active) { InitContext(); if (EAGLContext.CurrentContext == null) { EAGLContext.SetCurrentContext(Context); } _active = true; _surfaceCreated = false; } } } }
void SetupGL() { EAGLContext.SetCurrentContext(context); max = Math.Max(view_width, view_height); customApp = new CustomApp(); customApp.Setup(800, 600); }
internal iPhoneOSGraphicsContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext sharedContext, int major, int minor, GraphicsContextFlags flags) { // ignore mode, window iPhoneOSGraphicsContext shared = sharedContext as iPhoneOSGraphicsContext; EAGLRenderingAPI version = 0; if (major == 1 && minor == 1) { version = EAGLRenderingAPI.OpenGLES1; } else if (major == 2 && minor == 0) { version = EAGLRenderingAPI.OpenGLES2; } else if (major == 3 && minor == 0) { version = EAGLRenderingAPI.OpenGLES3; } else { throw new ArgumentException (string.Format("Unsupported GLES version {0}.{1}.", major, minor)); } EAGLContext = shared != null && shared.EAGLContext != null ? new EAGLContext(version, shared.EAGLContext.ShareGroup) : new EAGLContext(version); Handle = new ContextHandle(EAGLContext.Handle); }
public void SetupGL() { EAGLContext.SetCurrentContext(context); SetupBuffers(); LoadShaders(); GL.UseProgram(Program); // 0 and 1 are the texture IDs of lumaTexture and chromaTexture respectively. GL.Uniform1(uniforms [(int)UniformIndex.Y], 0); GL.Uniform1(uniforms [(int)UniformIndex.UV], 1); GL.Uniform1(uniforms [(int)UniformIndex.RotationAngle], 0); GL.UniformMatrix3(uniforms [(int)UniformIndex.ColorConversionMatrix], 1, false, preferredConversion); if (videoTextureCache != null) { return; } videoTextureCache = CVOpenGLESTextureCache.FromEAGLContext(context); if (videoTextureCache == null) { Console.WriteLine("Error at CVOpenGLESTextureCache.FromEAGLContext"); } }
void DoUpdate() { // set context and bind buffers EAGLContext.SetCurrentContext(_glContext); ThreadContext.Current.GLContext = _glContext.Handle; _alContext.MakeCurrent(); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, _cb); // do user time-step var time = _link.Timestamp; _frame.Time = time; _frame.DeltaTime = _lastTime < 0.0 ? 0f : (float)(time - _lastTime); _lastTime = time; if (_loadFrame > 0) { _frame.DeltaTime = Interval / 60f; _loadFrame--; } if (this.Update != null) { Update(this, _frame); } if (this.Render != null) { Render(this, _frame); } // present output _glContext.PresentRenderBuffer((uint)RenderbufferTarget.Renderbuffer); }
public override void LayoutSubviews() { // ISSUE: reference to a compiler-generated method base.LayoutSubviews(); if (GraphicsContext == null) { return; } var bounds = Bounds; if (Math.Round(bounds.Width) == Size.Width && Math.Round(bounds.Height) == Size.Height) { return; } if (!GraphicsContext.IsCurrent) { MakeCurrent(); } Size = new Size((int)bounds.Width, (int)bounds.Height); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, renderBuffer); if (!EAGLContext.RenderBufferStorage((uint)RenderbufferTarget.Renderbuffer, (CAEAGLLayer)Layer)) { throw new InvalidOperationException("Error with RenderbufferStorage()!"); } GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBuffer); GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, RenderbufferTarget.Renderbuffer, frameBuffer); }
protected virtual void DestroyFrameBuffer() { AssertValid(); AssertContext(); EAGLContext oldContext = EAGLContext.CurrentContext; if (!GraphicsContext.IsCurrent) { MakeCurrent(); } gl.DeleteFramebuffers(1, ref framebuffer); gl.DeleteRenderbuffers(1, ref renderbuffer); framebuffer = renderbuffer = 0; if (oldContext != EAGLContext) { EAGLContext.SetCurrentContext(oldContext); } else { EAGLContext.SetCurrentContext(null); } GraphicsContext.Dispose(); GraphicsContext = null; gl = null; }
public void MakeCurrent(IWindowInfo info) { if (!EAGLContext.SetCurrentContext(this.Context)) { throw new InvalidOperationException("Unable to change current EAGLContext."); } }
/// <summary> /// Sets up and initializes OpenGL ES /// </summary> void SetupGL() { // Setup the Rendering Context... Context = new EAGLContext(EAGLRenderingAPI.OpenGLES2); if (Context == null) { Console.WriteLine("Failed to create ES context"); } // Initialize the Renderer... Renderer = new ES2Renderer(); // Initialize the View... View.Context = Context; View.EnableSetNeedsDisplay = true; View.ClearsContextBeforeDrawing = false; View.DrawableDepthFormat = GLKViewDrawableDepthFormat.Format24; View.DrawableMultisample = GLKViewDrawableMultisample.None; View.DrawInRect += Draw; EAGLContext.SetCurrentContext(Context); GL.ClearDepth(0.0f); GL.DepthRange(0.0f, 1.0f); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Equal); GL.DepthMask(true); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Disable(EnableCap.Dither); GL.Disable(EnableCap.CullFace); }
/// <summary> /// Runs the given action on the UI thread and blocks the current thread while the action is running. /// If the current thread is the UI thread, the action will run immediately. /// </summary> /// <param name="action">The action to be run on the UI thread</param> internal static void BlockOnUIThread(Action action) { if (action == null) { throw new ArgumentNullException("action"); } #if DIRECTX || PSM action(); #else // If we are already on the UI thread, just call the action and be done with it if (mainThreadId == Thread.CurrentThread.ManagedThreadId) { action(); return; } #if IOS lock (BackgroundContext) { // Make the context current on this thread if it is not already if (!Object.ReferenceEquals(EAGLContext.CurrentContext, BackgroundContext)) { EAGLContext.SetCurrentContext(BackgroundContext); } // Execute the action action(); // Must flush the GL calls so the GPU asset is ready for the main context to use it GL.Flush(); GraphicsExtensions.CheckGLError(); } #elif SDL2 && THREADED_GL lock (BackgroundContext) { // Make the context current on this thread SDL.SDL_GL_MakeCurrent(WindowInfo, BackgroundContext.context); // Execute the action action(); // Must flush the GL calls so the texture is ready for the main context to use GL.Flush(); GraphicsExtensions.CheckGLError(); // Must make the context not current on this thread or the next thread will get error 170 from the MakeCurrent call SDL.SDL_GL_MakeCurrent(WindowInfo, IntPtr.Zero); } #else ManualResetEventSlim resetEvent = new ManualResetEventSlim(false); Add(() => { #if ANDROID //if (!Game.Instance.Window.GraphicsContext.IsCurrent) Game.Instance.Window.MakeCurrent(); #endif action(); resetEvent.Set(); }); resetEvent.Wait(); #endif #endif }
protected override void OnBeginFrame() { _stopwatch.Start(); _stopwatch2.Restart(); EAGLContext.SetCurrentContext(GLContext); GL.BindFrameBuffer(_frameBufferId); }
internal override void Initialize(GameContext gameContext) { GameContext = gameContext; gameForm = gameContext.GameView; nativeWindow = new WindowHandle(AppContextType.iOS, gameForm); gameForm.Load += gameForm_Load; gameForm.Unload += gameForm_Unload; gameForm.RenderFrame += gameForm_RenderFrame; // get the OpenGL ES version var contextAvailable = false; foreach (var version in OpenGLUtils.GetGLVersions(gameContext.RequestedGraphicsProfile)) { var contextRenderingApi = MajorVersionTOEAGLRenderingAPI(version); EAGLContext contextTest = null; try { contextTest = new EAGLContext(contextRenderingApi); // delete extra context if (contextTest != null) contextTest.Dispose(); gameForm.ContextRenderingApi = contextRenderingApi; contextAvailable = true; } catch (Exception) { // TODO: log message } } if (!contextAvailable) throw new Exception("Graphics context could not be created."); gameForm.LayerColorFormat = MonoTouch.OpenGLES.EAGLColorFormat.RGBA8; //gameForm.LayerRetainsBacking = false; // Setup the initial size of the window var width = gameContext.RequestedWidth; if (width == 0) { width = (int)(gameForm.Size.Width * gameForm.ContentScaleFactor); } var height = gameContext.RequestedHeight; if (height == 0) { height = (int)(gameForm.Size.Height * gameForm.ContentScaleFactor); } gameForm.Size = new Size(width, height); //gameForm.Resize += OnClientSizeChanged; }
public OpenGLRenderer () : base() { CurrentContext = new EAGLContext (EAGLRenderingAPI.OpenGLES2); EAGLContext.SetCurrentContext (CurrentContext); SetupOffScreenRenderContext(); loadShaders (); EAGLContext.SetCurrentContext (null); }
public static NSData GetJpegRepresentation (this CIImage image, float compressionQuality) { if (ciContext == null) { var eaglContext = new EAGLContext (EAGLRenderingAPI.OpenGLES2); ciContext = CIContext.FromContext (eaglContext); } using (CGImage outputImageRef = ciContext.CreateCGImage (image, image.Extent)) { using (UIImage uiImage = UIImage.FromImage (outputImageRef, 1f, UIImageOrientation.Up)) { return uiImage.AsJPEG (compressionQuality); } } }
public GLView () : base () { CAEAGLLayer eaglLayer = (CAEAGLLayer)Layer; eaglLayer.Opaque = true; context = new EAGLContext (EAGLRenderingAPI.OpenGLES2); if (context == null || !EAGLContext.SetCurrentContext (context)) return; animating = false; AnimationFrameInterval = 2; }
public CVOpenGLESTextureCache (EAGLContext context) { if (context == null) throw new ArgumentNullException ("context"); if (CVOpenGLESTextureCacheCreate (IntPtr.Zero, IntPtr.Zero, /* change one day to support cache attributes */ context.Handle, IntPtr.Zero, /* change one day to support texture attributes */ out handle) == 0) return; throw new Exception ("Could not create the texture cache"); }
public override void ViewDidLoad () { base.ViewDidLoad (); context = new EAGLContext (EAGLRenderingAPI.OpenGLES2); if (context == null) Console.WriteLine ("Failed to create ES context"); GLKView view = View as GLKView; view.Context = context; view.DrawableDepthFormat = GLKViewDrawableDepthFormat.Format24; setupGL (); }
/// <summary> /// Constructs an instance of ImageFilter. /// Newer iOS devices and versions can use GPU to render images and is much faster than using CPU. /// However, some older devices and/or iOS versions (specifically iPad 1 on iOS 5.x) /// may not be able to use GPU and needs to use the CPU. In that case, set the useGPU flag to false. /// </summary> /// <param name='useGPU'> /// useGPU true indicates to use GPU to render images; false indicates to use CPU. /// </param> public ImageFilter(bool useGPU = true) { if (useGPU) { EAGLContext eaglContext = new EAGLContext(EAGLRenderingAPI.S2); Dictionary<object, object> opts = new Dictionary<object, object>(); opts[CIContext.kCIContextWorkingColorSpace] = NSNull.Null(); _ciContext = CIContext.Context(eaglContext, opts); } else { _ciContext = CIContext.Context((Dictionary<object, object>) null); } }
protected override void Dispose(bool disposing) { base.Dispose(disposing); if (context != null) { context.Dispose(); context = null; } if (displayLink != null) { displayLink.Dispose(); displayLink = null; } }
public override void ViewDidLoad () { bool isPad = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad; base.ViewDidLoad (); context = new EAGLContext (EAGLRenderingAPI.OpenGLES2); glkView = (GLKView) View; glkView.Context = context; glkView.MultipleTouchEnabled = true; PreferredFramesPerSecond = 60; size = UIScreen.MainScreen.Bounds.Size.ToRoundedCGSize (); View.ContentScaleFactor = UIScreen.MainScreen.Scale; meshFactor = isPad ? 8 : 4; SetupGL (); SetupAVCapture (isPad ? AVCaptureSession.PresetiFrame1280x720 : AVCaptureSession.Preset640x480); }
public RosyWriterPreviewWindow (RectangleF frame) : base(frame) { // Use 2x scale factor on Retina dispalys. ContentScaleFactor = UIScreen.MainScreen.Scale; // Initialize OpenGL ES 2 CAEAGLLayer eagleLayer = (CAEAGLLayer)Layer; eagleLayer.Opaque = true; eagleLayer.DrawableProperties = NSDictionary.FromObjectsAndKeys ( new object[] { NSNumber.FromBoolean (false), EAGLColorFormat.RGBA8 }, new object[] { EAGLDrawableProperty.RetainedBacking, EAGLDrawableProperty.ColorFormat } ); Context = new EAGLContext (EAGLRenderingAPI.OpenGLES2); if(!EAGLContext.SetCurrentContext(Context)) throw new ApplicationException("Could not set EAGLContext"); }
public RosyWriterPreviewWindow(CGRect frame) : base(frame) { // Use 2x scale factor on Retina dispalys. ContentScaleFactor = UIScreen.MainScreen.Scale; // Initialize OpenGL ES 2 var eagleLayer = (CAEAGLLayer)Layer; eagleLayer.Opaque = true; eagleLayer.DrawableProperties = new NSDictionary ( EAGLDrawableProperty.RetainedBacking, false, EAGLDrawableProperty.ColorFormat, EAGLColorFormat.RGBA8 ); Context = new EAGLContext (EAGLRenderingAPI.OpenGLES2); if (!EAGLContext.SetCurrentContext (Context)) throw new ApplicationException ("Could not set EAGLContext"); }
internal override void Initialize(GameContext gameContext) { GameContext = gameContext; gameForm = gameContext.GameView; nativeWindow = new WindowHandle(AppContextType.iOS, gameForm); gameForm.Load += gameForm_Load; gameForm.Unload += gameForm_Unload; gameForm.RenderFrame += gameForm_RenderFrame; // get the OpenGL ES version var contextAvailable = false; foreach (var version in OpenGLUtils.GetGLVersions(gameContext.RequestedGraphicsProfile)) { var contextRenderingApi = MajorVersionTOEAGLRenderingAPI(version); EAGLContext contextTest = null; try { contextTest = new EAGLContext(contextRenderingApi); // delete extra context if (contextTest != null) contextTest.Dispose(); gameForm.ContextRenderingApi = contextRenderingApi; contextAvailable = true; break; } catch (Exception) { // TODO: log message } } if (!contextAvailable) throw new Exception("Graphics context could not be created."); gameForm.LayerColorFormat = EAGLColorFormat.RGBA8; //gameForm.LayerRetainsBacking = false; }
private void CreateFrameBuffer() { // Setup layer eaglLayer = (CAEAGLLayer)this.Layer; eaglLayer.Opaque = false; bool layerRetainsBacking = false; NSString layerColorFormat = EAGLColorFormat.RGBA8; eaglLayer.DrawableProperties = NSDictionary.FromObjectsAndKeys(new NSObject[] { NSNumber.FromBoolean(layerRetainsBacking), layerColorFormat }, new NSObject[] { EAGLDrawableProperty.RetainedBacking, EAGLDrawableProperty.ColorFormat }); // Create OpenGL drawing context EAGLRenderingAPI api = EAGLRenderingAPI.OpenGLES2; context = new EAGLContext(api); if (context == null) { throw new InvalidOperationException("Failed to initialize OpenGLES 2.0 context"); } if (!EAGLContext.SetCurrentContext(context)) { throw new InvalidOperationException("Failed to set current OpenGL context"); } // Create render buffer and assign it to the context GL.GenRenderbuffers(1, ref colorRenderBuffer); GL.BindRenderbuffer(All.Renderbuffer, colorRenderBuffer); context.RenderBufferStorage((uint)All.Renderbuffer, eaglLayer); // Create frame buffer uint frameBuffer = 0; GL.GenFramebuffers(1, ref frameBuffer); GL.BindFramebuffer(All.Framebuffer, frameBuffer); GL.FramebufferRenderbuffer(All.Framebuffer, All.ColorAttachment0, All.Renderbuffer, colorRenderBuffer); // Set viewport Size size = new Size((int)Math.Round((double)eaglLayer.Bounds.Size.Width), (int)Math.Round((double)eaglLayer.Bounds.Size.Height)); GL.Viewport(0, 0, size.Width, size.Height); // Create CADisplayLink for animation loop displayLink = CADisplayLink.Create(this, new Selector("render")); displayLink.FrameInterval = 1; displayLink.AddToRunLoop(NSRunLoop.Current, NSRunLoop.NSDefaultRunLoopMode); }
public override void ViewDidUnload () { base.ViewDidUnload (); tearDownGL (); if (EAGLContext.CurrentContext == context) EAGLContext.SetCurrentContext (null); context = null; rpyLabel = null; }
public override void ViewDidLoad () { base.ViewDidLoad (); context = new EAGLContext (EAGLRenderingAPI.OpenGLES2); if (context == null) Console.WriteLine ("Failed to create ES context"); var view = (GLKView) View; view.DrawInRect += Draw; view.Context = context; view.DrawableDepthFormat = GLKViewDrawableDepthFormat.Format24; // for planet positions generateRandomPermutation (); // for star positions for (int i = 0; i < NumStars; i++) { star [i].X = (float) (gen.NextDouble () - .5f) * FarZ; star [i].Y = (float) (gen.NextDouble () - .5f) * FarZ; star [i].Z = (float) gen.NextDouble () * (FarZ - MinStarHeight) + MinStarHeight; } setupGL (); motionManager = new CMMotionManager (); isDeviceMotionAvailable = motionManager.DeviceMotionAvailable; // the label for roll, pitch and yaw reading rpyLabel = new UILabel (new CGRect (0, 0, (int) UIScreen.MainScreen.Bounds.Size.Width, 30)); rpyLabel.BackgroundColor = UIColor.Clear; rpyLabel.TextColor = UIColor.White; rpyLabel.TextAlignment = UITextAlignment.Center; rpyLabel.LineBreakMode = UILineBreakMode.WordWrap; rpyLabel.Font = UIFont.FromName ("Helvetica-Bold", 20f); View.AddSubview (rpyLabel); }
public static CVOpenGLESTextureCache FromEAGLContext (EAGLContext context) { if (context == null) throw new ArgumentNullException ("context"); IntPtr handle; if (CVOpenGLESTextureCacheCreate (IntPtr.Zero, IntPtr.Zero, /* change one day to support cache attributes */ context.Handle, IntPtr.Zero, /* change one day to support texture attribuets */ out handle) == 0) return new CVOpenGLESTextureCache (handle); return null; }
public void SetupGL () { Context = new EAGLContext (EAGLRenderingAPI.OpenGLES2); DrawableDepthFormat = GLKViewDrawableDepthFormat.Format24; effect = new GLKBaseEffect (); effect.Light0.Enabled = true; EAGLContext.SetCurrentContext (Context); GL.Enable (EnableCap.DepthTest); GL.Oes.GenVertexArrays (1, out vertexArray); GL.Oes.BindVertexArray (vertexArray); GL.GenBuffers (1, out vertexBuffer); GL.BindBuffer (BufferTarget.ArrayBuffer, vertexBuffer); GL.BufferData (BufferTarget.ArrayBuffer, (IntPtr) (gCubeVertexData.Length * sizeof (float)), gCubeVertexData, BufferUsage.StaticDraw); GL.EnableVertexAttribArray ((int) GLKVertexAttrib.Position); GL.VertexAttribPointer ((int) GLKVertexAttrib.Position, 3, VertexAttribPointerType.Float, false, 24, 0); GL.EnableVertexAttribArray ((int) GLKVertexAttrib.Normal); GL.VertexAttribPointer ((int) GLKVertexAttrib.Normal, 3, VertexAttribPointerType.Float, false, 24, 12); GL.Oes.BindVertexArray (0); RandomizeBigCube (); for (int i = 0; i< NumLittleCubes; i++) littleCube[i] = bigCube; timeOfLastRenderedFrame = CAAnimation.CurrentMediaTime(); }
internal iPhoneOSGraphicsContext(ContextHandle h) { EAGLContext = (EAGLContext) Runtime.GetNSObject(h.Handle); }
public void Initialize() { CAEAGLLayer eaglLayer = (CAEAGLLayer)Layer; eaglLayer.Opaque = true; eaglLayer.DrawableProperties = NSDictionary.FromObjectsAndKeys( new object[] { NSNumber.FromBoolean(false), EAGLColorFormat.RGBA8 }, new object[] { EAGLDrawableProperty.RetainedBacking, EAGLDrawableProperty.ColorFormat }); m_context = new EAGLContext(EAGLRenderingAPI.OpenGLES2); if(m_context == null || !EAGLContext.SetCurrentContext(m_context)) { throw new ApplicationException("Could not create/set EAGLContext"); } m_renderer = new ES2Renderer(); m_renderer.InitWithContext(m_context, (CAEAGLLayer)Layer); Animating = false; displayLinkSupported = false; animationFrameInterval = 1; displayLink = null; animationTimer = null; // A system version of 3.1 or greater is required to use CADisplayLink. The NSTimer // class is used as fallback when it isn't available. var reqSysVer = new NSString("3.1"); var currSysVer = new NSString(UIDevice.CurrentDevice.SystemVersion); if(currSysVer.Compare(reqSysVer, NSStringCompareOptions.NumericSearch) != NSComparisonResult.Ascending) displayLinkSupported = true; }
public override void ViewDidLoad() { base.ViewDidLoad (); View.MultipleTouchEnabled = true; // set up GL PreferredFramesPerSecond = 60; context = new EAGLContext(EAGLRenderingAPI.OpenGLES2); var view = (GLKView)this.View; view.Context = context; view.DrawableDepthFormat = GLKViewDrawableDepthFormat.Format16; EAGLContext.SetCurrentContext(context); renderer = new GLRenderer(this); Delegate = renderer; // set view stuff View.MultipleTouchEnabled = true; if (desc.Orientation == ApplicationOrientations.Landscape) frameVector = new Vector2(view.Frame.Height, view.Frame.Width); else frameVector = new Vector2(view.Frame.Width, view.Frame.Height); // iAd if (enableAds) { iAdView = new ADBannerView(); iAdView.AdLoaded += new EventHandler(iAdLoaded); iAdView.FailedToReceiveAd += new EventHandler<AdErrorEventArgs>(iAdFailedToReceiveAd); var adSize = iAdView.SizeThatFits(new SizeF(frameVector.X, frameVector.Y)); iAdView.Frame = new RectangleF(0, frameVector.Y-adSize.Height, 1, 1); View.AddSubview(iAdView); iAdView.Hidden = true; } }
public EAGLLayer () { Opaque = true; DrawableProperties = NSDictionary.FromObjectsAndKeys ( new object[] { NSNumber.FromBoolean (false), EAGLColorFormat.RGBA8 }, new object[] { EAGLDrawableProperty.RetainedBacking, EAGLDrawableProperty.ColorFormat } ); context = new EAGLContext (EAGLRenderingAPI.OpenGLES2); if (context == null || !EAGLContext.SetCurrentContext (context)) throw new Exception ("Can't set EAGL context"); preferredConversion = colorConversion709; }