コード例 #1
0
        public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            RegisterCallback1(Add1);
            RegisterCallback2(Add2);

            nativeInit(IntPtr.Zero);
        }
コード例 #2
0
        public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            /*
             * By default, OpenGL enables features that improve quality
             * but reduce performance. One might want to tweak that
             * especially on software renderer.
             */
            gl.GlDisable(GL10.GlDither);

            /*
             * Some one-time OpenGL initialization can be made here
             * probably based on features of this particular context
             */
            gl.GlHint(GL10.GlPerspectiveCorrectionHint, GL10.GlFastest);

            if (mTranslucentBackground)
            {
                gl.GlClearColor(0, 0, 0, 0);
            }
            else
            {
                gl.GlClearColor(1, 1, 1, 1);
            }

            gl.GlEnable(GL10.GlCullFaceCapability);
            gl.GlShadeModel(GL10.GlSmooth);
            gl.GlEnable(GL10.GlDepthTest);
        }
コード例 #3
0
        public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            GLES20.GlClearColor(0.1f, 0.1f, 0.1f, 1.0f);

            // Create the texture and pass it to ARCore session to be filled during update().
            mBackgroundRenderer.CreateOnGlThread(/*context=*/ this);
            mSession.SetCameraTextureName(mBackgroundRenderer.TextureId);

            // Prepare the other rendering objects.
            try
            {
                mVirtualObject.CreateOnGlThread(/*context=*/ this, "andy.obj", "andy.png");
                mVirtualObject.SetMaterialProperties(0.0f, 3.5f, 1.0f, 6.0f);

                mVirtualObjectShadow.CreateOnGlThread(/*context=*/ this,
                                                      "andy_shadow.obj", "andy_shadow.png");
                mVirtualObjectShadow.BlendMode = BlendMode.Shadow;
                mVirtualObjectShadow.SetMaterialProperties(1.0f, 0.0f, 0.0f, 1.0f);
            }
            catch (Java.IO.IOException e)
            {
                Log.Error(TAG, "Failed to read obj file");
            }
            try
            {
                mPlaneRenderer.CreateOnGlThread(/*context=*/ this, "trigrid.png");
            }
            catch (Java.IO.IOException e)
            {
                Log.Error(TAG, "Failed to read plane texture");
            }
            mPointCloud.CreateOnGlThread(/*context=*/ this);
        }
コード例 #4
0
            public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
            {
                if (mShuttingDown)
                {
                    return;
                }

                mRenderer.OnSurfaceCreated(config);
            }
コード例 #5
0
 public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
 {
     lock (this) {
         if (_baseMapView != null)
         {
             _baseMapView.OnSurfaceCreated();
         }
     }
 }
コード例 #6
0
 public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
 {
     lock (this) {
         BaseMapView baseMapView = null;
         _baseMapView.TryGetTarget(out baseMapView);
         if (baseMapView != null)
         {
             baseMapView.OnSurfaceCreated();
         }
     }
 }
コード例 #7
0
        public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            gl.GlClearColor(0f, 0f, 0f, 1f);
            gl.GlShadeModel(GL10.GlSmooth);
            gl.GlHint(GL10.GlPerspectiveCorrectionHint, GL10.GlNicest);
            gl.GlHint(GL10.GlLineSmoothHint, GL10.GlNicest);
            gl.GlHint(GL10.GlPolygonSmoothHint, GL10.GlNicest);
            gl.GlEnable(GL10.GlLineSmooth);
            gl.GlDisable(GL10.GlDepthTest);
            gl.GlDisable(GL10.GlCullFaceCapability);

            mObserver.OnSurfaceCreated();
        }
コード例 #8
0
 public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
 {
     // Set background color and enable depth testing
     GLES20.GlClearColor(1f, 1f, 1f, 1.0f);
     GLES20.GlEnable(GLES20.GlDepthTest);
     resetModelMatCalculator();
     mCameraFrustum        = new CameraFrustum();
     mFloorGrid            = new Grid();
     mCameraFrustumAndAxis = new CameraFrustumAndAxis();
     mTrajectory           = new Trajectory(3);
     // Construct the initial view matrix
     Matrix.SetIdentityM(mViewMatrix, 0);
     Matrix.SetLookAtM(mViewMatrix, 0, 5f, 5f, 5f, 0f, 0f, 0f, 0f, 1f, 0f);
     mCameraFrustumAndAxis.ModelMatrix = ModelMatCalculator.ModelMatrix;
 }
コード例 #9
0
ファイル: Renderer.cs プロジェクト: KirinDenis/SeaBan
        public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            if (RenderManager.externalPaused)
            {
                RenderManager.initShaders();
            }
            else
            {
                RenderManager.createObjects();
            }

            GLES20.GlClearColor(0.1f, 0.1f, 0.9f, 0.0f);
            GLES20.GlEnable(GLES20.GlDepthTest);
            GLES20.GlEnable(GLES20.GlCullFaceMode);
            GLES20.GlCullFace(GLES20.GlBack);
        }
