public OpenGLRenderer() { CurrentContext = new EAGLContext(EAGLRenderingAPI.OpenGLES2); EAGLContext.SetCurrentContext(CurrentContext); SetupOffScreenRenderContext(); LoadShaders(); EAGLContext.SetCurrentContext(null); }
public IDisposable MakeCurrent() { var old = EAGLContext.CurrentContext; if (!EAGLContext.SetCurrentContext(Context)) { throw new OpenGlException("Unable to make context current"); } return(new ResetContext(old)); }
void SetupGL() { EAGLContext.SetCurrentContext(context); if (LoadShaders()) { GL.UseProgram(program); GL.Uniform1(uniforms [UNIFORM_Y], 0); GL.Uniform1(uniforms [UNIFORM_UV], 1); } }
public override void ViewDidUnload() { base.ViewDidUnload(); TeardownAVCapture(); TeardownGL(); if (EAGLContext.CurrentContext == context) { EAGLContext.SetCurrentContext(null); } }
private void SetupGL() { EAGLContext.SetCurrentContext(this.context); if (this.LoadShaders()) { GL.UseProgram(this.program); GL.Uniform1(this.uniforms[UNIFORM_Y], 0); GL.Uniform1(this.uniforms[UNIFORM_UV], 1); } }
public void Dispose() { if (_disposed) { return; } _disposed = true; EAGLContext.SetCurrentContext(_old); _old = null; }
void setupGL() { EAGLContext.SetCurrentContext(context); effect = new GLKBaseEffect(); effect.LightingType = GLKLightingType.PerPixel; 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)(Monkey.MeshVertexData.Length * sizeof(float)), Monkey.MeshVertexData, BufferUsage.StaticDraw); GL.EnableVertexAttribArray((int)GLKVertexAttrib.Position); GL.VertexAttribPointer((int)GLKVertexAttrib.Position, 3, VertexAttribPointerType.Float, false, 8 * sizeof(float), 0); GL.EnableVertexAttribArray((int)GLKVertexAttrib.Normal); GL.VertexAttribPointer((int)GLKVertexAttrib.Normal, 3, VertexAttribPointerType.Float, false, 8 * sizeof(float), 12); GL.EnableVertexAttribArray((int)GLKVertexAttrib.TexCoord0); GL.VertexAttribPointer((int)GLKVertexAttrib.TexCoord0, 2, VertexAttribPointerType.Float, false, 8 * sizeof(float), 24); GL.ActiveTexture(TextureUnit.Texture0); string path = NSBundle.MainBundle.PathForResource("monkey", "png"); NSError error; NSDictionary options = new NSDictionary(GLKTextureLoader.OriginBottomLeft, true); texture = GLKTextureLoader.FromFile(path, options, out error); if (texture == null) { Console.WriteLine(String.Format("Error loading texture: {0}", error.LocalizedDescription)); } GLKEffectPropertyTexture tex = new GLKEffectPropertyTexture(); tex.Enabled = true; tex.EnvMode = GLKTextureEnvMode.Decal; tex.GLName = texture.Name; effect.Texture2d0.GLName = tex.GLName; GL.Oes.BindVertexArray(0); }
/// <summary> /// Destroys all OpenGL ES resources associated with this view and the model being drawn. /// </summary> protected void TearDownGL() { EAGLContext.SetCurrentContext(Context); // Delete all the VBOs in the current model... if (App.Manager.CurrentModel != null) { if (App.Manager.CurrentModel.DisplayObjects != null) { // Destroy all buffers on all meshes foreach (var obj in App.Manager.CurrentModel.DisplayObjects) { var mesh = obj as DisplayMesh; if (mesh != null) { if (mesh.VertexBufferHandle != Globals.UNSET_HANDLE) { uint vbo = mesh.VertexBufferHandle; GL.DeleteBuffers(1, ref vbo); mesh.VertexBufferHandle = Globals.UNSET_HANDLE; } if (mesh.IndexBufferHandle != Globals.UNSET_HANDLE) { uint ibo = mesh.IndexBufferHandle; GL.DeleteBuffers(1, ref ibo); mesh.IndexBufferHandle = Globals.UNSET_HANDLE; } } } // Destroy all buffers on all transparent meshes foreach (var obj in App.Manager.CurrentModel.TransparentObjects) { var mesh = obj as DisplayMesh; if (mesh != null) { if (mesh.VertexBufferHandle != Globals.UNSET_HANDLE) { uint vbo = mesh.VertexBufferHandle; GL.DeleteBuffers(1, ref vbo); mesh.VertexBufferHandle = Globals.UNSET_HANDLE; } if (mesh.IndexBufferHandle != Globals.UNSET_HANDLE) { uint ibo = mesh.IndexBufferHandle; GL.DeleteBuffers(1, ref ibo); mesh.IndexBufferHandle = Globals.UNSET_HANDLE; } } } } } Renderer.Dispose(); }
public override void LayoutSubviews() { base.LayoutSubviews(); if (_viewContext != null) { EAGLContext.SetCurrentContext(_viewContext); _baseMapView.OnSurfaceChanged((int)(Bounds.Size.Width * _scale), (int)(Bounds.Size.Height * _scale)); SetNeedsDisplay(); } }
// Destructor(s) protected override void Dispose(bool disposing) { this.TearDownGL(); if (this.context == EAGLContext.CurrentContext) { EAGLContext.SetCurrentContext(null); } this.context = null; base.Dispose(disposing); }
private void InitializeGameComponents() { EAGLContext.SetCurrentContext(_view.BackgroundContext); foreach (GameComponent gc in _gameComponentCollection) { gc.Initialize(); } EAGLContext.SetCurrentContext(_view.MainContext); }
protected override void Dispose(bool disposing) { base.Dispose(disposing); TearDownGL(); if (EAGLContext.CurrentContext == context) { EAGLContext.SetCurrentContext(null); } }
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); /* * _monkeyMeshYellow = Mesh(meshFile: Bundle.main.path(forResource: "monkey", ofType: "json")!, * textureFile: Bundle.main.path(forResource: "texture", ofType: "png")!) * _monkeyMeshBlue = Mesh(meshFile: Bundle.main.path(forResource: "monkey", ofType: "json")!, * textureFile: Bundle.main.path(forResource: "texture2", ofType: "png")!) * _monkeyMeshRed = Mesh(meshFile: Bundle.main.path(forResource: "monkey", ofType: "json")!, * textureFile: Bundle.main.path(forResource: "texture3", ofType: "png")!) * _monkeyMeshGray = Mesh(meshFile: Bundle.main.path(forResource: "monkey", ofType: "json")!, * textureFile: Bundle.main.path(forResource: "texturegray", ofType: "png")!) */ string meshFile = NSBundle.MainBundle.PathForResource("monkey", "json"); string textureFile = NSBundle.MainBundle.PathForResource("texture", "png"); string textureFile2 = NSBundle.MainBundle.PathForResource("texture2", "png"); string textureFile3 = NSBundle.MainBundle.PathForResource("texture3", "png"); string textureFileGray = NSBundle.MainBundle.PathForResource("texturegray", "png"); mMonkeyMeshYellow = new Mesh(); mMonkeyMeshYellow.InitMesh(meshFile, textureFile); mMonkeyMeshYellow.LoadMesh(); mMonkeyMeshBlue = new Mesh(); mMonkeyMeshBlue.InitMesh(meshFile, textureFile2); mMonkeyMeshBlue.LoadMesh(); mMonkeyMeshRed = new Mesh(); mMonkeyMeshRed.InitMesh(meshFile, textureFile3); mMonkeyMeshRed.LoadMesh(); mMonkeyMeshGray = new Mesh(); mMonkeyMeshGray.InitMesh(meshFile, textureFileGray); mMonkeyMeshGray.LoadMesh(); mMonkeyMesh = mMonkeyMeshGray; GL.ClearColor(1, 1, 1, 1); } 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); }
private void InitializeGameComponents() { EAGLContext.SetCurrentContext(_view.BackgroundContext); for (int x = 0; x < _gameComponentCollection.Count; x++) { var gc = (GameComponent)_gameComponentCollection[x]; gc.Initialize(); } EAGLContext.SetCurrentContext(_view.MainContext); }
void SetupGL() { EAGLContext.SetCurrentContext(context); max = Math.Max(view_width, view_height); demoContext = new Mini.GLDemoContext(800, 600); demoContext.LoadDemo(new OpenTkEssTest.T108_LionFill()); //-------------------------------------------------------------------------------- GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.ClearColor(1, 1, 1, 1); //setup viewport size //square viewport }
protected override void Dispose(bool disposing) { DebugLogViewer.WriteLine("Dispose() : " + disposing); base.Dispose(disposing); TearDownGL(); if (EAGLContext.CurrentContext == m_Context) { EAGLContext.SetCurrentContext(null); } }
void TearDownGL() { EAGLContext.SetCurrentContext(m_Context); GL.DeleteBuffers(1, ref m_vertexBuffer); GL.Oes.DeleteVertexArrays(1, ref m_vaoObject); if (m_shaderProgram > 0) { GL.DeleteProgram(m_shaderProgram); m_shaderProgram = 0; } }
public virtual void Render() { if (glContext == null) { PrepareGLContexts(); } EAGLContext.SetCurrentContext(glContext); // manage the drawing surface if (renderTarget == null || surface == null) { // create or update the dimensions renderTarget?.Dispose(); Gles.glGetIntegerv(Gles.GL_FRAMEBUFFER_BINDING, out var framebuffer); Gles.glGetIntegerv(Gles.GL_STENCIL_BITS, out var stencil); Gles.glGetIntegerv(Gles.GL_SAMPLES, out var samples); var maxSamples = context.GetMaxSurfaceSampleCount(colorType); if (samples > maxSamples) { samples = maxSamples; } Gles.glGetRenderbufferParameteriv(Gles.GL_RENDERBUFFER, Gles.GL_RENDERBUFFER_WIDTH, out var bufferWidth); Gles.glGetRenderbufferParameteriv(Gles.GL_RENDERBUFFER, Gles.GL_RENDERBUFFER_HEIGHT, out var bufferHeight); var glInfo = new GRGlFramebufferInfo((uint)framebuffer, colorType.ToGlSizedFormat()); renderTarget = new GRBackendRenderTarget(bufferWidth, bufferHeight, samples, stencil, glInfo); // create the surface surface?.Dispose(); surface = SKSurface.Create(context, renderTarget, surfaceOrigin, colorType); } using (new SKAutoCanvasRestore(surface.Canvas, true)) { // start drawing var e = new SKPaintGLSurfaceEventArgs(surface, renderTarget, surfaceOrigin, colorType); OnPaintSurface(e); #pragma warning disable CS0618 // Type or member is obsolete DrawInSurface(e.Surface, e.RenderTarget); SKDelegate?.DrawInSurface(e.Surface, e.RenderTarget); #pragma warning restore CS0618 // Type or member is obsolete } // flush the SkiaSharp context to the GL context surface.Canvas.Flush(); context.Flush(); // present the GL buffers glContext.PresentRenderBuffer(Gles.GL_RENDERBUFFER); EAGLContext.SetCurrentContext(null); }
public override void ViewDidUnload() { base.ViewDidUnload(); tearDownGL(); if (EAGLContext.CurrentContext == context) { EAGLContext.SetCurrentContext(null); } context = null; rpyLabel = null; }
void TearDownGL() { EAGLContext.SetCurrentContext(context); GL.DeleteBuffers(1, ref vertexBuffer); GL.Oes.DeleteVertexArrays(1, ref vertexArray); effect = null; if (program > 0) { GL.DeleteProgram(program); program = 0; } }
// Setup and Teardown private void SetupGL() { // Context EAGLContext.SetCurrentContext(this.context); this.effect = new GLKBaseEffect(); GL.Disable(EnableCap.DepthTest); // Signature lines GL.Oes.GenVertexArrays(1, out vertexArray); GL.Oes.BindVertexArray(vertexArray); GL.GenBuffers(1, out vertexBuffer); GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBuffer); int s = Marshal.SizeOf(typeof(NICSignaturePoint)) * this.SignatureVertexData.Length; GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)s, this.SignatureVertexData, BufferUsage.DynamicDraw); this.BindShaderAttributes(); // Signature dots GL.Oes.GenVertexArrays(1, out dotsArray); GL.Oes.BindVertexArray(dotsArray); GL.GenBuffers(1, out dotsBuffer); GL.BindBuffer(BufferTarget.ArrayBuffer, dotsBuffer); s = Marshal.SizeOf(typeof(NICSignaturePoint)) * this.SignatureDotsData.Length; GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)s, this.SignatureDotsData, BufferUsage.DynamicDraw); this.BindShaderAttributes(); GL.Oes.BindVertexArray(0); // Perspective Matrix4 ortho = Matrix4.CreateOrthographic(2.0f, 2.0f, 0.1f, 2.0f); effect.Transform.ProjectionMatrix = ortho; Matrix4 modelViewMatrix = Matrix4.CreateTranslation(new Vector3 { X = 0.0f, Y = 0.0f, Z = -1.0f }); effect.Transform.ModelViewMatrix = modelViewMatrix; vertexLength = 0; dotsLength = 0; penThickness = 0.004f; previousPoint = new CGPoint { X = -100, Y = -100 }; }
public IOSWindow(IOSAppDelegate appDelegate) { _displaySize = new Vector2Int( (int)UIScreen.MainScreen.NativeBounds.Size.Width, (int)UIScreen.MainScreen.NativeBounds.Size.Height ); _stopwatch = new Stopwatch(); _stopwatch2 = new Stopwatch(); // Create the window Window = new UIWindow(UIScreen.MainScreen.Bounds); Window.RootViewController = new NozNavigationController(); Window.BackgroundColor = UIColor.White; Window.MakeKeyAndVisible(); appDelegate.Window = Window; // Create GL context GLContext = new EAGLContext(EAGLRenderingAPI.OpenGLES3); EAGLContext.SetCurrentContext(GLContext); // Create teh view _view = new NozView(this, Window.Bounds); _view.MultipleTouchEnabled = true; _view.UserInteractionEnabled = true; Window.AddSubview(_view); Graphics.Driver = OpenGLDriver.Create(); // Create render buffer.. _renderBufferId = GL.GenRenderBuffer(); GL.BindRenderBuffer(_renderBufferId); GLContext.RenderBufferStorage((uint)GL.Imports.GL_RENDERBUFFER, (CAEAGLLayer)_view.Layer); // Create frame buffer _frameBufferId = GL.GenFrameBuffer(); GL.BindFrameBuffer(_frameBufferId); GL.FrameBufferRenderBuffer(_renderBufferId); var link = CADisplayLink.Create(() => { Application.Step(); }); link.PreferredFramesPerSecond = 60; link.AddToRunLoop(NSRunLoop.Main, NSRunLoopMode.Default); }
public RosyWriterPreview(IntPtr handle) : base(handle) { // Initialize OpenGL ES 2 var eagleLayer = Layer as CAEAGLLayer; 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"); } }
private void OnDraw() { if (_viewContext != null && _active) { EAGLContext context = EAGLContext.CurrentContext; if (context != _viewContext) { EAGLContext.SetCurrentContext(_viewContext); } _baseMapView.OnDrawFrame(); if (context != _viewContext) { EAGLContext.SetCurrentContext(context); } } }
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; }
/// <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 (IsOnUIThread()) { 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(); } #else ManualResetEventSlim resetEvent = new ManualResetEventSlim(false); Add(() => { #if ANDROID //if (!Game.Instance.Window.GraphicsContext.IsCurrent) ((AndroidGameWindow)Game.Instance.Window).GameView.MakeCurrent(); #endif action(); resetEvent.Set(); }); resetEvent.Wait(); #endif #endif }
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; }
void SetupGL() { 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; EAGLContext.SetCurrentContext(context); // _max = Math.Max(_view_width * 2, _view_height * 2); _appHost = new LayoutFarm.AppHostIOS(this, _max, _max); _htmlBox = new Demo_UIHtmlBox(); _appHost.StartApp(_htmlBox); }
protected override void Dispose(bool disposing) { if (_willResignActiveNotificationObserver != null) { NSNotificationCenter.DefaultCenter.RemoveObserver(_willResignActiveNotificationObserver); _willResignActiveNotificationObserver = null; } if (_didBecomeActiveNotificationObserver != null) { NSNotificationCenter.DefaultCenter.RemoveObserver(_didBecomeActiveNotificationObserver); _didBecomeActiveNotificationObserver = null; } if (_didEnterBackgroundNotificationObserver != null) { NSNotificationCenter.DefaultCenter.RemoveObserver(_didEnterBackgroundNotificationObserver); _didEnterBackgroundNotificationObserver = null; } if (_willEnterForegroundNotificationObserver != null) { NSNotificationCenter.DefaultCenter.RemoveObserver(_willEnterForegroundNotificationObserver); _willEnterForegroundNotificationObserver = null; } lock (this) { if (_redrawRequestListener != null) { _redrawRequestListener.Detach(); _redrawRequestListener = null; } if (_baseMapView != null) { _baseMapView.OnSurfaceDestroyed(); _baseMapView.SetRedrawRequestListener(null); _baseMapView = null; _surfaceCreated = false; _activeDrawableSize = new CGSize(0, 0); } if (EAGLContext.CurrentContext == Context) { EAGLContext.SetCurrentContext(null); } } base.Dispose(disposing); }
public override void DidReceiveMemoryWarning() { base.DidReceiveMemoryWarning(); if (IsViewLoaded && View.Window == null) { View = null; TearDownGL(); if (EAGLContext.CurrentContext == context) { EAGLContext.SetCurrentContext(null); } } // Dispose of any resources that can be recreated. }