Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Always creating an old context.

Bugs
2013-10-08
2013-10-09
  • Harry Glinos
    Harry Glinos
    2013-10-08

    I noticed in the following code that it's always creating an old context instead of the new context regardless of the version of OpenGL that I'm using.

    When a new setting is passed as an argument, I think you should set the default values to 0xff RenderingContextSetting.

    public byte minorVersion = 0xff;
    public byte majorVersion = 0xff;
    
     new public static RenderingContext CreateContext(Control c, RenderingContextSetting setting)
    {
        RenderingContextWin rc = new RenderingContextWin();
        rc.setting = setting;
        rc.CreateOldContext(c);
        int[] OpenGLVersion = new int[1];
        // set highest context major version
        if (setting.majorVersion == 0xff)
        {
            gl.GetIntegerv(GL.MAJOR_VERSION, OpenGLVersion);
            setting.majorVersion = (byte)OpenGLVersion[0];
        }
        // set highest context minor version
        if (setting.minorVersion == 0xff)
        {
            gl.GetIntegerv(GL.MINOR_VERSION, OpenGLVersion);
            setting.minorVersion = (byte)OpenGLVersion[0];
        }
        // create new context using ARB_create_context
        if (setting.majorVersion >= 3)
        {
            rc.CreateNewContext();
        }
        else
        {
            setting.profile = 0;
            setting.context = 0;
        }
        OpenGLVersion[0] = 0;
        gl.GetIntegerv(GL.MAJOR_VERSION, OpenGLVersion);
        setting.majorVersion = (byte)OpenGLVersion[0];
        gl.GetIntegerv(GL.MINOR_VERSION, OpenGLVersion);
        setting.minorVersion = (byte)OpenGLVersion[0];
        return rc;
    }
    

    I also rewrote this to be the following which would ignore the default version numbers in setting.

      new public static RenderingContext CreateContext(Control c, RenderingContextSetting setting)
        {
            RenderingContextWin rc = new RenderingContextWin();
            rc.setting = setting;
    
            int[] OpenGLVersion = new int[1];
    
                    rc.CreateOldContext(c); //Need at least an old context to get the version number
                    gl.GetIntegerv(GL.MAJOR_VERSION, OpenGLVersion);
                    setting.majorVersion = (byte)OpenGLVersion[0];
                    gl.GetIntegerv(GL.MINOR_VERSION, OpenGLVersion);
                    setting.minorVersion = (byte)OpenGLVersion[0];
    
            // create new context using ARB_create_context
            if (setting.majorVersion >= 3)
            {
                rc.CreateNewContext();
            }
            else
            {   
                setting.profile = 0;
                setting.context = 0;
            }
    
            return rc;
        }
    
     
  • pet_cz
    pet_cz
    2013-10-09

    Yes, you are right. If you are creating new context with new RenderingContextSetting without the version specification, the old context is created. The default value for version in RenderingContextSetting is 2.0. This was due to the fact that the library was used for education purposes. This is definitely a subject to change in future revisions. A quick fix could be done by changing the default values of minorVersion and majorVersion variables in RenderingContextSetting to 0xff.

    Thank you for the report.

     
    Last edit: pet_cz 2013-10-10