コード例 #10
0
        public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            // Create the triangle
            SetupTriangle();

            // Create the image information
            SetupImage();

            // Set the clear color to yellow
            GLES20.GlClearColor(1.0f, 1.0f, 0f, 1);

            GLES20.GlEnable(GLES20.GlBlend);
            GLES20.GlBlendFunc(GLES20.GlOne, GLES20.GlOneMinusSrcAlpha);

            #region Solid colors mode

            /*
             * // Create the shaders, solid color
             * int vertexShader = ShaderHelper.LoadShader(GLES20.GlVertexShader, ShaderHelper.VsSolidColor);
             * int fragmentShader = ShaderHelper.LoadShader(GLES20.GlFragmentShader, ShaderHelper.FsSolidColor);
             *
             * ShaderHelper.SpSolidColor = GLES20.GlCreateProgram();             // create empty OpenGL ES Program
             * GLES20.GlAttachShader(ShaderHelper.SpSolidColor, vertexShader);   // add the vertex shader to program
             * GLES20.GlAttachShader(ShaderHelper.SpSolidColor, fragmentShader); // add the fragment shader to program
             * GLES20.GlLinkProgram(ShaderHelper.SpSolidColor);                  // creates OpenGL ES program executables
             *
             * // Set our shader programm
             * GLES20.GlUseProgram(ShaderHelper.SpSolidColor);
             */
            #endregion

            #region Texture mode
            // Create the shaders, images
            int vertexShader   = ShaderHelper.LoadShader(GLES20.GlVertexShader, ShaderHelper.VsImage);
            int fragmentShader = ShaderHelper.LoadShader(GLES20.GlFragmentShader, ShaderHelper.FsImage);

            ShaderHelper.SpImage = GLES20.GlCreateProgram();
            GLES20.GlAttachShader(ShaderHelper.SpImage, vertexShader);
            GLES20.GlAttachShader(ShaderHelper.SpImage, fragmentShader);
            GLES20.GlLinkProgram(ShaderHelper.SpImage);

            // Set our shader programm
            GLES20.GlUseProgram(ShaderHelper.SpImage);
            #endregion
        }
コード例 #11
0
        /// <summary>
        /// This method will clear the surface view from its last rendered pixels.
        /// This is used to avoid seeing the previous video rendering when setting
        /// a video source to null.
        /// </summary>
        internal void Clear()
        {
#pragma warning disable 618
            // The solution is as described here:
            // https://stackoverflow.com/questions/25660994/clear-video-frame-from-surfaceview-on-video-complete
            if (Holder?.Surface == null)
            {
                return;
            }

            var egl     = Javax.Microedition.Khronos.Egl.EGLContext.EGL.JavaCast <IEGL10>();
            var display = egl.EglGetDisplay(EGL10.EglDefaultDisplay);
            egl.EglInitialize(display, null);

            int[] attribList =
            {
                EGL10.EglRedSize,                         8,
                EGL10.EglGreenSize,                       8,
                EGL10.EglBlueSize,                        8,
                EGL10.EglAlphaSize,                       8,
                EGL10.EglRenderableType, EGL10.EglWindowBit,
                EGL10.EglNone,                            0, // placeholder for recordable [@-3]
                EGL10.EglNone
            };

            var configs    = new Javax.Microedition.Khronos.Egl.EGLConfig[1];
            var numConfigs = new int[1];

            egl.EglChooseConfig(display, attribList, configs, configs.Length, numConfigs);
            var config  = configs[0];
            var context = egl.EglCreateContext(display, config, EGL10.EglNoContext, new int[] { 12440, 2, EGL10.EglNone });

            var eglSurface = egl.EglCreateWindowSurface(display, config, Holder.Surface, new int[] { EGL10.EglNone });

            egl.EglMakeCurrent(display, eglSurface, eglSurface, context);
            GLES20.GlClearColor(0, 0, 0, 1);
            GLES20.GlClear(GLES20.GlColorBufferBit);
            egl.EglSwapBuffers(display, eglSurface);
            egl.EglDestroySurface(display, eglSurface);
            egl.EglMakeCurrent(display, EGL10.EglNoSurface, EGL10.EglNoSurface, EGL10.EglNoContext);
            egl.EglDestroyContext(display, context);
            egl.EglTerminate(display);
#pragma warning restore 618
        }
コード例 #12
0
        public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            GLES20.GlClearColor(0.1f, 0.1f, 0.1f, 1.0f);

            // Create the texture and pass it to ARCore session to be filled during update().
            mBackgroundRenderer.CreateOnGlThread(/*context=*/ this);
            if (mSession != null)
            {
                mSession.SetCameraTextureName(mBackgroundRenderer.TextureId);
            }

            // Prepare the other rendering objects.
            try
            {
                mVirtualObject.CreateOnGlThread(/*context=*/ this, "andy.obj", "andy2.png");
                mVirtualObject.setMaterialProperties(0.0f, 3.5f, 1.0f, 6.0f);

                mVirtualObjectShadow.CreateOnGlThread(/*context=*/ this, "andy_shadow.obj", "vsplogo.png");
                mVirtualObjectShadow.SetBlendMode(ObjectRenderer.BlendMode.Shadow);
                mVirtualObjectShadow.setMaterialProperties(1.0f, 0.0f, 0.0f, 1.0f);
                showLoadingObjMessage("1. loaded obj file");
            }
            catch (Java.IO.IOException e)
            {
                Log.Error(TAG, "Failed to read obj file");
                showLoadingObjMessage("2. Failed to read obj file");
            }

            try
            {
                mPlaneRenderer.CreateOnGlThread(/*context=*/ this, "dot4.png");
                showLoadingObjMessage("3. load floor image file");
            }
            catch (Java.IO.IOException e)
            {
                Log.Error(TAG, "Failed to read plane texture");
            }
            mPointCloud.CreateOnGlThread(/*context=*/ this);
        }
