KiCad PCB EDA Suite
cogl_att_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 <mrluzeiro@ua.pt>
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 "cogl_att_list.h"
31 #include <macros.h>
32 #include <wx/glcanvas.h>
33 #include <fctsys.h>
34 #include <wx/debug.h>
35 
48 
49  // Boolean attributes (using itself at padding):
50 
51  // 0 1
52  WX_GL_RGBA, WX_GL_RGBA,
53  // 2 3
54  WX_GL_DOUBLEBUFFER, WX_GL_DOUBLEBUFFER,
55 
56 
57  // Normal attributes with values:
58 
59  // 4 5
60  WX_GL_DEPTH_SIZE, 16,
61  // 6 7
62  WX_GL_STENCIL_SIZE, 8,
63 
64 
65  // This ones need to be the last in the list (as the tags will set to 0 if AA fails)
66 
67  // 8 9
68  WX_GL_SAMPLES, 0, // Disable AA for the start.
69  //10 11
70  WX_GL_SAMPLE_BUFFERS, 1, // Enable multisampling support (antialiasing).
71 
72  0, 0 // NULL termination
73 };
74 
75 #define ATT_WX_GL_SAMPLES_OFFSET 8
76 #define ATT_WX_GL_SAMPLES_OFFSET_DATA 9
77 #define ATT_WX_GL_SAMPLE_BUFFERS_OFFSET 10
78 #define ATT_WX_GL_SAMPLE_BUFFERS_DATA 11
79 
82 
83 
84 const int *COGL_ATT_LIST::GetAttributesList( ANTIALIASING_MODE aAntiAliasingMode )
85 {
86  wxASSERT( aAntiAliasingMode <= ANTIALIASING_MODE::AA_8X );
87 
91 
92  if( aAntiAliasingMode > ANTIALIASING_MODE::AA_NONE )
93  {
94  // There is a bug on wxGLCanvas that makes IsDisplaySupported fail
95  // while testing for antialiasing.
96  // http://trac.wxwidgets.org/ticket/16909
97  // this next code will only work after this bug is fixed
98  //
99  // On my experience (Mario) it was only working on Linux but failing on
100  // Windows, so there was no AA.
101 
102 
103  // Check if the canvas supports multisampling.
104  if( wxGLCanvas::IsDisplaySupported( m_openGL_attributes_list_to_use ) )
105  {
106  static const int aaSamples[4] = {0, 2, 4, 8};
107 
108  // Check for possible sample sizes, start form the requested.
109  int maxSamples = aaSamples[static_cast<int>( aAntiAliasingMode )];
110 
112 
113  for( ; (maxSamples > 0) &&
114  ( !wxGLCanvas::IsDisplaySupported( m_openGL_attributes_list_to_use ) );
115  maxSamples = maxSamples >> 1 )
116  {
118  }
119  }
120  else
121  {
122  DBG( printf("GetAttributesList: AntiAliasing is not supported.\n") );
123  aAntiAliasingMode = ANTIALIASING_MODE::AA_NONE;
124  }
125  }
126 
127  // Disable antialising if it failed or was not requested
128  if( aAntiAliasingMode == ANTIALIASING_MODE::AA_NONE )
129  {
130  // Remove multisampling information
131  // (hoping that the GPU driver will decide what is best)
136  }
137 
139 }
#define ATT_WX_GL_SAMPLE_BUFFERS_DATA
static const int m_openGL_attributes_list[]
Attributes list to be passed to a wxGLCanvas creation.
Definition: cogl_att_list.h:70
This file contains miscellaneous commonly used macros and functions.
#define ATT_WX_GL_SAMPLES_OFFSET
#define ATT_WX_GL_SAMPLES_OFFSET_DATA
static int m_openGL_attributes_list_to_use[]
Attributes list that was (eventualy) changed and are passed to creation.
Definition: cogl_att_list.h:75
ANTIALIASING_MODE
Anti-aliasing options.
Definition: cogl_att_list.h:34
Declaration of the cogl_att_list class.
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:160
static const int * GetAttributesList(ANTIALIASING_MODE aAntiAliasingMode)
Get a list of attributes to pass to wxGLCanvas.
#define DBG(x)
Definition: fctsys.h:33
#define ATT_WX_GL_SAMPLE_BUFFERS_OFFSET