Ejemplo n.º 1
0
        private void initiateGL()
        {
            String versionString  = GL.GetString(StringName.Version);  //GL11.glGetString(GL11.GL_VERSION);
            String vendorString   = GL.GetString(StringName.Vendor);   //GL11.glGetString(GL11.GL_VENDOR);
            String rendererString = GL.GetString(StringName.Renderer); //GL11.glGetString(GL11.GL_RENDERER);

            glVersion = new GLVersion(ApplicationType.Desktop, versionString, vendorString, rendererString);
        }
Ejemplo n.º 2
0
        private static void initiateGL()
        {
            var versionString  = GL.GetString(StringName.Version);  //GL11.glGetString(GL11.GL_VERSION);
            var vendorString   = GL.GetString(StringName.Vendor);   //GL11.glGetString(GL11.GL_VENDOR);
            var rendererString = GL.GetString(StringName.Renderer); //GL11.glGetString(GL11.GL_RENDERER);

            glVersion = new GLVersion(ApplicationType.Desktop, versionString, vendorString, rendererString);

            Gdx.app.log("Application", $"GL Version: \t{versionString}");
            Gdx.app.log("Application", $"GL Vendor: \t{vendorString}");
            Gdx.app.log("Application", $"GL Renderer: \t{rendererString}");
        }
        public static GLCalls GetGLCalls(GLVersion api)
        {
            switch (api)
            {
            case GLVersion.ES2:
                return(CreateES2());

            case GLVersion.ES3:
                return(CreateES3());
            }
            throw new ArgumentException("api");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates the render context provider. Must also create the OpenGL extensions.
        /// </summary>
        /// <param name="openGLVersion">The desired OpenGL version.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="bitDepth">The bit depth.</param>
        /// <param name="parameter">The extra parameter.</param>
        /// <returns></returns>
        public virtual bool Create(GLVersion openGLVersion, int width, int height, int bitDepth, object parameter)
        {
            //  Set the width, height and bit depth.
            this.Width    = width;
            this.Height   = height;
            this.BitDepth = bitDepth;

            //  For now, assume we're going to be able to create the requested OpenGL version.
            this.RequestedGLVersion = openGLVersion;
            this.CreatedGLVersion   = openGLVersion;

            return(true);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates the render context provider. Must also create the OpenGL extensions.
        /// </summary>
        /// <param name="openGLVersion">The desired OpenGL version.</param>
        /// <param name="gl">The OpenGL context.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="bitDepth">The bit depth.</param>
        /// <param name="parameter">The extra parameter.</param>
        /// <returns></returns>
        public virtual bool Create(GLVersion openGLVersion, int width, int height, int bitDepth, object parameter)
        {
            //  Set the width, height and bit depth.
            Width = width;
            Height = height;
            BitDepth = bitDepth;

            //  For now, assume we're going to be able to create the requested OpenGL version.
            RequestedGLVersion = openGLVersion;
            CreatedGLVersion = openGLVersion;

            return true;
        }
Ejemplo n.º 6
0
 private bool TryCreateFrameBuffer(GLVersion version, ColorFormat requestedColorFormat, int requestedDepth, int requestedStencil)
 {
     try
     {
         ContextRenderingApi = version;
         GraphicsMode        = new GraphicsMode(requestedColorFormat, requestedDepth, requestedStencil);
         base.CreateFrameBuffer();
         return(true);
     }
     catch (Exception)
     {
         base.DestroyFrameBuffer(); // Destroy to prevent side effects on future calls to CreateFrameBuffer
         return(false);
         // TODO: PDX-364: Log some warning message: "Could not create appropriate graphics mode"
     }
 }
Ejemplo n.º 7
0
        //static List<WeakReference<FBORenderContext>> renderContextList = new List<WeakReference<FBORenderContext>>();
        //public FBORenderContext()
        //{
        //    renderContextList.Add(new WeakReference<FBORenderContext>(this));
        //}

        //public override void Destroy()
        //{
        //    bool found = false;
        //    WeakReference<FBORenderContext> target = null;
        //    for (int index = 0; index < renderContextList.Count; index++)
        //    {
        //        target = renderContextList[index];
        //        FBORenderContext context;
        //        if (target.TryGetTarget(out context))
        //        {
        //            if (context == this)
        //            { break; }
        //        }
        //    }
        //    if (found)
        //    {
        //        renderContextList.Remove(target);
        //    }

        //    base.Destroy();
        //}
        //public static FBORenderContext GetCurrentRenderContext()
        //{
        //    IntPtr renderContext = Win32.wglGetCurrentContext();

        //}

        /// <summary>
        /// Creates the render context provider. Must also create the OpenGL extensions.
        /// </summary>
        /// <param name="openGLVersion">The desired OpenGL version.</param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="bitDepth"></param>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public override bool Create(GLVersion openGLVersion, int width, int height, int bitDepth, object parameter)
        {
            //  Call the base class.
            base.Create(openGLVersion, width, height, bitDepth, parameter);

            // Create frame buffer object.
            var framebuffer = new DefaultFramebuffer();

            framebuffer.Create(width, height);
            this.framebuffer = framebuffer;

            //  Create the DIB section.
            var dibSection = new DIBSection();

            dibSection.Create(this.DeviceContextHandle, width, height, bitDepth);
            this.dibSection = dibSection;

            return(true);
        }
Ejemplo n.º 8
0
        public AndroidGraphicsContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext sharedContext,
                                      GLVersion glesVersion, GraphicsContextFlags flags)
#endif
        {
            int major = (int)glesVersion;
            int minor = 0;

#if OPENTK_0
            major--;
#endif
            // ES 3.1
            if (major == 4)
            {
                major = 3;
                minor = 1;
            }

            Init(mode, window, sharedContext, major, minor, flags);
        }
Ejemplo n.º 9
0
        private void LoadConstants()
        {
            Version         = new GLVersion(GetInteger(GetName.MajorVersion), GetInteger(GetName.MinorVersion));
            MaxSamples      = Math.Min(16, GetInteger(GetName.MaxSamples));
            MaxTextureSize  = GetInteger(GetName.MaxTextureSize);
            MaxTextureUnits = GetInteger(GetName.MaxTextureImageUnits);
            FramebufferMaxColorAttachments = GetInteger(GetName.MaxColorAttachments);
            DirectStateAccess = (Version.Major >= 4 && Version.Minor >= 5);

            Vendor   = GetString(StringName.Vendor);
            Renderer = GetString(StringName.Renderer);
            ShadingLanguageVersion = GetString(StringName.ShadingLanguageVersion);
            VersionText            = GetString(StringName.Version);

            this.Extensions = GetString(StringName.Extenstions)
                              .Split(new char[1] {
                ' '
            }, StringSplitOptions.RemoveEmptyEntries)
                              .ToList()
                              .AsReadOnly();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates the render context provider. Must also create the OpenGL extensions.
        /// </summary>
        /// <param name="openGLVersion">The desired OpenGL version.</param>
        /// <param name="gl">The OpenGL context.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="bitDepth">The bit depth.</param>
        /// <param name="parameter">The parameter</param>
        /// <returns></returns>
        public override bool Create(GLVersion openGLVersion, int width, int height, int bitDepth, object parameter)
        {
            //  Call the base class. 	        
            base.Create(openGLVersion, width, height, bitDepth, parameter);

            uint[] ids = new uint[1];

            //  First, create the frame buffer and bind it.
            ids = new uint[1];
            GL.GenFramebuffersEXT(1, ids);
            frameBufferID = ids[0];
            GL.BindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, frameBufferID);

            //	Create the colour render buffer and bind it, then allocate storage for it.
            GL.GenRenderbuffersEXT(1, ids);
            colourRenderBufferID = ids[0];
            GL.BindRenderbufferEXT(GL.GL_RENDERBUFFER_EXT, colourRenderBufferID);
            GL.RenderbufferStorageEXT(GL.GL_RENDERBUFFER_EXT, GL.GL_RGBA, width, height);

            //	Create the depth render buffer and bind it, then allocate storage for it.
            GL.GenRenderbuffersEXT(1, ids);
            depthRenderBufferID = ids[0];
            GL.BindRenderbufferEXT(GL.GL_RENDERBUFFER_EXT, depthRenderBufferID);
            GL.RenderbufferStorageEXT(GL.GL_RENDERBUFFER_EXT, GL.GL_DEPTH_COMPONENT24, width, height);

            //  Set the render buffer for colour and depth.
            GL.FramebufferRenderbufferEXT(GL.GL_FRAMEBUFFER_EXT, GL.GL_COLOR_ATTACHMENT0_EXT,
                GL.GL_RENDERBUFFER_EXT, colourRenderBufferID);
            GL.FramebufferRenderbufferEXT(GL.GL_FRAMEBUFFER_EXT, GL.GL_DEPTH_ATTACHMENT_EXT,
                GL.GL_RENDERBUFFER_EXT, depthRenderBufferID);

            dibSectionDeviceContext = Win32.CreateCompatibleDC(DeviceContextHandle);

            //  Create the DIB section.
            dibSection.Create(dibSectionDeviceContext, width, height, bitDepth);

            return true;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates the render context provider. Must also create the OpenGL extensions.
        /// </summary>
        /// <param name="openGLVersion">The desired OpenGL version.</param>
        /// <param name="gl">The OpenGL context.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="bitDepth">The bit depth.</param>
        /// <param name="parameter">The parameter</param>
        /// <returns></returns>
        public override bool Create(GLVersion openGLVersion, int width, int height, int bitDepth, object parameter)
        {
            //  Call the base class.
            base.Create(openGLVersion, width, height, bitDepth, parameter);

            uint[] ids = new uint[1];

            //  First, create the frame buffer and bind it.
            ids = new uint[1];
            GL.GetDelegateFor <GL.glGenFramebuffersEXT>()(1, ids);
            frameBufferID = ids[0];
            GL.GetDelegateFor <GL.glBindFramebufferEXT>()(GL.GL_FRAMEBUFFER_EXT, frameBufferID);

            //	Create the colour render buffer and bind it, then allocate storage for it.
            GL.GetDelegateFor <GL.glGenRenderbuffersEXT>()(1, ids);
            colourRenderBufferID = ids[0];
            GL.GetDelegateFor <GL.glBindRenderbufferEXT>()(GL.GL_RENDERBUFFER_EXT, colourRenderBufferID);
            GL.GetDelegateFor <GL.glRenderbufferStorageEXT>()(GL.GL_RENDERBUFFER_EXT, GL.GL_RGBA, width, height);

            //	Create the depth render buffer and bind it, then allocate storage for it.
            GL.GetDelegateFor <GL.glGenRenderbuffersEXT>()(1, ids);
            depthRenderBufferID = ids[0];
            GL.GetDelegateFor <GL.glBindRenderbufferEXT>()(GL.GL_RENDERBUFFER_EXT, depthRenderBufferID);
            GL.GetDelegateFor <GL.glRenderbufferStorageEXT>()(GL.GL_RENDERBUFFER_EXT, GL.GL_DEPTH_COMPONENT24, width, height);

            //  Set the render buffer for colour and depth.
            GL.GetDelegateFor <GL.glFramebufferRenderbufferEXT>()(GL.GL_FRAMEBUFFER_EXT, GL.GL_COLOR_ATTACHMENT0_EXT,
                                                                  GL.GL_RENDERBUFFER_EXT, colourRenderBufferID);
            GL.GetDelegateFor <GL.glFramebufferRenderbufferEXT>()(GL.GL_FRAMEBUFFER_EXT, GL.GL_DEPTH_ATTACHMENT_EXT,
                                                                  GL.GL_RENDERBUFFER_EXT, depthRenderBufferID);

            dibSectionDeviceContext = Win32.CreateCompatibleDC(DeviceContextHandle);

            //  Create the DIB section.
            dibSection.Create(dibSectionDeviceContext, width, height, bitDepth);

            return(true);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Creates the render context provider. Must also create the OpenGL extensions.
        /// </summary>
        /// <param name="openGLVersion">The desired OpenGL version.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="bitDepth">The bit depth.</param>
        /// <param name="parameter">The parameter</param>
        /// <returns></returns>
        public override bool Create(GLVersion openGLVersion, int width, int height, int bitDepth, object parameter)
        {
            //  Call the base.
            base.Create(openGLVersion, width, height, bitDepth, parameter);

            // Create a new window class, as basic as possible.
            if (!this.CreateBasicRenderContext(width, height, bitDepth))
            {
                return(false);
            }

            //	Create the render context.
            this.RenderContextHandle = Win32.wglCreateContext(this.DeviceContextHandle);

            //  Make the context current.
            this.MakeCurrent();

            //  Update the context if required.
            this.UpdateContextVersion();

            //  Return success.
            return(true);
        }
Ejemplo n.º 13
0
        /// <summary>   Initialises the OpenTK Framework, Specificaly OpenGL. </summary>
        /// <param name="a_eGLVersion"> (optional) the e gl version. </param>
        /// <returns> True If Successfull, false otherwise. </returns>
        public bool Initialise(GLVersion a_eGLVersion = GLVersion.Unknown)
        {
            bool bSuccess = false;  // used to shpow success or failure of Init.

            // create a OpenTK Controll and query it for the GLContext version number:
            OpenTK.GLControl oTest = new GLControl(new GraphicsMode(32, 24, 8, 4), 4, 0, GraphicsContextFlags.Default);
            // We need to "show" a for before OpenTK actuall initilise the GLContext (which we need to happen to get a version number!).
            // the following creates a form that we can show but will never be seen by the end user!
            Form oOpenGLVersionCheck = new Form();

            oOpenGLVersionCheck.Controls.Add(oTest);
            oOpenGLVersionCheck.StartPosition   = FormStartPosition.CenterScreen;
            oOpenGLVersionCheck.Size            = new Size(0, 0);
            oOpenGLVersionCheck.ShowInTaskbar   = false;
            oOpenGLVersionCheck.FormBorderStyle = FormBorderStyle.None;
            oOpenGLVersionCheck.TopMost         = false;
            oOpenGLVersionCheck.Show();
            oOpenGLVersionCheck.Hide();

            string szOpenGLVersion;
            int    iMajor, iMinor;

            try
            {
                szOpenGLVersion = GL.GetString(StringName.Version);
                iMajor          = int.Parse(szOpenGLVersion[0].ToString()); // extracts the major verion number an converts it to a int.
                iMinor          = int.Parse(szOpenGLVersion[2].ToString()); // same again for minor verion number.
                #if DEBUG
                logger.Debug("Highest OpenGL Version Initialised is " + szOpenGLVersion);
                #endif
            }
            catch (System.NullReferenceException e)
            {
                // Problem occured when trying to get open GL Verion, Logg and assume 2.0 so program exacution can continue:
                logger.Error("Error Getting OpenGL Version, Assuming version 2.0!");
                iMajor = 2;
                iMinor = 0;
            }


            if (iMajor == 1)
            {
                m_eSupportedOpenGLVersion = GLVersion.OpenGL1X;
            }
            else if (iMajor == 2)
            {
                m_eSupportedOpenGLVersion = GLVersion.OpenGL2X;
                bSuccess = true;
            }
            else if (iMajor <= 3 && iMinor < 2)
            {
                m_eSupportedOpenGLVersion = GLVersion.OpenGL2X;
                bSuccess = true;
            }
            else if (iMajor <= 3 && iMinor >= 2)
            {
                m_eSupportedOpenGLVersion = GLVersion.OpenGL3X;
                bSuccess = true;
            }
            else if (iMajor == 4)
            {
                m_eSupportedOpenGLVersion = GLVersion.OpenGL4X;
                bSuccess = true;
            }
            else
            {
                logger.Error("OpenGL Version Autodetect Could Not work out which version of OpenGL is on this system");
                logger.Error("OpenGL Version Major is: " + iMajor.ToString() + "OpenGL Minor is: " + iMinor.ToString());
                bSuccess = false;
            }

            // override the Detected veriosn if a one was specified.
            if (a_eGLVersion != GLVersion.Unknown)
            {
                m_eSupportedOpenGLVersion = a_eGLVersion;
                logger.Warn("OpenGL Version Autodetect has been overridden to " + a_eGLVersion.ToString());
                bSuccess = true;
            }

            return(bSuccess);
        }
Ejemplo n.º 14
0
		public AndroidGraphicsContext (GraphicsMode mode, IWindowInfo window, IGraphicsContext sharedContext,
								GLVersion glesVersion, GraphicsContextFlags flags)
#endif
		{
			int major = (int)glesVersion;
			int minor = 0;
#if OPENTK_0
			major--;
#endif
			// ES 3.1
			if (major == 4) {
				major = 3;
				minor = 1;
			}

			Init (mode, window, sharedContext, major, minor, flags);
		}
Ejemplo n.º 15
0
		internal static AndroidGraphicsContext CreateGraphicsContext (GraphicsMode mode, IWindowInfo window,
			IGraphicsContext sharedContext, GLVersion glVersion, GraphicsContextFlags flags)
#endif
		{
			return new AndroidGraphicsContext(mode, window, sharedContext, glVersion, flags);
		}
Ejemplo n.º 16
0
        /// <summary>
        /// Creates the render context provider. Must also create the OpenGL extensions.
        /// </summary>
        /// <param name="openGLVersion">The desired OpenGL version.</param>
        /// <param name="gl">The OpenGL context.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="bitDepth">The bit depth.</param>
        /// <param name="parameter">The parameter</param>
        /// <returns></returns>
        public override bool Create(GLVersion openGLVersion, int width, int height, int bitDepth, object parameter)
        {
            //  Call the base.
            base.Create(openGLVersion, width, height, bitDepth, parameter);

            //	Create a new window class, as basic as possible.                
            WNDCLASSEX wndClass = new WNDCLASSEX();
            wndClass.Init();
            wndClass.style = ClassStyles.HorizontalRedraw | ClassStyles.VerticalRedraw | ClassStyles.OwnDC;
            wndClass.lpfnWndProc = wndProcDelegate;
            wndClass.cbClsExtra = 0;
            wndClass.cbWndExtra = 0;
            wndClass.hInstance = IntPtr.Zero;
            wndClass.hIcon = IntPtr.Zero;
            wndClass.hCursor = IntPtr.Zero;
            wndClass.hbrBackground = IntPtr.Zero;
            wndClass.lpszMenuName = null;
            wndClass.lpszClassName = "SharpGLRenderWindow";
            wndClass.hIconSm = IntPtr.Zero;
            Win32.RegisterClassEx(ref wndClass);

            //	Create the window. Position and size it.
            windowHandle = Win32.CreateWindowEx(0,
                          "SharpGLRenderWindow",
                          "",
                          WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_POPUP,
                          0, 0, width, height,
                          IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

            //	Get the window device context.
            DeviceContextHandle = Win32.GetDC(windowHandle);

            //	Setup a pixel format.
            PIXELFORMATDESCRIPTOR pfd = new PIXELFORMATDESCRIPTOR();
            pfd.Init();
            pfd.nVersion = 1;
            pfd.dwFlags = Win32.PFD_DRAW_TO_WINDOW | Win32.PFD_SUPPORT_OPENGL | Win32.PFD_DOUBLEBUFFER;
            pfd.iPixelType = Win32.PFD_TYPE_RGBA;
            pfd.cColorBits = (byte)bitDepth;
            pfd.cDepthBits = 16;
            pfd.cStencilBits = 8;
            pfd.iLayerType = Win32.PFD_MAIN_PLANE;

            //	Match an appropriate pixel format 
            int iPixelformat;
            if ((iPixelformat = Win32.ChoosePixelFormat(DeviceContextHandle, pfd)) == 0)
                return false;

            //	Sets the pixel format
            if (Win32.SetPixelFormat(DeviceContextHandle, iPixelformat, pfd) == 0)
            {
                return false;
            }

            //	Create the render context.
            RenderContextHandle = Win32.wglCreateContext(DeviceContextHandle);

            //  Make the context current.
            MakeCurrent();

            //  Update the context if required.
            UpdateContextVersion();

            //  Return success.
            return true;
        }
Ejemplo n.º 17
0
        public static GLParser FromFile(string xmlFile, params string[] Api)
        {
            XDocument file = XDocument.Load(xmlFile);
            GLParser  spec = new GLParser();

            spec.HeaderComment = file.Root.Element("comment").Value;

            foreach (var feature in file.Root.Elements("feature"))
            {
                var apiName = feature.Attribute("api").Value;
                if (Api.Contains(apiName))
                {
                    var version = new GLVersion
                    {
                        Api    = feature.Attribute("api").Value.ToUpper(),
                        Number = feature.Attribute("number").Value,
                    };

                    version.Name = version.Api + version.Number.Replace(".", "");

                    // Add all enums and commands from previus versions
                    int i = spec.Versions.Count - 1;
                    if (i >= 0)
                    {
                        var previousVersion = spec.Versions[i];

                        foreach (var g in previousVersion.Groups)
                        {
                            version.Groups.Add(g.Clone());
                        }

                        foreach (var c in previousVersion.Commands)
                        {
                            version.Commands.Add(c.Clone());
                        }
                    }

                    // Include all new enums and commands
                    foreach (var require in feature.Elements("require"))
                    {
                        foreach (var enumElem in require.Elements("enum"))
                        {
                            var enumName = enumElem.Attribute("name").Value;

                            // if enum doesn't exists
                            bool exists = version.Groups.Exists(g => g.Enums.Exists(e => e.Name == enumName));

                            if (!exists)
                            {
                                // Find group
                                string groupFound = FindGroupInXML(file, enumName);

                                // The group already exists
                                GlGroup glgroup = version.Groups.Find(g => g.Name == groupFound);

                                if (glgroup == null)
                                {
                                    glgroup = new GlGroup()
                                    {
                                        Name = groupFound
                                    };
                                    version.Groups.Add(glgroup);
                                }

                                // Create new Enum
                                var glEnum = new GLEnum();
                                glEnum.Initialize(file, enumName);
                                glgroup.Enums.Add(glEnum);
                            }
                        }

                        foreach (var commandElem in require.Elements("command"))
                        {
                            var glCommand = new GLCommand()
                            {
                                Name = commandElem.Attribute("name").Value
                            };
                            if (version.Commands.Find(c => c.Name == glCommand.Name) == null)
                            {
                                // Create new command
                                glCommand.Initialize(commandElem.Document);
                                version.Commands.Add(glCommand);
                            }
                        }
                    }

                    // Add enum from commands
                    foreach (var commandElem in version.Commands)
                    {
                        // Return Type
                        if (commandElem.ReturnType.Type == "GLenum")
                        {
                            var  selectedGroup = commandElem.ReturnType.Group;
                            bool groupExists   = version.Groups.Exists(g => g.Name == selectedGroup);
                            if (!groupExists)
                            {
                                foreach (var group in file.Root.Element("groups").Elements("group"))
                                {
                                    string groupName = group.Attribute("name").Value;
                                    if (groupName == selectedGroup)
                                    {
                                        GlGroup glgroup = new GlGroup()
                                        {
                                            Name = selectedGroup
                                        };
                                        foreach (var e in group.Elements("enum"))
                                        {
                                            GLEnum glEnum   = new GLEnum();
                                            var    enumName = e.Attribute("name").Value;
                                            glEnum.Initialize(file, enumName);
                                            glgroup.Enums.Add(glEnum);
                                        }
                                        version.Groups.Add(glgroup);
                                    }
                                }
                            }
                        }

                        // Parameters
                        foreach (var param in commandElem.Parameters)
                        {
                            if (param.Type == "GLenum")
                            {
                                bool groupExists = version.Groups.Exists(g => g.Name == param.Group);
                                if (!groupExists)
                                {
                                    foreach (var group in file.Root.Element("groups").Elements("group"))
                                    {
                                        string groupName = group.Attribute("name").Value;
                                        if (groupName == param.Group)
                                        {
                                            GlGroup glgroup = new GlGroup()
                                            {
                                                Name = param.Group
                                            };
                                            foreach (var e in group.Elements("enum"))
                                            {
                                                GLEnum glEnum   = new GLEnum();
                                                var    enumName = e.Attribute("name").Value;
                                                glEnum.Initialize(file, enumName);
                                                glgroup.Enums.Add(glEnum);
                                            }
                                            version.Groups.Add(glgroup);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    // Remove any anums and commands
                    foreach (var remove in feature.Elements("remove"))
                    {
                        foreach (var e in remove.Elements("enum"))
                        {
                            foreach (var group in version.Groups)
                            {
                                var glenum = group.Enums.Find(n => n.Name == e.Attribute("name").Value);

                                if (glenum != null)
                                {
                                    group.Enums.Remove(glenum);
                                }
                            }
                        }

                        foreach (var c in remove.Elements("command"))
                        {
                            version.Commands.RemoveAll(command => command.Name == c.Attribute("name").Value);
                        }
                    }

                    // Remove all group with 0 enums
                    version.Groups.RemoveAll(g => g.Enums.Count == 0);

                    // Remove GLBoolean type
                    version.Groups.RemoveAll(g => g.Name == "Boolean");

                    spec.Versions.Add(version);
                }
            }

            return(spec);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Creates the render context provider. Must also create the OpenGL extensions.
        /// </summary>
        /// <param name="openGLVersion">The desired OpenGL version.</param>
        /// <param name="gl">The OpenGL context.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="bitDepth">The bit depth.</param>
        /// <param name="parameter">The parameter</param>
        /// <returns></returns>
        public override bool Create(GLVersion openGLVersion, int width, int height, int bitDepth, object parameter)
        {
            //  Call the base.
            base.Create(openGLVersion, width, height, bitDepth, parameter);

            //	Create a new window class, as basic as possible.
            WNDCLASSEX wndClass = new WNDCLASSEX();

            wndClass.Init();
            wndClass.style         = ClassStyles.HorizontalRedraw | ClassStyles.VerticalRedraw | ClassStyles.OwnDC;
            wndClass.lpfnWndProc   = wndProcDelegate;
            wndClass.cbClsExtra    = 0;
            wndClass.cbWndExtra    = 0;
            wndClass.hInstance     = IntPtr.Zero;
            wndClass.hIcon         = IntPtr.Zero;
            wndClass.hCursor       = IntPtr.Zero;
            wndClass.hbrBackground = IntPtr.Zero;
            wndClass.lpszMenuName  = null;
            wndClass.lpszClassName = "SharpGLRenderWindow";
            wndClass.hIconSm       = IntPtr.Zero;
            Win32.RegisterClassEx(ref wndClass);

            //	Create the window. Position and size it.
            windowHandle = Win32.CreateWindowEx(0,
                                                "SharpGLRenderWindow",
                                                "",
                                                WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_POPUP,
                                                0, 0, width, height,
                                                IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

            //	Get the window device context.
            DeviceContextHandle = Win32.GetDC(windowHandle);

            //	Setup a pixel format.
            PIXELFORMATDESCRIPTOR pfd = new PIXELFORMATDESCRIPTOR();

            pfd.Init();
            pfd.nVersion     = 1;
            pfd.dwFlags      = Win32.PFD_DRAW_TO_WINDOW | Win32.PFD_SUPPORT_OPENGL | Win32.PFD_DOUBLEBUFFER;
            pfd.iPixelType   = Win32.PFD_TYPE_RGBA;
            pfd.cColorBits   = (byte)bitDepth;
            pfd.cDepthBits   = 16;
            pfd.cStencilBits = 8;
            pfd.iLayerType   = Win32.PFD_MAIN_PLANE;

            //	Match an appropriate pixel format
            int iPixelformat;

            if ((iPixelformat = Win32.ChoosePixelFormat(DeviceContextHandle, pfd)) == 0)
            {
                return(false);
            }

            //	Sets the pixel format
            if (Win32.SetPixelFormat(DeviceContextHandle, iPixelformat, pfd) == 0)
            {
                return(false);
            }

            //	Create the render context.
            RenderContextHandle = Win32.wglCreateContext(DeviceContextHandle);

            //  Make the context current.
            MakeCurrent();

            //  Update the context if required.
            UpdateContextVersion();

            //  Return success.
            return(true);
        }
Ejemplo n.º 19
0
        internal static AndroidGraphicsContext CreateGraphicsContext(GraphicsMode mode, IWindowInfo window,
                                                                     IGraphicsContext sharedContext, GLVersion glVersion, GraphicsContextFlags flags)
#endif
        {
            return(new AndroidGraphicsContext(mode, window, sharedContext, glVersion, flags));
        }
Ejemplo n.º 20
0
 private bool TryCreateFrameBuffer(GLVersion version, ColorFormat requestedColorFormat, int requestedDepth, int requestedStencil)
 {
     try
     {
         ContextRenderingApi = version;
         GraphicsMode = new GraphicsMode(requestedColorFormat, requestedDepth, requestedStencil);
         base.CreateFrameBuffer();
         return true;
     }
     catch (Exception)
     {
         base.DestroyFrameBuffer(); // Destroy to prevent side effects on future calls to CreateFrameBuffer
         return false;
         // TODO: PDX-364: Log some warning message: "Could not create appropriate graphics mode"
     }
 }