コード例 #13
0
ファイル: AndroidSupport.cs プロジェクト: ryan-bunker/axiom3d
		/// <summary>
		/// </summary>
		/// <param name="eglDisplay"> </param>
		/// <param name="glConfig"> </param>
		/// <param name="shareList"> </param>
		/// <returns> </returns>
		public EGLCONTEXT CreateNewContext( EGLDisplay eglDisplay, EGLConfig glConfig, EGLCONTEXT shareList )
		{
			var contexAttrs = new int[] { 1, 2, EGL10Consts.EglNone };
			EGLCONTEXT context = null;
			if ( eglDisplay == null )
			{
				context = EGLCONTEXT.EGL11.EglCreateContext( this._glDisplay, glConfig, shareList, contexAttrs );
			}
			else
			{
				context = EGLCONTEXT.EGL11.EglCreateContext( this._glDisplay, glConfig, null, contexAttrs );
			}

			if ( context == null )
			{
				throw new AxiomException( "Fail to create New context" );
			}

			return context;
		}
コード例 #14
0
ファイル: AndroidSupport.cs プロジェクト: ryan-bunker/axiom3d
		/// <summary>
		/// </summary>
		/// <param name="attribList"> </param>
		/// <param name="elements"> </param>
		/// <returns> </returns>
		public EGLConfig[] ChooseGLConfig( int[] attribList, int[] elements )
		{
			EGLConfig[] configs;
			if ( Javax.Microedition.Khronos.Egl.EGLContext.EGL11.EglChooseConfig( this._glDisplay, attribList, null, 0, elements ) == false )
			{
				throw new AxiomException( "Failed to choose config" );
			}

			configs = new EGLConfig[ Marshal.SizeOf( typeof ( EGLConfig ) ) * elements.Length ];
			if ( Javax.Microedition.Khronos.Egl.EGLContext.EGL11.EglChooseConfig( this._glDisplay, attribList, configs, configs.Length, elements ) == false )
			{
				throw new AxiomException( "Failed to choose config" );
			}

			return configs;
		}
コード例 #15
0
ファイル: AndroidSupport.cs プロジェクト: ryan-bunker/axiom3d
		/// <summary>
		/// </summary>
		/// <param name="glConfig"> </param>
		/// <param name="attribute"> </param>
		/// <param name="value"> </param>
		/// <returns> </returns>
		public bool GetGLConfigAttrib( EGLConfig glConfig, int attribute, int[] value )
		{
			bool status = false;
			status = Javax.Microedition.Khronos.Egl.EGLContext.EGL11.EglGetConfigAttrib( this._glDisplay, glConfig, attribute, value );
			return status;
		}
コード例 #16
0
		public EGLSurface CreatePBufferSurface (EGLConfig config, int[] attribList)
		{
			IEGL10 egl = EGLContext.EGL.JavaCast<IEGL10> ();
			EGLSurface result = egl.EglCreatePbufferSurface (eglDisplay, config, attribList);
			if (result == null || result == EGL10.EglNoSurface)
				throw EglException.GenerateException ("EglCreatePBufferSurface", egl, null);
			return result;
		}
コード例 #17
0
		public void CreatePBufferSurface (EGLConfig config)
		{
			eglSurface = CreatePBufferSurface (config, null);
		}
コード例 #18
0
 public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
 {
     nativeInit(IntPtr.Zero);
 }
コード例 #19
0
		public void CreateSurface (EGLConfig config)
		{
			if (refHolder == null) {
				CreatePBufferSurface (config);
				return;
			}

			IEGL10 egl = EGLContext.EGL.JavaCast<IEGL10> ();
			eglSurface = egl.EglCreateWindowSurface (eglDisplay, config, ((Java.Lang.Object)Holder), null);
			if (eglSurface == null || eglSurface == EGL10.EglNoSurface)
				throw EglException.GenerateException ("EglCreateWindowSurface", egl, null);
		}
コード例 #20
0
 public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
 {
 }
