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

Tags:
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:
Status:
RESOLVED NOT_ON_ROADMAP

Description MPH 2013-04-04 05:08:02 UTC
Overview:
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.

References:
http://alvinalexander.com/java/jwarehouse/android-examples/samples/android-8/ApiDemos/src/com/example/android/apis/graphics/FrameBufferObjectActivity.java.shtml

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.3_r1/com/google/android/gles_jni/GLImpl.java#GLImpl
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.

http://androidapi.xamarin.com/?link=M%3aAndroid.Runtime.Extensions.JavaCast%3CTResult%3E