コード例 #1
0
 public void MakeCurrent()
 {
     if (EGL.MakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext) == false)
     {
         throw new Exception("Failed to make EGLSurface current");
     }
 }
コード例 #2
0
 public void DestroySurface()
 {
     if (eglDisplay != EGL.EGL_NO_DISPLAY && eglSurface != EGL.EGL_NO_SURFACE)
     {
         EGL.DestroySurface(eglDisplay, eglSurface);
         eglSurface = EGL.EGL_NO_SURFACE;
     }
 }
コード例 #3
0
        protected EGLBoolean createSurface(EGLConfig config)
        {
            eglSurface = EGL.eglCreateWindowSurface(eglDisplay, config, windType, nullptr);

            if (eglSurface == EGL.EGL_NO_SURFACE)
            {
                return(EGL.EGL_FALSE);
            }

            return(EGL.EGL_TRUE);
        }
コード例 #4
0
        private void Cleanup()
        {
            if (eglDisplay != EGL.EGL_NO_DISPLAY && eglContext != EGL.EGL_NO_CONTEXT)
            {
                EGL.DestroyContext(eglDisplay, eglContext);
                eglContext = EGL.EGL_NO_CONTEXT;
            }

            if (eglDisplay != EGL.EGL_NO_DISPLAY)
            {
                EGL.Terminate(eglDisplay);
                eglDisplay = EGL.EGL_NO_DISPLAY;
            }
        }
コード例 #5
0
        public void CreateSurface(SwapChainPanel panel, Size?renderSurfaceSize, float?resolutionScale)
        {
            if (panel == null)
            {
                throw new ArgumentNullException("SwapChainPanel parameter is invalid");
            }

            EGLSurface surface = EGL.EGL_NO_SURFACE;

            int[] surfaceAttributes = new[]
            {
                // EGL_ANGLE_SURFACE_RENDER_TO_BACK_BUFFER is part of the same optimization as EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER (see above).
                // If you have compilation issues with it then please update your Visual Studio templates.
                EGLX.EGL_ANGLE_SURFACE_RENDER_TO_BACK_BUFFER, EGL.EGL_TRUE,
                EGL.EGL_NONE
            };

            // Create a PropertySet and initialize with the EGLNativeWindowType.
            PropertySet surfaceCreationProperties = new PropertySet();

            surfaceCreationProperties.Add(SkiaEGL.EGLNativeWindowTypeProperty, panel);

            // If a render surface size is specified, add it to the surface creation properties
            if (renderSurfaceSize.HasValue)
            {
                PropertySetExtensions.AddSize(surfaceCreationProperties, SkiaEGL.EGLRenderSurfaceSizeProperty, renderSurfaceSize.Value);
            }

            // If a resolution scale is specified, add it to the surface creation properties
            if (resolutionScale.HasValue)
            {
                PropertySetExtensions.AddSingle(surfaceCreationProperties, SkiaEGL.EGLRenderResolutionScaleProperty, resolutionScale.Value);
            }

            surface = EGL.CreateWindowSurface(eglDisplay, eglConfig, surfaceCreationProperties, surfaceAttributes);
            if (surface == EGL.EGL_NO_SURFACE)
            {
                throw new Exception("Failed to create EGL surface");
            }

            eglSurface = surface;
        }
コード例 #6
0
        protected EGLBoolean createEGLEnv()
        {
            EGLint numConfigs = 0;

            EGLint[] contextAttribs = { EGL.EGL_CONTEXT_CLIENT_VERSION, 2, EGL.EGL_NONE, EGL.EGL_NONE };

            eglDisplay = EGL.eglGetDisplay(EGL.EGL_DEFAULT_DISPLAY);

            if (eglDisplay == EGL.EGL_NO_DISPLAY)
            {
                return(EGL.EGL_FALSE);
            }

            if (EGL.eglInitialize(eglDisplay, ref majorVersion, ref minorVersion) == EGL.EGL_FALSE)
            {
                return(EGL.EGL_FALSE);
            }


            if (EGL.eglGetConfigs(eglDisplay, nullptr, 0, ref numConfigs) == EGL.EGL_FALSE)
            {
                return(EGL.EGL_FALSE);
            }

            if (chooseConfig(ref config, ref numConfigs) == 0)
            {
                return(EGL.EGL_FALSE);
            }

            if (createSurface(config) == EGL.EGL_FALSE)
            {
                return(EGL.EGL_FALSE);
            }

            eglContext = EGL.eglCreateContext(eglDisplay, config, EGL.EGL_NO_CONTEXT, contextAttribs);
            if (eglContext == EGL.EGL_NO_CONTEXT)
            {
                return(EGL.EGL_FALSE);
            }
            ;
            return(UseContext());
        }