コード例 #21
0
        /**
         * Creates the buffers we use to store information about the 3D world.
         *
         * OpenGL doesn't use Java arrays, but rather needs data in a format it can understand.
         * Hence we use ByteBuffers.
         */
        public void OnSurfaceCreated(Javax.Microedition.Khronos.Egl.EGLConfig config)
        {
            Android.Util.Log.Info(TAG, "onSurfaceCreated");

            GLES20.GlClearColor(0.1f, 0.1f, 0.1f, 0.5f);  // Dark background so text shows up well.

            var bbVertices = ByteBuffer.AllocateDirect(WorldLayoutData.CUBE_COORDS.Length * 4);

            bbVertices.Order(ByteOrder.NativeOrder());
            cubeVertices = bbVertices.AsFloatBuffer();
            cubeVertices.Put(WorldLayoutData.CUBE_COORDS);
            cubeVertices.Position(0);

            var bbColors = ByteBuffer.AllocateDirect(WorldLayoutData.CUBE_COLORS.Length * 4);

            bbColors.Order(ByteOrder.NativeOrder());
            cubeColors = bbColors.AsFloatBuffer();
            cubeColors.Put(WorldLayoutData.CUBE_COLORS);
            cubeColors.Position(0);

            var bbFoundColors = ByteBuffer.AllocateDirect(WorldLayoutData.CUBE_FOUND_COLORS.Length * 4);

            bbFoundColors.Order(ByteOrder.NativeOrder());
            cubeFoundColors = bbFoundColors.AsFloatBuffer();
            cubeFoundColors.Put(WorldLayoutData.CUBE_FOUND_COLORS);
            cubeFoundColors.Position(0);

            var bbNormals = ByteBuffer.AllocateDirect(WorldLayoutData.CUBE_NORMALS.Length * 4);

            bbNormals.Order(ByteOrder.NativeOrder());
            cubeNormals = bbNormals.AsFloatBuffer();
            cubeNormals.Put(WorldLayoutData.CUBE_NORMALS);
            cubeNormals.Position(0);

            // make a floor
            var bbFloorVertices = ByteBuffer.AllocateDirect(WorldLayoutData.FLOOR_COORDS.Length * 4);

            bbFloorVertices.Order(ByteOrder.NativeOrder());
            floorVertices = bbFloorVertices.AsFloatBuffer();
            floorVertices.Put(WorldLayoutData.FLOOR_COORDS);
            floorVertices.Position(0);

            var bbFloorNormals = ByteBuffer.AllocateDirect(WorldLayoutData.FLOOR_NORMALS.Length * 4);

            bbFloorNormals.Order(ByteOrder.NativeOrder());
            floorNormals = bbFloorNormals.AsFloatBuffer();
            floorNormals.Put(WorldLayoutData.FLOOR_NORMALS);
            floorNormals.Position(0);

            var bbFloorColors = ByteBuffer.AllocateDirect(WorldLayoutData.FLOOR_COLORS.Length * 4);

            bbFloorColors.Order(ByteOrder.NativeOrder());
            floorColors = bbFloorColors.AsFloatBuffer();
            floorColors.Put(WorldLayoutData.FLOOR_COLORS);
            floorColors.Position(0);

            int vertexShader      = loadGLShader(GLES20.GlVertexShader, Resource.Raw.light_vertex);
            int gridShader        = loadGLShader(GLES20.GlFragmentShader, Resource.Raw.grid_fragment);
            int passthroughShader = loadGLShader(GLES20.GlFragmentShader, Resource.Raw.passthrough_fragment);

            cubeProgram = GLES20.GlCreateProgram();
            GLES20.GlAttachShader(cubeProgram, vertexShader);
            GLES20.GlAttachShader(cubeProgram, passthroughShader);
            GLES20.GlLinkProgram(cubeProgram);
            GLES20.GlUseProgram(cubeProgram);

            CheckGLError("Cube program");

            cubePositionParam = GLES20.GlGetAttribLocation(cubeProgram, "a_Position");
            cubeNormalParam   = GLES20.GlGetAttribLocation(cubeProgram, "a_Normal");
            cubeColorParam    = GLES20.GlGetAttribLocation(cubeProgram, "a_Color");

            cubeModelParam               = GLES20.GlGetUniformLocation(cubeProgram, "u_Model");
            cubeModelViewParam           = GLES20.GlGetUniformLocation(cubeProgram, "u_MVMatrix");
            cubeModelViewProjectionParam = GLES20.GlGetUniformLocation(cubeProgram, "u_MVP");
            cubeLightPosParam            = GLES20.GlGetUniformLocation(cubeProgram, "u_LightPos");

            CheckGLError("Cube program params");

            floorProgram = GLES20.GlCreateProgram();
            GLES20.GlAttachShader(floorProgram, vertexShader);
            GLES20.GlAttachShader(floorProgram, gridShader);
            GLES20.GlLinkProgram(floorProgram);
            GLES20.GlUseProgram(floorProgram);

            CheckGLError("Floor program");

            floorModelParam               = GLES20.GlGetUniformLocation(floorProgram, "u_Model");
            floorModelViewParam           = GLES20.GlGetUniformLocation(floorProgram, "u_MVMatrix");
            floorModelViewProjectionParam = GLES20.GlGetUniformLocation(floorProgram, "u_MVP");
            floorLightPosParam            = GLES20.GlGetUniformLocation(floorProgram, "u_LightPos");

            floorPositionParam = GLES20.GlGetAttribLocation(floorProgram, "a_Position");
            floorNormalParam   = GLES20.GlGetAttribLocation(floorProgram, "a_Normal");
            floorColorParam    = GLES20.GlGetAttribLocation(floorProgram, "a_Color");

            CheckGLError("Floor program params");

            Matrix.SetIdentityM(modelFloor, 0);
            Matrix.TranslateM(modelFloor, 0, 0, -floorDepth, 0);  // Floor appears below user.

            // Avoid any delays during start-up due to decoding of sound files.
            System.Threading.Tasks.Task.Run(() => {
                // Start spatial audio playback of SOUND_FILE at the model postion. The returned
                //soundId handle is stored and allows for repositioning the sound object whenever
                // the cube position changes.
                gvrAudioEngine.PreloadSoundFile(SOUND_FILE);
                soundId = gvrAudioEngine.CreateSoundObject(SOUND_FILE);
                gvrAudioEngine.SetSoundObjectPosition(
                    soundId, modelPosition [0], modelPosition [1], modelPosition [2]);
                gvrAudioEngine.PlaySound(soundId, true /* looped playback */);
            });

            UpdateModelPosition();

            CheckGLError("onSurfaceCreated");
        }
