2015-12-08 07:31:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2016-07-19 17:35:25 +00:00
|
|
|
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
|
2020-04-17 21:33:23 +00:00
|
|
|
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-12-08 07:31:57 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file cogl_att_list.cpp
|
|
|
|
* @brief Implements a attribute list support for openGL
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cogl_att_list.h"
|
2020-04-17 21:33:23 +00:00
|
|
|
#include <macros.h>
|
|
|
|
#include <wx/glcanvas.h>
|
|
|
|
#include <wx/debug.h>
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Attributes list to be passed to a wxGLCanvas creation.
|
|
|
|
*
|
|
|
|
* This array should be 2*n+1
|
|
|
|
* Sadly wxwidgets / glx < 13 allowed
|
|
|
|
* a thing named "boolean attributes" that don't take a value.
|
|
|
|
* (See src/unix/glx11.cpp -> wxGLCanvasX11::ConvertWXAttrsToGL() ).
|
|
|
|
* To avoid problems due to this, just specify those attributes twice.
|
|
|
|
* Only WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_STEREO are such boolean
|
|
|
|
* attributes.
|
|
|
|
*/
|
2016-07-19 17:35:25 +00:00
|
|
|
const int COGL_ATT_LIST::m_openGL_attributes_list[] = {
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
// Boolean attributes (using itself at padding):
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// 0 1
|
2020-04-17 21:33:23 +00:00
|
|
|
WX_GL_RGBA, WX_GL_RGBA,
|
2016-07-19 17:35:25 +00:00
|
|
|
// 2 3
|
2015-12-08 07:31:57 +00:00
|
|
|
WX_GL_DOUBLEBUFFER, WX_GL_DOUBLEBUFFER,
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
// Normal attributes with values:
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// 4 5
|
2015-12-08 07:31:57 +00:00
|
|
|
WX_GL_DEPTH_SIZE, 16,
|
2016-07-19 17:35:25 +00:00
|
|
|
// 6 7
|
|
|
|
WX_GL_STENCIL_SIZE, 8,
|
|
|
|
|
|
|
|
|
|
|
|
// This ones need to be the last in the list (as the tags will set to 0 if AA fails)
|
|
|
|
|
|
|
|
// 8 9
|
2015-12-08 07:31:57 +00:00
|
|
|
WX_GL_SAMPLES, 0, // Disable AA for the start.
|
2016-07-19 17:35:25 +00:00
|
|
|
//10 11
|
|
|
|
WX_GL_SAMPLE_BUFFERS, 1, // Enable multisampling support (antialiasing).
|
|
|
|
|
|
|
|
0, 0 // NULL termination
|
2015-12-08 07:31:57 +00:00
|
|
|
};
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
#define ATT_WX_GL_SAMPLES_OFFSET 8
|
|
|
|
#define ATT_WX_GL_SAMPLES_OFFSET_DATA 9
|
|
|
|
#define ATT_WX_GL_SAMPLE_BUFFERS_OFFSET 10
|
|
|
|
#define ATT_WX_GL_SAMPLE_BUFFERS_DATA 11
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
int COGL_ATT_LIST::m_openGL_attributes_list_to_use[
|
2019-01-06 16:43:12 +00:00
|
|
|
arrayDim( COGL_ATT_LIST::m_openGL_attributes_list ) ] = { 0 };
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
|
2020-04-17 21:33:23 +00:00
|
|
|
const int *COGL_ATT_LIST::GetAttributesList( ANTIALIASING_MODE aAntiAliasingMode )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2020-04-17 21:33:23 +00:00
|
|
|
wxASSERT( aAntiAliasingMode <= ANTIALIASING_MODE::AA_8X );
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
memcpy( m_openGL_attributes_list_to_use,
|
|
|
|
m_openGL_attributes_list,
|
|
|
|
sizeof( m_openGL_attributes_list_to_use ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-04-17 21:33:23 +00:00
|
|
|
if( aAntiAliasingMode > ANTIALIASING_MODE::AA_NONE )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2016-07-19 17:35:25 +00:00
|
|
|
// There is a bug on wxGLCanvas that makes IsDisplaySupported fail
|
|
|
|
// while testing for antialiasing.
|
|
|
|
// http://trac.wxwidgets.org/ticket/16909
|
|
|
|
// this next code will only work after this bug is fixed
|
|
|
|
//
|
|
|
|
// On my experience (Mario) it was only working on Linux but failing on
|
|
|
|
// Windows, so there was no AA.
|
|
|
|
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
// Check if the canvas supports multisampling.
|
2016-07-19 17:35:25 +00:00
|
|
|
if( wxGLCanvas::IsDisplaySupported( m_openGL_attributes_list_to_use ) )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2020-04-17 21:33:23 +00:00
|
|
|
static const int aaSamples[4] = {0, 2, 4, 8};
|
|
|
|
|
|
|
|
// Check for possible sample sizes, start form the requested.
|
|
|
|
int maxSamples = aaSamples[static_cast<int>( aAntiAliasingMode )];
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
m_openGL_attributes_list_to_use[ATT_WX_GL_SAMPLES_OFFSET_DATA] = maxSamples;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
for( ; (maxSamples > 0) &&
|
|
|
|
( !wxGLCanvas::IsDisplaySupported( m_openGL_attributes_list_to_use ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
maxSamples = maxSamples >> 1 )
|
|
|
|
{
|
2016-07-19 17:35:25 +00:00
|
|
|
m_openGL_attributes_list_to_use[ATT_WX_GL_SAMPLES_OFFSET_DATA] = maxSamples;
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-04-17 21:33:23 +00:00
|
|
|
aAntiAliasingMode = ANTIALIASING_MODE::AA_NONE;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Disable antialising if it failed or was not requested
|
2020-04-17 21:33:23 +00:00
|
|
|
if( aAntiAliasingMode == ANTIALIASING_MODE::AA_NONE )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2016-07-19 17:35:25 +00:00
|
|
|
// Remove multisampling information
|
|
|
|
// (hoping that the GPU driver will decide what is best)
|
|
|
|
m_openGL_attributes_list_to_use[ATT_WX_GL_SAMPLES_OFFSET] = 0;
|
|
|
|
m_openGL_attributes_list_to_use[ATT_WX_GL_SAMPLES_OFFSET_DATA] = 0;
|
|
|
|
m_openGL_attributes_list_to_use[ATT_WX_GL_SAMPLE_BUFFERS_OFFSET] = 0;
|
|
|
|
m_openGL_attributes_list_to_use[ATT_WX_GL_SAMPLE_BUFFERS_DATA] = 0;
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
return m_openGL_attributes_list_to_use;
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|