Browse Source
Added support for Compatibility profile in Wgl and Glx code (#15598 )
* Added support for Compatibility profile in Wgl and Glx code
* Fixes after code review
---------
Co-authored-by: Olivier DALET <olivier.dalet@addupsolutions.com>
pull/15640/head
odalet
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with
25 additions and
8 deletions
src/Avalonia.Native/AvaloniaNativeGlPlatformGraphics.cs
src/Avalonia.OpenGL/GlConsts.cs
src/Avalonia.OpenGL/GlVersion.cs
src/Avalonia.X11/Glx/GlxDisplay.cs
src/Windows/Avalonia.Win32/OpenGl/WglConsts.cs
src/Windows/Avalonia.Win32/OpenGl/WglDisplay.cs
@ -25,7 +25,10 @@ namespace Avalonia.Native
var basic = new GlBasicInfoInterface ( display . GetProcAddress ) ;
basic . GetIntegerv ( GlConsts . GL_MAJOR_VERSION , out major ) ;
basic . GetIntegerv ( GlConsts . GL_MINOR_VERSION , out minor ) ;
_ version = new GlVersion ( GlProfileType . OpenGL , major , minor ) ;
basic . GetIntegerv ( GlConsts . GL_CONTEXT_PROFILE_MASK , out var profileMask ) ;
var isCompatibilityProfile = ( profileMask & GlConsts . GL_CONTEXT_COMPATIBILITY_PROFILE_BIT ) = = GlConsts . GL_CONTEXT_COMPATIBILITY_PROFILE_BIT ;
_ version = new GlVersion ( GlProfileType . OpenGL , major , minor , isCompatibilityProfile ) ;
glInterface = new GlInterface ( _ version , ( name ) = >
{
var rv = _d isplay . GetProcAddress ( name ) ;
@ -1282,8 +1282,8 @@ namespace Avalonia.OpenGL
// public const int GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER = 0x8A46;
// public const int GL_INVALID_INDEX = -1;
// public const int GL_VERSION_3_2 = 1;
// public const int GL_CONTEXT_CORE_PROFILE_BIT = 0x00000001;
// public const int GL_CONTEXT_COMPATIBILITY_PROFILE_BIT = 0x00000002;
public const int GL_CONTEXT_CORE_PROFILE_BIT = 0x00000001 ;
public const int GL_CONTEXT_COMPATIBILITY_PROFILE_BIT = 0x00000002 ;
// public const int GL_LINES_ADJACENCY = 0x000A;
// public const int GL_LINE_STRIP_ADJACENCY = 0x000B;
// public const int GL_TRIANGLES_ADJACENCY = 0x000C;
@ -1303,7 +1303,7 @@ namespace Avalonia.OpenGL
// public const int GL_MAX_GEOMETRY_INPUT_COMPONENTS = 0x9123;
// public const int GL_MAX_GEOMETRY_OUTPUT_COMPONENTS = 0x9124;
// public const int GL_MAX_FRAGMENT_INPUT_COMPONENTS = 0x9125;
// public const int GL_CONTEXT_PROFILE_MASK = 0x9126;
public const int GL_CONTEXT_PROFILE_MASK = 0x9126 ;
// public const int GL_DEPTH_CLAMP = 0x864F;
// public const int GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION = 0x8E4C;
// public const int GL_FIRST_VERTEX_CONVENTION = 0x8E4D;
@ -11,12 +11,15 @@ namespace Avalonia.OpenGL
public GlProfileType Type { get ; }
public int Major { get ; }
public int Minor { get ; }
public bool IsCompatibilityProfile { get ; } // Only makes sense if Type is OpenGL and Version is >= 3.2
public GlVersion ( GlProfileType type , int major , int minor )
public GlVersion ( GlProfileType type , int major , int minor ) : this ( type , major , minor , false ) { }
public GlVersion ( GlProfileType type , int major , int minor , bool isCompatibilityProfile )
{
Type = type ;
Major = major ;
Minor = minor ;
IsCompatibilityProfile = isCompatibilityProfile ;
}
}
}
@ -126,7 +126,11 @@ namespace Avalonia.X11.Glx
GlxContext Create ( GlVersion profile )
{
var profileMask = GLX_CONTEXT_CORE_PROFILE_BIT_ARB ;
if ( profile . Type = = GlProfileType . OpenGLES )
if ( profile . Type = = GlProfileType . OpenGL & &
profile . IsCompatibilityProfile & &
( profile . Major > 3 | | profile . Major = = 3 & & profile . Minor > = 2 ) )
profileMask = GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB ;
else if ( profile . Type = = GlProfileType . OpenGLES )
profileMask = GLX_CONTEXT_ES2_PROFILE_BIT_EXT ;
var attrs = new int [ ]
@ -7,6 +7,8 @@ namespace Avalonia.Win32.OpenGl
public const int WGL_CONTEXT_LAYER_PLANE_ARB = 0x2093 ;
public const int WGL_CONTEXT_FLAGS_ARB = 0x2094 ;
public const int WGL_CONTEXT_PROFILE_MASK_ARB = 0x9126 ;
public const int WGL_CONTEXT_CORE_PROFILE_BIT_ARB = 0x00000001 ;
public const int WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB = 0x00000002 ;
public const int WGL_NUMBER_PIXEL_FORMATS_ARB = 0x2000 ;
public const int WGL_DRAW_TO_WINDOW_ARB = 0x2001 ;
@ -126,6 +126,11 @@ namespace Avalonia.Win32.OpenGl
IntPtr context ;
using ( shareContext ? . Lock ( ) )
{
var profileMask = WGL_CONTEXT_CORE_PROFILE_BIT_ARB ;
if ( version . IsCompatibilityProfile & &
( version . Major > 3 | | version . Major = = 3 & & version . Minor > = 2 ) )
profileMask = WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB ;
context = s_wglCreateContextAttribsArb ( dc , shareContext ? . Handle ? ? IntPtr . Zero ,
new [ ]
{
@ -133,8 +138,8 @@ namespace Avalonia.Win32.OpenGl
WGL_CONTEXT_MAJOR_VERSION_ARB , version . Major ,
// minor
WGL_CONTEXT_MINOR_VERSION_ARB , version . Minor ,
// core profile
WGL_CONTEXT_PROFILE_MASK_ARB , 1 ,
// core or compatibility profile
WGL_CONTEXT_PROFILE_MASK_ARB , profileMask ,
// debug
// WGL_CONTEXT_FLAGS_ARB, 1,
// end