コード例 #22
0
        private EGLConfig ChooseConfigEGL(EGLConfig[] configs)
        {
            if(configs.Length == 0)
                throw new NotSupportedException("The graphic device configuration demanded is not supported.");

            var readableConfigs = new UserReadableEglConfig[configs.Length];

            // convert the configs into user readable configs
            for (int i = 0; i < configs.Length; i++)
                readableConfigs[i] = EglConfigToUserReadableEglConfig(configs[i]);

            return configs[0];
        }
コード例 #23
0
		// This method is called everytime the context needs
		// to be recreated. Use it to set any egl-specific settings
		// prior to context creation
		protected override void CreateFrameBuffer ()
		{
			IEGL10 egl = EGLContext.EGL.JavaCast<IEGL10> ();
			var win = new AndroidWindow (Holder);
			win.InitializeDisplay ();

			int[] num_configs = new int[1];
			if (!egl.EglGetConfigs (win.Display, null, 0, num_configs)) {
				throw EglException.GenerateException ("Failed to retrieve GraphicsMode configurations", egl);
			}

			EGLConfig[] configs = new EGLConfig[num_configs[0]];
			if (!egl.EglGetConfigs (win.Display, configs, num_configs[0], num_configs)) {
				throw EglException.GenerateException ("Failed to retrieve GraphicsMode configurations", egl);
			}

			Log.Verbose ("GLDiag", "Testing {0} graphics configurations", num_configs[0]);

			Dictionary<IntPtr, AndroidGraphicsMode> validModes = new Dictionary<IntPtr, AndroidGraphicsMode> ();

			int count = 0;
			foreach (var c in configs) {
				var r = GetAttrib (egl, win.Display, c, EGL11.EglRedSize);
				var g = GetAttrib (egl, win.Display, c, EGL11.EglGreenSize);
				var b = GetAttrib (egl, win.Display, c, EGL11.EglBlueSize);
				var a = GetAttrib (egl, win.Display, c, EGL11.EglAlphaSize);
				var depth = GetAttrib (egl, win.Display, c, EGL11.EglDepthSize);
				var stencil = GetAttrib (egl, win.Display, c, EGL11.EglStencilSize);
				var s = GetAttrib (egl, win.Display, c, EGL11.EglSampleBuffers);
				var samples = GetAttrib (egl, win.Display, c, EGL11.EglSamples);

				Log.Verbose ("AndroidGraphicsMode", "Testing graphics mode: {8} red {0} green {1} blue {2} alpha {3} ({4}) depth {5} stencil {6} samples {7}",
						r, g, b,
						a, r+g+b+a, depth,
						stencil, samples, count++);

				try {
					win.CreateSurface (c);
					win.DestroySurface ();
					validModes.Add (c.Handle, new AndroidGraphicsMode (r+g+b+a, depth, stencil, s > 0 ? samples : 0, 2, true));
					Log.Verbose ("AndroidGraphicsMode", "Graphics mode {0} valid", count-1);
				} catch {
					Log.Verbose ("AndroidGraphicsMode", "Graphics mode {0} invalid", count-1);
				}
			}

			win.TerminateDisplay ();

			if (validModes.Count == 0)
				throw new EglException ("There is no valid graphics mode, aborting");

			IntPtr key = IntPtr.Zero;
			foreach (var k in validModes) {
				if (key == IntPtr.Zero)
					key = k.Key;
				var a = k.Value;
				Log.Verbose ("AndroidGraphicsMode", "Valid graphics mode: {9} red {0} green {1} blue {2} alpha {3} ({4}) depth {5} stencil {6} samples {7} buffers {8}",
						a.ColorFormat.Red, a.ColorFormat.Green, a.ColorFormat.Blue,
						a.ColorFormat.Alpha, a.ColorFormat.BitsPerPixel, a.Depth,
						a.Stencil, a.Samples, a.Buffers, (int)k.Key);
			}

			GraphicsMode = validModes[key];

			// if you don't call this, the context won't be created
			base.CreateFrameBuffer ();
		}
