KiCad PCB EDA Suite
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 (C) 1992-2020 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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
30#include "ogl_attr_list.h"
31#include <wx/glcanvas.h>
32#include <wx/debug.h>
33#include <core/arraydim.h>
34
35
37
38 // Boolean attributes (using itself at padding):
39
40 // 0 1
41 WX_GL_RGBA, WX_GL_RGBA,
42 // 2 3
43 WX_GL_DOUBLEBUFFER, WX_GL_DOUBLEBUFFER,
44
45
46 // Normal attributes with values:
47
48 // 4 5
49 WX_GL_DEPTH_SIZE, 16,
50 // 6 7
51 WX_GL_STENCIL_SIZE, 8,
52
53
54 // This ones need to be the last in the list (as the tags will set to 0 if AA fails)
55
56 // 8 9
57 WX_GL_SAMPLES, 0, // Disable AA for the start.
58 //10 11
59 WX_GL_SAMPLE_BUFFERS, 1, // Enable multisampling support (antialiasing).
60
61 0, 0 // NULL termination
62};
63
64#define ATT_WX_GL_SAMPLES_OFFSET 8
65#define ATT_WX_GL_SAMPLES_OFFSET_DATA 9
66#define ATT_WX_GL_SAMPLE_BUFFERS_OFFSET 10
67#define ATT_WX_GL_SAMPLE_BUFFERS_DATA 11
68
71
72
74{
75 wxASSERT( aAntiAliasingMode <= ANTIALIASING_MODE::AA_8X );
76
79
80 if( aAntiAliasingMode > ANTIALIASING_MODE::AA_NONE )
81 {
82 // There is a bug on wxGLCanvas that makes IsDisplaySupported fail
83 // while testing for antialiasing.
84 // http://trac.wxwidgets.org/ticket/16909
85 // this next code will only work after this bug is fixed
86 //
87 // On my experience (Mario) it was only working on Linux but failing on
88 // Windows, so there was no AA.
89
90
91 // Check if the canvas supports multisampling.
92 if( wxGLCanvas::IsDisplaySupported( m_openGL_attributes_list_to_use ) )
93 {
94 static const int aaSamples[4] = {0, 2, 4, 8};
95
96 // Check for possible sample sizes, start form the requested.
97 int maxSamples = aaSamples[static_cast<int>( aAntiAliasingMode )];
98
100
101 for( ; (maxSamples > 0) &&
102 ( !wxGLCanvas::IsDisplaySupported( m_openGL_attributes_list_to_use ) );
103 maxSamples = maxSamples >> 1 )
104 {
106 }
107 }
108 else
109 {
110 aAntiAliasingMode = ANTIALIASING_MODE::AA_NONE;
111 }
112 }
113
114 // Disable antialiasing if it failed or was not requested
115 if( aAntiAliasingMode == ANTIALIASING_MODE::AA_NONE )
116 {
117 // Remove multisampling information
118 // (hoping that the GPU driver will decide what is best)
123 }
124
126}
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31
static int m_openGL_attributes_list_to_use[]
Attributes list that was (eventually) changed and are passed to creation.
Definition: ogl_attr_list.h:76
static const int m_openGL_attributes_list[]
Attributes list to be passed to a wxGLCanvas creation.
Definition: ogl_attr_list.h:71
static const int * GetAttributesList(ANTIALIASING_MODE aAntiAliasingMode)
Get a list of attributes to pass to wxGLCanvas.
#define ATT_WX_GL_SAMPLE_BUFFERS_OFFSET
#define ATT_WX_GL_SAMPLES_OFFSET
#define ATT_WX_GL_SAMPLE_BUFFERS_DATA
#define ATT_WX_GL_SAMPLES_OFFSET_DATA
Declaration of the cogl_att_list class.
ANTIALIASING_MODE
Anti-aliasing options.
Definition: ogl_attr_list.h:35