Xamarin .NET MAUI transfer OpenTK GLSurfaceView

渡邉 陽 20 Reputation points
2024-01-17T05:42:10.8733333+00:00

I'm migrating Xamarin Android/iOS to .NET MAUI. Most of the functions have been migrated successfully, but I am having trouble with the migration regarding OpenTK. Xamarin Android uses Xamarin.Legacy.OpenTK1.0.2, and the same Nuget also exists in .NET MAUI, so I use that. However Methods such as OnSurfaceCreated and OnSurfaceChanged are not called.
I'm looking for useful information regarding these.

Developer technologies | .NET | Xamarin
Developer technologies | .NET | .NET MAUI
{count} votes

1 answer

Sort by: Most helpful
  1. 渡邉 陽 20 Reputation points
    2024-01-19T06:47:11.7866667+00:00

    Was self resolved. Since I can't post all the sources, some excerpts are based on the following sources. AddHandler was used for MovieView and MovieViewRenderer. When using Xamarin, if you do not set GLView in ViewGroup, an error will occur during Dispose, so I wrapped it. I tried omitting GLViewWrapper to extract some parts, and it started working properly.

    namespace MyApp.Droid.Renderers
    {
    
        //public class MovieViewRenderer : ViewRenderer<MovieView, GLViewWrapper>	// change point
        public class MovieViewRenderer : ViewRenderer<MovieView, GLView>
        {
            private GLViewWrapper glViewWrap;
            private GLView glView;
            private MovieView movieView;
    
            public MovieViewRenderer(Context context) : base(context)
            {
            }
    
            protected override void OnElementChanged(ElementChangedEventArgs<MovieView> e)
            {
                if (Control == null)
                {
                    movieView = (MovieView)Element;
    
                    //glViewWrap = new GLViewWrapper(this.Context, movieView);	// change point
                    //glView = glViewWrap.glView;	// change point
    
                    glView = new GLView(this.Context);
                    SetNativeControl(glView);
                }
            }
    
            protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
            {
            }
    
            protected override void Dispose(bool disposing)
            {
            }
        }
    }
    
    
    
    namespace MyApp.Droid.Views
    {
        public class GLView : GLSurfaceView, GLSurfaceView.IRenderer, SurfaceTexture.IOnFrameAvailableListener
        {
    
            public GLView(Context context) : base(context)
            {
                SetEGLContextClientVersion(2);  //GLVersion.ES20
                SetRenderer(this);
            }
    
            public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
            {
                InitGL();
                InitMovieTexture();
                	:
            }
    
            public void OnSurfaceChanged(IGL10 gl, int width, int height)
            {
                gl.GlViewport(0, 0, width, height);
                	:
            }
    
            public void OnDrawFrame(IGL10 gl)
            {
            	BeginDraw(gl);
                	:
            }
        }
    }
    
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.