コード例 #24
0
		int GetAttrib (IEGL10 egl, EGLDisplay display, EGLConfig config, int attrib)
		{
			int[] ret = new int [1];
			try {
				egl.EglGetConfigAttrib (display, config, attrib, ret);
			} catch (Exception e) {
				Log.Warn ("AndroidGraphicsMode", "EglGetConfigAttrib {0} threw exception {1}", attrib, e);
			}
			return ret[0];
		}
コード例 #25
0
		void ChooseConfig (EGLDisplay display)
		{
#if LOGGING
			Log.Verbose ("AndroidGraphicsMode", "Requested graphics mode on display {7} with red {0} green {1} blue {2} alpha {3} depth {4} stencil {5} buffers {6}",
					ColorFormat.Red, ColorFormat.Green, ColorFormat.Blue, ColorFormat.Alpha, Depth, Stencil, Buffers, display);
#endif

			var egl = EGLContext.EGL.JavaCast<IEGL10> ();

			try {
				if (display == null)
					display = egl.EglGetDisplay (EGL11.EglDefaultDisplay);
			} catch {
				throw EglException.GenerateException ("Failed to get default display", egl, null);
			}

			List<int> configSpec = new List<int> {
			};

			if (ColorFormat.Red > 0) {
				configSpec.Add (EGL11.EglRedSize);
				configSpec.Add (ColorFormat.Red);
			}

			if (ColorFormat.Green > 0) {
				configSpec.Add (EGL11.EglGreenSize);
				configSpec.Add (ColorFormat.Green);
			}

			if (ColorFormat.Blue > 0) {
				configSpec.Add (EGL11.EglBlueSize);
				configSpec.Add (ColorFormat.Blue);
			}

			if (ColorFormat.Alpha > 0) {
				configSpec.Add (EGL11.EglAlphaSize);
				configSpec.Add (ColorFormat.Alpha);
			}

			if (Depth > 0) {
				configSpec.Add (EGL11.EglDepthSize);
				configSpec.Add (Depth);
			}

			if (Stencil > 0) {
				configSpec.Add (EGL11.EglStencilSize);
				configSpec.Add (Stencil);
			}
			//http://code.google.com/p/gdc2011-android-opengl/source/browse/trunk/src/com/example/gdc11/MultisampleConfigChooser.java?r=5
			if (Samples > 0) {
				// Enable Multi Sampling if we can
				configSpec.Add (EGL11.EglSampleBuffers);
				configSpec.Add (1);
				configSpec.Add (EGL11.EglSamples);
				configSpec.Add (Samples);
			}

			if (Version > 1) {
				configSpec.Add (EGL11.EglRenderableType);
				configSpec.Add (4);
			}

			configSpec.Add (EGL11.EglNone);

			int[] num_configs = new int[1];
			if (!egl.EglGetConfigs (display, null, 0, num_configs) || num_configs[0] < 1) {
				throw EglException.GenerateException ("Failed to retrieve GraphicsMode configurations", egl, null);
			}

			EGLConfig[] configs = new EGLConfig[1];
			if (!egl.EglChooseConfig (display, configSpec.ToArray(), configs, configs.Length, num_configs)) {
				Log.Warn ("AndroidGraphicsMode", "Failed to choose GraphicsMode with red {0} green {1} blue {2} alpha {3} depth {4} stencil {5} buffers {6}: egl error {7}. Falling back go lowest configuration available.",
				ColorFormat.Red, ColorFormat.Green, ColorFormat.Blue, ColorFormat.Alpha, Depth, Stencil, Buffers, egl.EglGetError ());

				configSpec = new List<int> {
					EGL11.EglRedSize, 4,
					EGL11.EglGreenSize, 4,
					EGL11.EglBlueSize, 4,
					EGL11.EglNone
				};

				if (!egl.EglChooseConfig (display, configSpec.ToArray(), configs, configs.Length, num_configs)) {
					throw EglException.GenerateException ("Failed to find a valid GraphicsMode configuration", egl, null);
				}
			}

			EGLConfig active_config = configs[0];

#if LOGGING
			Log.Verbose ("AndroidGraphicsMode", "Checking selected config {0}", active_config);
#endif

			if (active_config == null)
				throw EglException.GenerateException ("Failed to find a valid GraphicsMode configuration", egl, null);

			var r = GetAttrib (egl, display, active_config, EGL11.EglRedSize);
			var g = GetAttrib (egl, display, active_config, EGL11.EglGreenSize);
			var b = GetAttrib (egl, display, active_config, EGL11.EglBlueSize);
			var a = GetAttrib (egl, display, active_config, EGL11.EglAlphaSize);
			var depth = GetAttrib (egl, display, active_config, EGL11.EglDepthSize);
			var stencil = GetAttrib (egl, display, active_config, EGL11.EglStencilSize);
			var s = GetAttrib (egl, display, active_config, EGL11.EglSampleBuffers);
			var samples = GetAttrib (egl, display, active_config, EGL11.EglSamples);
			var bufs = GetAttrib (egl, display, active_config, EGL11.EglRenderBuffer);
			var surfaceType = GetAttrib (egl, display, active_config, EGL11.EglSurfaceType);

#if LOGGING
			Log.Verbose ("AndroidGraphicsMode", "Requested graphics mode with red {0} green {1} blue {2} alpha {3} depth {4} stencil {5} buffers {6} samples {7}",
					ColorFormat.Red, ColorFormat.Green, ColorFormat.Blue, ColorFormat.Alpha, Depth, Stencil, Buffers, Samples);
#endif

			this.Index = active_config.Handle;
			this.ColorFormat = new ColorFormat (r, g, b, a);
			this.Depth = depth;
			this.Stencil = stencil;
			this.Samples = s > 0 ? samples : 0;
			this.Config = active_config;
			this.Buffers = bufs;
			this.PBufferSupported = (surfaceType & EGL11.EglPbufferBit) == EGL11.EglPbufferBit;

#if LOGGING
			Log.Verbose ("AndroidGraphicsMode", "Selected  graphics mode with red {0} green {1} blue {2} alpha {3} depth {4} stencil {5} buffers {6}, samples {7}",
					ColorFormat.Red, ColorFormat.Green, ColorFormat.Blue, ColorFormat.Alpha, Depth, Stencil, Buffers, Samples);
#endif
		}
