kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #14191
[PATCH] Anti-aliasing for the 3D-Viewer
Heyho,
please feel free to test and apply the attached patch for the 3D viewer.
It'll enable anti-aliasing - if the renderer supports it with up to
factor 8 (beyond this there was no difference in the subtracted images).
The code also deals with the possible changes to the attributes array
(avoiding fixed indices).
For the results see http://imgur.com/a/TgaXT .
Bye,
imp
=== modified file '3d-viewer/3d_frame.cpp'
--- 3d-viewer/3d_frame.cpp 2014-07-30 15:39:55 +0000
+++ 3d-viewer/3d_frame.cpp 2014-08-03 00:56:01 +0000
@@ -107,8 +107,51 @@
ReCreateMainToolbar();
// Make a EDA_3D_CANVAS
- int attrs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 16,
- WX_GL_STENCIL_SIZE, 1, 0 };
+ int attrs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER,
+ WX_GL_DEPTH_SIZE, 16,
+ WX_GL_STENCIL_SIZE, 1,
+ WX_GL_SAMPLE_BUFFERS, 1, // Enable multisampling support (antialiasing).
+ WX_GL_SAMPLES, 0, // Disable AA for the start.
+ 0 }; // NULL termination
+
+ unsigned int ii;
+
+ // Check if the canvas supports multisampling.
+ if( EDA_3D_CANVAS::IsDisplaySupported( attrs ) )
+ {
+ // Check for possible sample sizes, start form the top.
+ int maxSamples = 8; // Any higher doesn't change anything.
+ int samplesOffset = 0;
+
+ for( ii = 0; ii < sizeof( attrs ); ii += 2)
+ {
+ if( attrs[ii] == WX_GL_SAMPLES )
+ {
+ samplesOffset = ii+1;
+ break;
+ }
+ }
+
+ attrs[samplesOffset] = maxSamples;
+
+ for( ; maxSamples > 0 && !EDA_3D_CANVAS::IsDisplaySupported( attrs );
+ maxSamples = maxSamples>>1 )
+ {
+ attrs[samplesOffset] = maxSamples;
+ }
+ }
+ else
+ {
+ // Disable multisampling
+ for( ii = 0; ii < sizeof( attrs ); ii += 2){
+ if( attrs[ii] == WX_GL_SAMPLE_BUFFERS )
+ {
+ attrs[ii+1] = 0;
+ break;
+ }
+ }
+ }
+
m_canvas = new EDA_3D_CANVAS( this, attrs );
m_auimgr.SetManagedWindow( this );
Follow ups