当我回到父视图后再次加载iphoneOSGameView时,opengl不呈现

时间:2016-12-16 07:38:03

标签: ios unity3d xamarin opengl-es opentk

我创建了以下视图类

    public partial class MyGLUIView : iPhoneOSGameView
{
    int intHeight = (int)UIScreen.MainScreen.Bounds.Height;
    int intWidth = (int)UIScreen.MainScreen.Bounds.Width;

    myRendererHandler rendrer = RendererHandler.SharedInstance();

    [Export("layerClass")]
    static Class LayerClass()
    {
        return iPhoneOSGameView.GetLayerClass();
    }

    [Export("initWithCoder:")]
    public MyGLUIView(NSCoder coder) : base(coder)
    {
        LayerRetainsBacking = false;
        LayerColorFormat = EAGLColorFormat.RGBA8;
        ContextRenderingApi = EAGLRenderingAPI.OpenGLES1;
    }

    public void SetData(int NUMBER_DEVICES, TopologyBinaryData[] data)
    {
        //set data to renderer
    }

    protected override void ConfigureLayer(CAEAGLLayer eaglLayer)
    {
        eaglLayer.Opaque = true;
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        MakeCurrent();
        rendrer.InitializeTextures();
    }

    public void onTapEvent(int x, int y)
    {
        rendrer.ProcessExpansion(x, y);
    }

    protected override void OnRenderFrame(FrameEventArgs e)
    {
        base.OnRenderFrame(e);
        rendrer.render();
        SwapBuffers();
    }
    protected override void CreateFrameBuffer()
    {

    }
}

并且viewcontroller类是

public partial class TopologyViewController : UIViewController
{


    public TopologyViewController(IntPtr handle) : base(handle)
    {
    }


    public override void ViewDidLoad()
    {
        base.ViewDidLoad();
        WireUpTapGestureRecognizer();

    }
    protected void WireUpTapGestureRecognizer()
    {
        // create a new tap gesture
        UITapGestureRecognizer tapGesture = null;

        Action action = () =>
        {

        };

        tapGesture = new UITapGestureRecognizer(action);
        // configure it
        tapGesture.NumberOfTapsRequired = 1;
        // add the gesture recognizer to the view
    }
    public override void ViewDidAppear(bool animated)
    {
        base.ViewDidAppear(animated);
    }
    public override void ViewWillAppear(bool animated)
    {
        base.ViewWillAppear(animated);
    }
    public override void ViewDidDisappear(bool animated)
    {
        base.ViewDidDisappear(animated);
        this.topologyView.Stop();
    }
    public override void DidReceiveMemoryWarning()
    {
        base.DidReceiveMemoryWarning();
        // Release any cached data, images, etc that aren't in use.
    }

}

如果我第一次在视图上方加载它的工作正常但在返回并再次加载此视图后,没有任何内容正在绘制,并且EAGLContext为null。当我在

再次按下(导航按钮)时,应用程序崩溃
   public override void ViewDidDisappear(bool animated)
{
    base.ViewDidDisappear(animated);
    **this.topologyView.Stop();**
}

我正在使用xamarin studio和openTK 1.0。

1 个答案:

答案 0 :(得分:0)

操作系统将释放EGL上下文,以减少后台视图和进程的内存;因此EAGL上下文为空。如果您想恢复绘图,则必须重新创建EAGL上下文和图形资源。