コード例 #7
0
        protected EGLBoolean chooseConfig(ref EGLConfig config, ref EGLint numConfigs)
        {
            EGLint[] attribList =
            {
                EGL.EGL_RED_SIZE,       8,
                EGL.EGL_GREEN_SIZE,     8,
                EGL.EGL_BLUE_SIZE,      8,
                EGL.EGL_ALPHA_SIZE,     8,
                EGL.EGL_DEPTH_SIZE,     8,
                EGL.EGL_STENCIL_SIZE,   8,
                EGL.EGL_SAMPLE_BUFFERS, 1,
                EGL.EGL_SAMPLES,        4,
                EGL.EGL_NONE
            };
            if (EGL.eglChooseConfig(eglDisplay, attribList, ref config, 1, ref numConfigs) == EGL.EGL_FALSE)
            {
                int err = EGL.eglGetError();
                return(EGL.EGL_FALSE);
            }

            return(EGL.EGL_TRUE);
        }
コード例 #8
0
ファイル: EGLSupport.cs プロジェクト: bostich83/axiom
 public override void Stop()
 {
     EGL.Terminate(GlDisplay);
     GLES2Config.GlCheckError(this);
 }
コード例 #9
0
        void DrawGUI_Android(P.Params currentParams)
        {
            int opt = currentParams.platformOption;

            //bool fold;


            //using( new GUILayout.VerticalScope( s_styles.HelpBox ) ) {
            //	using( new GUILayout.HorizontalScope() ) {
            //		EditorGUI.BeginChangeCheck();
            //		fold = EditorGUILayout.Foldout( BuildManagerSettingsEditor.i.fold.Has( BuildManagerSettingsEditor.FoldPlatform ), "Player Settings", s_styles.Foldout );
            //		BuildManagerSettingsEditor.i.fold.Toggle( BuildManagerSettingsEditor.FoldPlatform, fold );
            //		if( EditorGUI.EndChangeCheck() ) s_changed = true;

            //		GUILayout.FlexibleSpace();
            //		var r = GUILayoutUtility.GetRect( 20, 18 );
            //		GUI.Label( r, s_styles.Settings, s_styles.Icon );
            //		if( EditorHelper.HasMouseClick( GUILayoutUtility.GetLastRect() ) ) {
            //			Selection.activeObject = AssetDatabase.LoadAssetAtPath<UnityObject>( AssetDatabase.GUIDToAssetPath( "00000000000000004000000000000000" ) );
            //			EditorUtils.InspectorWindow().Focus();
            //			Event.current.Use();
            //		}
            //	}

            //	EditorGUI.BeginChangeCheck();
            //	if( fold ) {
            //		EditorGUI.indentLevel++;
            //		currentParams.scriptingBackend = (ScriptingImplementation) EditorGUILayout.Popup( L.Tr( "ScriptingBackend" ), (int) currentParams.scriptingBackend, s_scriptingBackend );
            //		using( new EditorGUI.DisabledGroupScope( currentParams.scriptingBackend == ScriptingImplementation.Mono2x ) ) {
            //			currentParams.il2CppCompilerConfiguration = (Il2CppCompilerConfiguration) EditorGUILayout.EnumPopup( L.Tr( "C++ Compiler Configuration" ), currentParams.il2CppCompilerConfiguration );
            //		}
            //		EditorGUILayout.LabelField( $"{L.Tr( "Scripting Define Symbols" )} ({L.Tr( "Additional" )})" );
            //		currentParams.scriptingDefineSymbols = EditorGUILayout.TextField( currentParams.scriptingDefineSymbols );
            //		EditorGUILayout.LabelField( $"{L.Tr( "Scripting Define Symbols" )} ({L.Tr( "Current" )})" );
            //		EditorGUI.BeginDisabledGroup( true );
            //		EditorGUILayout.TextField( B.scriptingDefineSymbols );
            //		EditorGUI.EndDisabledGroup();
            //		EditorGUI.indentLevel--;
            //		GUILayout.Space( 4 );
            //	}
            //	if( EditorGUI.EndChangeCheck() ) {
            //		currentParams.platformOption = opt;
            //		s_changed = true;
            //	}
            //}

            GUILayout.Space(4);
            DrawGUI_3rdpartySettings();
#if false //保留
            currentParams.DEBUG_LOG                 = EGL.Toggle("DEBUG_LOG", currentParams.DEBUG_LOG);
            BuildManagerPreference.i.adb_exe        = EGL.TextField("adb.exe", BuildManagerPreference.i.adb_exe);
            BuildManagerPreference.i.bundletool_jar = EGL.TextField("bundletool", BuildManagerPreference.i.bundletool_jar);
            using (new GL.HorizontalScope()) {
                GL.FlexibleSpace();
                GL.Button("Install on device");
                GL.Button("Launch on device");
            }
#endif
            GUILayout.Space(4);

            EditorGUI.BeginChangeCheck();
            using (new GUILayout.HorizontalScope()) {
                GUILayout.Label($"Version", EditorStyles.label);
                GUILayout.Label($"{PlayerSettings.bundleVersion}", EditorStyles.label);
                var a = GUILayoutUtility.GetLastRect();
                a.x += a.width;

                a.width  = 8;
                a.height = 8;
                //a.x -= 6;
                var rcU = a;
                rcU.y -= 0;
                var rcD = a;
                rcD.y += 0 + a.height;

                if (GUI.Button(rcU, Styles.iconAllowUp, Styles.icon))
                {
                    var f = float.Parse(PlayerSettings.bundleVersion);
                    int i = (int)((f * 100.0f + 0.5f));
                    i += 100;
                    f  = ((float)i) / 100.0f;
                    PlayerSettings.bundleVersion = f.ToString("F2");
                }
                if (GUI.Button(rcD, Styles.iconAllowDown, Styles.icon))
                {
                    var f = float.Parse(PlayerSettings.bundleVersion);
                    int i = (int)((f * 100.0f + 0.5f));
                    i -= 100;
                    f  = ((float)i) / 100.0f;
                    PlayerSettings.bundleVersion = f.ToString("F2");
                }
                rcU.x += 8;
                rcD.x += 8;
                if (GUI.Button(rcU, Styles.iconAllowUp, Styles.icon))
                {
                    var f = float.Parse(PlayerSettings.bundleVersion);
                    int i = (int)((f * 100.0f + 0.5f));
                    i++;
                    f = ((float)i) / 100.0f;
                    PlayerSettings.bundleVersion = f.ToString("F2");
                }
                if (GUI.Button(rcD, Styles.iconAllowDown, Styles.icon))
                {
                    var f = float.Parse(PlayerSettings.bundleVersion);
                    int i = (int)((f * 100.0f + 0.5f));
                    i--;
                    f = ((float)i) / 100.0f;
                    PlayerSettings.bundleVersion = f.ToString("F2");
                }

                GUILayout.Space(20);

                GUILayout.Label($"Bundle Version Code", EditorStyles.label);
                GUILayout.Label($"{PlayerSettings.Android.bundleVersionCode}", EditorStyles.label);
                a        = GUILayoutUtility.GetLastRect();
                a.x     += a.width;
                a.width  = 8;
                a.height = 8;

                rcU    = a;
                rcU.y -= 0;
                rcD    = a;
                rcD.y += 0 + a.height;

                if (GUI.Button(rcU, Styles.iconAllowUp, Styles.icon))
                {
                    PlayerSettings.Android.bundleVersionCode++;
                }
                if (GUI.Button(rcD, Styles.iconAllowDown, Styles.icon))
                {
                    PlayerSettings.Android.bundleVersionCode--;
                }

                GUILayout.FlexibleSpace();
            }

            if (EditorGUI.EndChangeCheck())
            {
                s_changed = true;
            }

            bool once = false;

            void errorLabel(string s, string icon = "")
            {
                var c = EditorStyles.label.normal.textColor;

                EditorStyles.label.normal.textColor = Color.red;
                EditorStyles.label.fontStyle        = FontStyle.Bold;

                GUILayout.Label(EditorHelper.TempContent(s, Icon.Get(icon)), EditorStyles.label);

                EditorStyles.label.fontStyle        = FontStyle.Normal;
                EditorStyles.label.normal.textColor = c;
            }

            void errorTitle()
            {
                if (once)
                {
                    return;
                }
                errorLabel(L.Tr("PlayerSettings.Android settings are incomplete"), "console.erroricon.sml");
                once = true;
            }

            if (PlayerSettings.Android.bundleVersionCode == 0)
            {
                errorTitle();
                errorLabel(L.Tr($"If BundleVersionCode is 0, a build error occurs"));
            }

            if (B.applicationIdentifier.IsEmpty())
            {
                errorTitle();
                errorLabel(L.Tr($"PackageName of Identification is empty"));
            }
            else if (B.applicationIdentifier == "com.Company.ProductName")
            {
                errorTitle();
                errorLabel(L.Tr($"An error occurs if PackageName is \"com.Company.ProductName\""));
            }
            else if (!B.applicationIdentifier.Contains("."))
            {
                errorTitle();
                errorLabel(L.Tr($"PackageName must be separated by at least one .(Dot)"));
            }
            else if (B.applicationIdentifier[0] == '.')
            {
                errorTitle();
                errorLabel(L.Tr($"An error occurs if PackageName starts with a .(Dot)"));
            }
            else if (B.applicationIdentifier[B.applicationIdentifier.Length - 1] == '.')
            {
                errorTitle();
                errorLabel(L.Tr($"An error occurs if the end of PackageName is .(Dot)"));
            }
        }
