Bug 169 - Can't add ColorFormat, Stencil Buffer, or DepthBuffers because GraphicsMode on GraphicsContext in AndroidGameView is null and cannot be changed
Summary: Can't add ColorFormat, Stencil Buffer, or DepthBuffers because GraphicsMode o...
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 1.0
Hardware: PC Other
: High critical
Target Milestone: 4.2
Assignee: shana@xamarin.com
Depends on:
Reported: 2011-08-03 21:04 UTC by Chris Drake
Modified: 2012-02-27 13:01 UTC (History)
7 users (show)

Tags: AndroidGameView, GraphicsContext, GraphicsMode
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Chris Drake 2011-08-03 21:04:54 UTC
Overview: I am attempting to add a stencil buffer to GraphicsContext.GraphicsMode. Since this is a read-only property of the GraphicsContext class I am forced to generate a new GraphicsContext, set the new GraphicsMode in its constructor, and then make the new GraphicsContext current like so:

GraphicsMode newGm = new GraphicsMode (32, 24, 8, 4);
GraphicsContext gc = new GraphicsContext (newGm, WindowInfo, 2, 0, GraphicsContextFlags.Embedded | GraphicsContextFlags.Debug);

The first problem I noted while debugging is that the default GraphicsContext.GraphicsMode in AndroidGameView is initially set to "null" which seemed odd, but since this property is used to set up optional fragment operations I thought that may be normal. I then noticed that the GraphicsMode property on the GraphicsContext I had just constructed was also set to "null" after I had explicitly set it to a valid GraphicsMode object in the GraphicsContext constructor. GraphicsContext.GraphicsMode is read-only so I know of no other way to set it other than through the GraphicsContext constructor. I also get an InvalidOperationException when I attempt to make my new GraphicsContext current using "gc.MakeCurrent(WindowInfo)"

Steps to Reproduce: 

1. Construct new GraphicsMode object and use it to construct a new GraphicsContext object.
2. Notice that after construction of the new GraphicsContext object the GraphicsMode object is still set to "null"
3. Attempt to make the new GraphicsContext object current on the thread using the AndroidGameView.WindowInfo property to set the native window.
4. Notice that you get an InvalidOperationException 

Actual Results: 

GraphicsMode was still set to null and received an InvalidOperationException after the MakeCurrent(WindowInfo) call

Expected Results: 

My GraphicsContext object should be current with stencil and depth buffers set to the size requested in the GraphicsMode object used to construct the GraphicsContext

Build Date & Platform: 

    Version 1.0 on Android 2.2

Additional Builds and Platforms: 

Not sure

Additional Information:

This is similar to bug# 680647 at the following link:

Comment 4 PJ 2012-01-06 17:45:53 UTC
Trying to reproduce, but get an error on the constructor itself.

Screencast to demonstrate my steps: http://screencast.com/t/3o5CL87n7EM6

I imagine I could just be putting the code in the wrong place, but any info/confirmation would be appreciated. Thanks!

Here's the error:
System.Diagnostics.Debugger.Mono_UnhandledException (ex=) in /home/jon/Development/xamarin/mono/mcs/class/corlib/System.Diagnostics/Debugger.cs:124
System.Object.a381ebfa-fa9a-4c75-9aad-9591a5ff04f1 (Parameters=) in 
OpenTK.Platform.Android.AndroidGraphicsContext..ctor (Parameters=) in /home/jpobst/Desktop/monodroid/OpenGLES/OpenTK/Platform/Android/AndroidGraphicsContext.cs:95
OpenTK.Platform.Factory.CreateGLContext (Parameters=) in /home/jpobst/Desktop/monodroid/OpenGLES/OpenTK/Platform/Factory.Android.cs:49
OpenTK.Graphics.GraphicsContext..ctor (Parameters=) in /home/jpobst/Desktop/monodroid/OpenGLES/OpenTK/Graphics/GraphicsContext.cs:135
GraphicsContextTest.GLView1.OnRenderFrame (Parameters=) in c:\Users\XamarinQA\Documents\GraphicsContextTest\GraphicsContextTest\GLView1.cs:36
OpenTK.Platform.Android.AndroidGameView.RunIteration (Parameters=) in /home/jpobst/Desktop/monodroid/OpenGLES/OpenTK/Platform/Android/AndroidGameView.cs:1215
OpenTK.Platform.Android.RepeatTimerTask.Run (Parameters=) in /home/jpobst/Desktop/monodroid/OpenGLES/OpenTK/Platform/Android/AndroidGameView.cs:1668
Java.Util.TimerTask.n_Run (Parameters=) in /home/jpobst/Desktop/monodroid/Mono.Android/platforms/android-8/src/generated/Java.Util.TimerTask.cs:80
System.Object.a381ebfa-fa9a-4c75-9aad-9591a5ff04f1 (Parameters=) in
Comment 5 Andreia Gaita 2012-02-27 13:01:35 UTC
MfA 4.0.5 (which is coming out this week) has a new OpenTK/Android backend and full support for custom contexts, where you can set all the options you need.