KiCad PCB EDA Suite
Loading...
Searching...
No Matches
ogl_attr_list.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2015-2016 Mario Luzeiro <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
25
26#include "ogl_attr_list.h"
27#include <wx/debug.h>
28#include <core/arraydim.h>
29
30
31const wxGLAttributes OGL_ATT_LIST::GetAttributesList( ANTIALIASING_MODE aAntiAliasingMode,
32 bool aAlpha )
33{
34 wxASSERT( aAntiAliasingMode <= ANTIALIASING_MODE::AA_8X );
35
36 auto makeAttribs = [aAlpha]( int aSamplers )
37 {
38 wxGLAttributes dispAttrs;
39
40 dispAttrs.RGBA()
41 .DoubleBuffer()
42 .Depth( 16 )
43 .Stencil( 8 )
44 .Samplers( aSamplers )
45 .SampleBuffers( aSamplers >= 0 ? 1 : -1 )
46 .MinRGBA( 8, 8, 8, aAlpha ? 8 : -1 )
47 .EndList();
48
49 return dispAttrs;
50 };
51
52 int maxSamples = -1;
53
54 if( aAntiAliasingMode > ANTIALIASING_MODE::AA_NONE )
55 {
56 // Check if the canvas supports multisampling.
57 if( wxGLCanvas::IsDisplaySupported( makeAttribs( 0 ) ) )
58 {
59 static const int aaSamples[4] = { 0, 2, 4, 8 };
60
61 // Check for possible sample sizes, start form the requested.
62 maxSamples = aaSamples[static_cast<int>( aAntiAliasingMode )];
63
64 while( maxSamples > 0 && !wxGLCanvas::IsDisplaySupported( makeAttribs( maxSamples ) ) )
65 {
66 maxSamples = maxSamples >> 1;
67 }
68 }
69 }
70
71 return makeAttribs( maxSamples );
72}
static const wxGLAttributes GetAttributesList(ANTIALIASING_MODE aAntiAliasingMode, bool aAlpha=false)
Get a list of attributes to pass to wxGLCanvas.
Declaration of the cogl_att_list class.
ANTIALIASING_MODE
Anti-aliasing options.