示例#1
0
        public bool Run(SdlContext context)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            lock (this.syncRoot) {
                if (this.isRunning)
                {
                    return(false);
                }

                try {
                    this.isRunning = true;
                    Monitor.Exit(this.syncRoot);
                    try {
                        this.context = context;
                        this.PrepareRegisters();

                        this.RunInternal();
                        return(true);
                    }
                    finally {
                        Monitor.Enter(this.syncRoot);
                    }
                }
                finally {
                    this.isRunning = false;
                    this.context   = null;
                    this.ClearRegisters();
                }
            }
        }
示例#2
0
        internal GraphicsAdapter()
        {
            outputs = new [] { new GraphicsOutput() };

            // set default values
            int detectedVersion = 100;

            string renderer, vendor, version;
            int    versionMajor, versionMinor;

            var SDL = Stride.Graphics.SDL.Window.SDL;
            // Some platforms (i.e. Android) can only have a single window
            var sdlWindow = DefaultWindow;

            if (sdlWindow == null)
            {
                sdlWindow = SDL.CreateWindow("Stride Hidden OpenGL", 50, 50, 1280, 720, (uint)(WindowFlags.WindowHidden | WindowFlags.WindowOpengl));
            }

            using (var sdlContext = new SdlContext(SDL, sdlWindow))
                using (var gl = GL.GetApi(sdlContext))
                {
#if STRIDE_GRAPHICS_API_OPENGLES
                    SDL.GLSetAttribute(GLattr.GLContextProfileMask, (int)GLprofile.GLContextProfileES);
#else
                    SDL.GLSetAttribute(GLattr.GLContextProfileMask, (int)GLprofile.GLContextProfileCore);
#endif
                    sdlContext.Create();
                    renderer = gl.GetStringS(StringName.Renderer);
                    vendor   = gl.GetStringS(StringName.Vendor);
                    version  = gl.GetStringS(StringName.Version);
                    gl.GetInteger(GetPName.MajorVersion, out versionMajor);
                    gl.GetInteger(GetPName.MinorVersion, out versionMinor);
                }
            if (sdlWindow != DefaultWindow)
            {
                SDL.DestroyWindow(sdlWindow);
            }

            // Stay close to D3D: Cut renderer after first / (ex: "GeForce 670/PCIe/SSE2")
            var rendererSlash = renderer.IndexOf('/');

            if (rendererSlash != -1)
            {
                renderer = renderer.Substring(0, rendererSlash);
            }

            // Stay close to D3D: Remove "Corporation" from vendor
            vendor = vendor.Replace(" Corporation", string.Empty);

            // Generate adapter Description
            Description = $"{vendor} {renderer}";

            // get real values
            // Note: using glGetIntegerv(GL_MAJOR_VERSION / GL_MINOR_VERSION) only works on opengl (es) >= 3.0
            detectedVersion          = versionMajor * 100 + versionMinor * 10;
            supportedGraphicsProfile = OpenGLUtils.GetFeatureLevel(detectedVersion);

            OpenGLVersion  = detectedVersion;
            OpenGLRenderer = renderer;
        }