コード例 #26
0
        private void CreateEGLContext()
        {
            ExEnLog.WriteLine("ExEnAndroidSurfaceView.CreateEGLContext Begin");

            // Assumes lockObject is locked

            lostEglContext = false;

            egl = EGLContext.EGL.JavaCast<IEGL10>();

            eglDisplay = egl.EglGetDisplay(EGL10Consts.EglDefaultDisplay);
            if(eglDisplay == EGL10Consts.EglNoDisplay)
                throw new ExEnSurfaceException("Could not get EGL display");

            int[] version = new int[2];
            if(!egl.EglInitialize(eglDisplay, version))
                throw new ExEnSurfaceException(AddEGLError("Could not initialize EGL display"));

            ExEnLog.WriteLine("EGL Version: " + version[0] + "." + version[1]);

            // TODO: allow GraphicsDeviceManager to specify a frame buffer configuration
            // TODO: test this configuration works on many devices:
            int[] configAttribs = new int[] {
                    //EGL10Consts.EglRedSize, 5,
                    //EGL10Consts.EglGreenSize, 6,
                    //EGL10Consts.EglBlueSize, 5,
                    //EGL10Consts.EglAlphaSize, 0,
                    //EGL10Consts.EglDepthSize, 4,
                    //EGL10Consts.EglStencilSize, 0,
                    EGL10Consts.EglNone };
            EGLConfig[] configs = new EGLConfig[1];
            int[] numConfigs = new int[1];
            if(!egl.EglChooseConfig(eglDisplay, configAttribs, configs, 1, numConfigs))
                throw new ExEnSurfaceException(AddEGLError("Could not get EGL config"));
            if(numConfigs[0] == 0)
                throw new ExEnSurfaceException("No valid EGL configs found");
            eglConfig = configs[0];

            const int EglContextClientVersion = 0x3098;
            int[] contextAttribs = new int[] { EglContextClientVersion, 1, EGL10Consts.EglNone };
            eglContext = egl.EglCreateContext(eglDisplay, eglConfig, EGL10Consts.EglNoContext, contextAttribs);
            if(eglContext == null || eglContext == EGL10Consts.EglNoContext)
            {
                eglContext = null;
                throw new ExEnSurfaceException(AddEGLError("Could not create EGL context"));
            }

            eglContextAvailable = true;

            ExEnLog.WriteLine("ExEnAndroidSurfaceView.CreateEGLContext End");
        }