コード例 #10
0
        private void Initialize()
        {
            int[] configAttributes = new[]
            {
                EGL.EGL_RED_SIZE, 8,
                EGL.EGL_GREEN_SIZE, 8,
                EGL.EGL_BLUE_SIZE, 8,
                EGL.EGL_ALPHA_SIZE, 8,
                EGL.EGL_DEPTH_SIZE, 8,
                EGL.EGL_STENCIL_SIZE, 8,
                EGL.EGL_NONE
            };

            int[] contextAttributes = new[]
            {
                EGL.EGL_CONTEXT_CLIENT_VERSION, 2,
                EGL.EGL_NONE
            };

            int[] defaultDisplayAttributes = new[]
            {
                // These are the default display attributes, used to request ANGLE's D3D11 renderer.
                // eglInitialize will only succeed with these attributes if the hardware supports D3D11 Feature Level 10_0+.
                EGLX.EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGLX.EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,

                // EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER is an optimization that can have large performance benefits on mobile devices.
                // Its syntax is subject to change, though. Please update your Visual Studio templates if you experience compilation issues with it.
                EGLX.EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL.EGL_TRUE,

                // EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE is an option that enables ANGLE to automatically call
                // the IDXGIDevice3::Trim method on behalf of the application when it gets suspended.
                // Calling IDXGIDevice3::Trim when an application is suspended is a Windows Store application certification requirement.
                EGLX.EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE, EGL.EGL_TRUE,
                EGL.EGL_NONE,
            };

            int[] fl9_3DisplayAttributes = new[]
            {
                // These can be used to request ANGLE's D3D11 renderer, with D3D11 Feature Level 9_3.
                // These attributes are used if the call to eglInitialize fails with the default display attributes.
                EGLX.EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGLX.EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
                EGLX.EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, 9,
                EGLX.EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, 3,
                EGLX.EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL.EGL_TRUE,
                EGLX.EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE, EGL.EGL_TRUE,
                EGL.EGL_NONE,
            };

            int[] warpDisplayAttributes = new[]
            {
                // These attributes can be used to request D3D11 WARP.
                // They are used if eglInitialize fails with both the default display attributes and the 9_3 display attributes.
                EGLX.EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGLX.EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
                EGLX.EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, EGLX.EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE,
                EGLX.EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL.EGL_TRUE,
                EGLX.EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE, EGL.EGL_TRUE,
                EGL.EGL_NONE,
            };

            EGLConfig config = IntPtr.Zero;

            //
            // To initialize the display, we make three sets of calls to eglGetPlatformDisplayEXT and eglInitialize, with varying
            // parameters passed to eglGetPlatformDisplayEXT:
            // 1) The first calls uses "defaultDisplayAttributes" as a parameter. This corresponds to D3D11 Feature Level 10_0+.
            // 2) If eglInitialize fails for step 1 (e.g. because 10_0+ isn't supported by the default GPU), then we try again
            //    using "fl9_3DisplayAttributes". This corresponds to D3D11 Feature Level 9_3.
            // 3) If eglInitialize fails for step 2 (e.g. because 9_3+ isn't supported by the default GPU), then we try again
            //    using "warpDisplayAttributes".  This corresponds to D3D11 Feature Level 11_0 on WARP, a D3D11 software rasterizer.
            //

            // This tries to initialize EGL to D3D11 Feature Level 10_0+. See above comment for details.
            eglDisplay = EGLX.GetPlatformDisplayEXT(EGLX.EGL_PLATFORM_ANGLE_ANGLE, EGL.EGL_DEFAULT_DISPLAY, defaultDisplayAttributes);
            if (eglDisplay == EGL.EGL_NO_DISPLAY)
            {
                throw new Exception("Failed to get EGL display");
            }

            if (EGL.Initialize(eglDisplay, out int major, out int minor) == false)
            {
                // This tries to initialize EGL to D3D11 Feature Level 9_3, if 10_0+ is unavailable (e.g. on some mobile devices).
                eglDisplay = EGLX.GetPlatformDisplayEXT(EGLX.EGL_PLATFORM_ANGLE_ANGLE, EGL.EGL_DEFAULT_DISPLAY, fl9_3DisplayAttributes);
                if (eglDisplay == EGL.EGL_NO_DISPLAY)
                {
                    throw new Exception("Failed to get EGL display");
                }

                if (EGL.Initialize(eglDisplay, out major, out minor) == false)
                {
                    // This initializes EGL to D3D11 Feature Level 11_0 on WARP, if 9_3+ is unavailable on the default GPU.
                    eglDisplay = EGLX.GetPlatformDisplayEXT(EGLX.EGL_PLATFORM_ANGLE_ANGLE, EGL.EGL_DEFAULT_DISPLAY, warpDisplayAttributes);
                    if (eglDisplay == EGL.EGL_NO_DISPLAY)
                    {
                        throw new Exception("Failed to get EGL display");
                    }

                    if (EGL.Initialize(eglDisplay, out major, out minor) == false)
                    {
                        // If all of the calls to eglInitialize returned EGL_FALSE then an error has occurred.
                        throw new Exception("Failed to initialize EGL");
                    }
                }
            }

            EGLDisplay_ configs;

            if ((EGL.ChooseConfig(eglDisplay, configAttributes, out configs, 1, out int numConfigs) == false) || (numConfigs == 0))
            {
                throw new Exception("Failed to choose first EGLConfig");
            }
            eglConfig = configs;

            eglContext = EGL.CreateContext(eglDisplay, eglConfig, EGL.EGL_NO_CONTEXT, contextAttributes);
            if (eglContext == EGL.EGL_NO_CONTEXT)
            {
                throw new Exception("Failed to create EGL context");
            }
        }
コード例 #11
0
 public bool SwapBuffers()
 {
     return(EGL.SwapBuffers(eglDisplay, eglSurface) == true);
 }
コード例 #12
0
 public void GetSurfaceDimensions(out int width, out int height)
 {
     EGL.QuerySurface(eglDisplay, eglSurface, EGL.EGL_WIDTH, out width);
     EGL.QuerySurface(eglDisplay, eglSurface, EGL.EGL_HEIGHT, out height);
 }
コード例 #13
0
 public EGLBoolean UseContext()
 {
     return(EGL.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext));
 }
コード例 #14
0
 public void SwapBuffer()
 {
     EGL.eglSwapBuffers(eglDisplay, eglSurface);
 }
コード例 #15
0
 extern static uint eglBindAPI(EGL api); // returns EGLboolean