Bug 11574 - GLSurfaceView.Render gl parameter cannot be cast to IGL11ExtensionPack
Summary: GLSurfaceView.Render gl parameter cannot be cast to IGL11ExtensionPack
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.6.x
Hardware: Macintosh Mac OS
: High normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2013-04-04 05:08 UTC by MPH
Modified: 2014-01-10 16:49 UTC (History)
3 users (show)

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 MPH 2013-04-04 05:08:02 UTC
When GLSurfaceView calls its renderer methods, it passes an instance that implements the IGL10 interface.  However, this instance implements several other interfaces, which seem to not be correctly exposed.

Steps to reproduce:
In your Renderer, cast the IGL10 object to an instance of IGL11ExtensionPack, e.g.:

public class MyGLViewRenderer : Java.Lang.Object, GLSurfaceView.IRenderer
   public void OnDrawFrame(IGL10 gl)
      IGL11ExtensionPack gl11ep = (IGL11ExtensionPack)gl;

This fails.  (Furthermore, a cursory review of the object in Java suggest it is based on a com.google.android.gles_jni.GLImpl which contains various OES Extension methods, but they are not exposed here.)

Expected Behavior:
This succeeds. See reference code.


Comment 1 Jonathan Pryor 2014-01-10 16:49:08 UTC
Use the .JavaCast<T>() extension method. The GLImpl type is not public, and thus cannot be bound by itself, and your C# cast will only be operating on Xamarin.Android proxy instances.

Use the .JavaCast<T>() extension method to safely coerce types.