コード例 #27
0
        private UserReadableEglConfig EglConfigToUserReadableEglConfig(EGLConfig eglConfig)
        {
            var surfaceType = new int[1];
            var renderableType = new int[1];
            var redSize = new int[1];
            var greenSize = new int[1];
            var blueSize = new int[1];
            var alphaSize = new int[1];
            var depthSize = new int[1];
            var stencilSize = new int[1];
            var samples = new int[1];

            if (!egl.EglGetConfigAttrib(EGLDisplay, eglConfig, EGL10.EglSurfaceType, surfaceType))
                throw new InvalidOperationException(string.Format("EglGetConfigAttrib {0:x}", egl.EglGetError()));
            if (!egl.EglGetConfigAttrib(EGLDisplay, eglConfig, EGL10.EglRenderableType, renderableType))
                throw new InvalidOperationException(string.Format("EglGetConfigAttrib {0:x}", egl.EglGetError()));
            if (!egl.EglGetConfigAttrib(EGLDisplay, eglConfig, EGL10.EglRedSize, redSize))
                throw new InvalidOperationException(string.Format("EglGetConfigAttrib {0:x}", egl.EglGetError()));
            if (!egl.EglGetConfigAttrib(EGLDisplay, eglConfig, EGL10.EglGreenSize, greenSize))
                throw new InvalidOperationException(string.Format("EglGetConfigAttrib {0:x}", egl.EglGetError()));
            if (!egl.EglGetConfigAttrib(EGLDisplay, eglConfig, EGL10.EglBlueSize, blueSize))
                throw new InvalidOperationException(string.Format("EglGetConfigAttrib {0:x}", egl.EglGetError()));
            if (!egl.EglGetConfigAttrib(EGLDisplay, eglConfig, EGL10.EglAlphaSize, alphaSize))
                throw new InvalidOperationException(string.Format("EglGetConfigAttrib {0:x}", egl.EglGetError()));
            if (!egl.EglGetConfigAttrib(EGLDisplay, eglConfig, EGL10.EglDepthSize, depthSize))
                throw new InvalidOperationException(string.Format("EglGetConfigAttrib {0:x}", egl.EglGetError()));
            if (!egl.EglGetConfigAttrib(EGLDisplay, eglConfig, EGL10.EglStencilSize, stencilSize))
                throw new InvalidOperationException(string.Format("EglGetConfigAttrib {0:x}", egl.EglGetError()));
            if (!egl.EglGetConfigAttrib(EGLDisplay, eglConfig, EGL10.EglSamples, samples))
                throw new InvalidOperationException(string.Format("EglGetConfigAttrib {0:x}", egl.EglGetError()));

            return new UserReadableEglConfig
                {
                    SurfaceType = surfaceType[0],
                    RenderableType = renderableType[0],
                    RedSize = redSize[0],
                    GreenSize = greenSize[0],
                    BlueSize = blueSize[0],
                    AlphaSize = alphaSize[0],
                    DepthSize = depthSize[0],
                    StencilSize = stencilSize[0],
                    Samples = samples[0]
                };
        }
コード例 #28
0
 public void OnSurfaceCreated(IGL10 gl, EGLConfig config)
 {
     nativeInit(IntPtr.Zero);
 }
コード例 #29
0
        internal AndroidAsyncGraphicsContext(AndroidGraphicsContext graphicsContext, AndroidWindow androidWindow, int versionMajor)
        {
            egl = EGLContext.EGL.JavaCast<IEGL10>();

            var pbufferAttribList = new[] 
                {
                    EGL10.EglWidth, 1,
                    EGL10.EglHeight, 1,
                    EGL10.EglNone
                };

            EGLDisplay = androidWindow.Display;
            var androidGraphicsContext = graphicsContext;
            var config = androidGraphicsContext.EGLConfig;

            var attribList = new[] 
                { 
                    EGL10.EglSurfaceType, EGL10.EglPbufferBit,
                    EGL10.EglRenderableType, 4, // (opengl es 2.0)
            
                    EGL10.EglRedSize, graphicsContext.GraphicsMode.ColorFormat.Red,
                    EGL10.EglGreenSize, graphicsContext.GraphicsMode.ColorFormat.Green,
                    EGL10.EglBlueSize, graphicsContext.GraphicsMode.ColorFormat.Blue,
                    EGL10.EglAlphaSize, graphicsContext.GraphicsMode.ColorFormat.Alpha,
            
                    EGL10.EglDepthSize, graphicsContext.GraphicsMode.Depth,
                    EGL10.EglStencilSize, graphicsContext.GraphicsMode.Stencil,
            
                    //Egl.SAMPLE_BUFFERS, samples > 0 ? 1 : 0,
                    EGL10.EglSamples, 0,
            
                    EGL10.EglNone,
                };

            // first ask the number of config available
            var numConfig = new int[1];
            if (!egl.EglChooseConfig(EGLDisplay, attribList, null, 0, numConfig))
            {
                throw new InvalidOperationException(string.Format("EglChooseConfig {0:x}", egl.EglGetError()));
            }

            // retrieve the available configs
            var configs = new EGLConfig[numConfig[0]];
            if (!egl.EglChooseConfig(EGLDisplay, attribList, configs, configs.Length, numConfig))
            {
                throw new InvalidOperationException(string.Format("EglChooseConfig {0:x}", egl.EglGetError()));
            }

            // choose the best config
            EGLConfig = ChooseConfigEGL(configs);

            // create the surface
            EGLSurface = egl.EglCreatePbufferSurface(EGLDisplay, EGLConfig, pbufferAttribList);
            if (EGLSurface == EGL10.EglNoSurface)
            {
                throw new InvalidOperationException(string.Format("EglCreatePBufferSurface {0:x}", egl.EglGetError()));
            }

            // 0x3098 is EGL_CONTEXT_CLIENT_VERSION
            var attribList3 = new[] { 0x3098, versionMajor, EGL10.EglNone };
            EGLContext = egl.EglCreateContext(EGLDisplay, config, androidGraphicsContext.EGLContext, attribList3);
            if (EGLContext == EGL10.EglNoContext)
            {
                throw new InvalidOperationException(string.Format("EglCreateContext {0:x}", egl.EglGetError()));
            }
        }
コード例 #30
0
 public void OnSurfaceCreated(Javax.Microedition.Khronos.Egl.EGLConfig paramEGLConfig)
 {
     mStereoRenderer.OnSurfaceCreated(paramEGLConfig);
 }