Equalizer
1.2.1
|
00001 00002 /* Copyright (c) 2005-2011, Stefan Eilemann <eile@equalizergraphics.com> 00003 * 2007-2011, Maxim Makhinya <maxmah@gmail.com> 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * - Redistributions of source code must retain the above copyright notice, this 00009 * list of conditions and the following disclaimer. 00010 * - Redistributions in binary form must reproduce the above copyright notice, 00011 * this list of conditions and the following disclaimer in the documentation 00012 * and/or other materials provided with the distribution. 00013 * - Neither the name of Eyescale Software GmbH nor the names of its 00014 * contributors may be used to endorse or promote products derived from this 00015 * software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 00028 * 00029 */ 00030 00031 00032 #include "aglWindowShared.h" 00033 00034 #ifdef AGL 00035 00036 namespace eqAsync 00037 { 00038 00039 AGLWindowShared::AGLWindowShared( eq::Window* parent, 00040 CGDirectDisplayID displayID ) 00041 : eq::agl::Window( parent, displayID ) 00042 {} 00043 00044 00045 AGLPixelFormat AGLWindowShared::chooseAGLPixelFormat() 00046 { 00047 eq::Global::enterCarbon(); 00048 00049 CGOpenGLDisplayMask glDisplayMask = 00050 CGDisplayIDToOpenGLDisplayMask( getCGDisplayID( )); 00051 00052 // build attribute list 00053 std::vector<GLint> attributes; 00054 00055 attributes.push_back( AGL_RGBA ); 00056 attributes.push_back( GL_TRUE ); 00057 attributes.push_back( AGL_ACCELERATED ); 00058 attributes.push_back( GL_TRUE ); 00059 00060 // 00061 // This condition is the only difference from the original function 00062 // 00063 if( getIAttribute( eq::Window::IATTR_HINT_FULLSCREEN ) == eq::ON ) 00064 { 00065 attributes.push_back( AGL_FULLSCREEN ); 00066 } 00067 00068 attributes.push_back( AGL_DISPLAY_MASK ); 00069 attributes.push_back( glDisplayMask ); 00070 00071 GLint colorSize = getIAttribute( eq::Window::IATTR_PLANES_COLOR ); 00072 if( colorSize != eq::OFF ) 00073 { 00074 switch( colorSize ) 00075 { 00076 case eq::RGBA16F: 00077 attributes.push_back( AGL_COLOR_FLOAT ); 00078 colorSize = 16; 00079 break; 00080 case eq::RGBA32F: 00081 attributes.push_back( AGL_COLOR_FLOAT ); 00082 colorSize = 32; 00083 break; 00084 case eq::AUTO: 00085 colorSize = 8; 00086 break; 00087 default: 00088 break; 00089 } 00090 00091 attributes.push_back( AGL_RED_SIZE ); 00092 attributes.push_back( colorSize ); 00093 attributes.push_back( AGL_GREEN_SIZE ); 00094 attributes.push_back( colorSize ); 00095 attributes.push_back( AGL_BLUE_SIZE ); 00096 attributes.push_back( colorSize ); 00097 00098 const int alphaSize = getIAttribute( eq::Window::IATTR_PLANES_ALPHA ); 00099 if( alphaSize > 0 || alphaSize == eq::AUTO ) 00100 { 00101 attributes.push_back( AGL_ALPHA_SIZE ); 00102 attributes.push_back( alphaSize > 0 ? alphaSize : colorSize ); 00103 } 00104 } 00105 00106 const int depthSize = getIAttribute( eq::Window::IATTR_PLANES_DEPTH ); 00107 if( depthSize > 0 || depthSize == eq::AUTO ) 00108 { 00109 attributes.push_back( AGL_DEPTH_SIZE ); 00110 attributes.push_back( depthSize>0 ? depthSize : 24 ); 00111 } 00112 const int stencilSize = getIAttribute( eq::Window::IATTR_PLANES_STENCIL ); 00113 if( stencilSize > 0 || stencilSize == eq::AUTO ) 00114 { 00115 attributes.push_back( AGL_STENCIL_SIZE ); 00116 attributes.push_back( stencilSize>0 ? stencilSize : 1 ); 00117 } 00118 const int accumSize = getIAttribute( eq::Window::IATTR_PLANES_ACCUM ); 00119 const int accumAlpha = getIAttribute( eq::Window::IATTR_PLANES_ACCUM_ALPHA); 00120 if( accumSize >= 0 ) 00121 { 00122 attributes.push_back( AGL_ACCUM_RED_SIZE ); 00123 attributes.push_back( accumSize ); 00124 attributes.push_back( AGL_ACCUM_GREEN_SIZE ); 00125 attributes.push_back( accumSize ); 00126 attributes.push_back( AGL_ACCUM_BLUE_SIZE ); 00127 attributes.push_back( accumSize ); 00128 attributes.push_back( AGL_ACCUM_ALPHA_SIZE ); 00129 attributes.push_back( accumAlpha >= 0 ? accumAlpha : accumSize ); 00130 } 00131 else if( accumAlpha >= 0 ) 00132 { 00133 attributes.push_back( AGL_ACCUM_ALPHA_SIZE ); 00134 attributes.push_back( accumAlpha ); 00135 } 00136 00137 const int samplesSize = getIAttribute( eq::Window::IATTR_PLANES_SAMPLES ); 00138 if( samplesSize >= 0 ) 00139 { 00140 attributes.push_back( AGL_SAMPLE_BUFFERS_ARB ); 00141 attributes.push_back( 1 ); 00142 attributes.push_back( AGL_SAMPLES_ARB ); 00143 attributes.push_back( samplesSize ); 00144 } 00145 00146 if( getIAttribute( eq::Window::IATTR_HINT_DOUBLEBUFFER ) == eq::ON || 00147 ( getIAttribute( eq::Window::IATTR_HINT_DOUBLEBUFFER ) == eq::AUTO && 00148 getIAttribute( eq::Window::IATTR_HINT_DRAWABLE ) == eq::WINDOW )) 00149 { 00150 attributes.push_back( AGL_DOUBLEBUFFER ); 00151 attributes.push_back( GL_TRUE ); 00152 } 00153 if( getIAttribute( eq::Window::IATTR_HINT_STEREO ) == eq::ON ) 00154 { 00155 attributes.push_back( AGL_STEREO ); 00156 attributes.push_back( GL_TRUE ); 00157 } 00158 00159 attributes.push_back( AGL_NONE ); 00160 00161 // build backoff list, least important attribute last 00162 std::vector<int> backoffAttributes; 00163 if( getIAttribute( eq::Window::IATTR_HINT_DOUBLEBUFFER ) == eq::AUTO && 00164 getIAttribute( eq::Window::IATTR_HINT_DRAWABLE ) == eq::WINDOW ) 00165 00166 backoffAttributes.push_back( AGL_DOUBLEBUFFER ); 00167 00168 if( stencilSize == eq::AUTO ) 00169 backoffAttributes.push_back( AGL_STENCIL_SIZE ); 00170 00171 // choose pixel format 00172 AGLPixelFormat pixelFormat = 0; 00173 while( true ) 00174 { 00175 pixelFormat = aglCreatePixelFormat( &attributes.front( )); 00176 00177 if( pixelFormat || // found one or 00178 backoffAttributes.empty( )) // nothing else to try 00179 00180 break; 00181 00182 // Gradually remove backoff attributes 00183 const GLint attribute = backoffAttributes.back(); 00184 backoffAttributes.pop_back(); 00185 00186 std::vector<GLint>::iterator iter = find( attributes.begin(), 00187 attributes.end(), attribute ); 00188 EQASSERT( iter != attributes.end( )); 00189 00190 attributes.erase( iter, iter+2 ); // remove two item (attr, value) 00191 } 00192 00193 if( !pixelFormat ) 00194 setError( eq::ERROR_SYSTEMWINDOW_PIXELFORMAT_NOTFOUND ); 00195 00196 eq::Global::leaveCarbon(); 00197 return pixelFormat; 00198 } 00199 00200 } // namespace eqAsync 00201 00202 #endif // AGL