Salome HOME
updated copyright message
[modules/gui.git] / src / GLViewer / GLViewer_Drawer.cxx
index 612234c05ddd92c77f61910ff15ee3b59b0a5cd9..bbe2b533bac34e3f10167f78b90a4ba8d02234fb 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -36,7 +36,9 @@
 #include <QPainter>
 #include <QFile>
 
-#ifndef WIN32
+#if defined(__APPLE__)
+#include <OpenGL/CGLCurrent.h>
+#elif !defined(WIN32)
 #include <GL/glx.h>
 #endif
 
@@ -75,7 +77,7 @@ void GLViewer_TexFont::clearTextBases()
   Default constructor
 */
 GLViewer_TexFont::GLViewer_TexFont()
-: myMaxRowWidth( 0 ), myFontHeight( 0 )
+: myFontHeight( 0 ), myMaxRowWidth( 0 )
 {
     myQFont = QApplication::font();//QFont::defaultFont();
     mySeparator = 2;
@@ -93,7 +95,7 @@ GLViewer_TexFont::GLViewer_TexFont()
   \param theMinMagFilter - min/mag filter, affects text sharpness
 */
 GLViewer_TexFont::GLViewer_TexFont( QFont* theFont, int theSeparator, bool theIsResizeable, GLuint theMinMagFilter )
-: myMaxRowWidth( 0 ), myFontHeight( 0 )
+: myFontHeight( 0 ), myMaxRowWidth( 0 )
 {
     myQFont = *theFont;
     mySeparator = theSeparator;
@@ -159,7 +161,7 @@ bool GLViewer_TexFont::generateTexture()
     aFindFont.myIsItal = myQFont.italic();
     aFindFont.myIsUndl = myQFont.underline();
     aFindFont.myPointSize = myQFont.pointSize();
-    aFindFont.myViewPortId = size_t(QGLContext::currentContext());
+    aFindFont.myViewPortId = (long)QGLContext::currentContext(); //!<TODO: conversion from "size_t" to "long"
         
     if( TexFontBase.contains( aFindFont ) )
     {
@@ -377,12 +379,12 @@ static GLuint displayListBase( QFont* theFont )
   aFindFont.myIsUndl = theFont->underline();
   aFindFont.myPointSize = theFont->pointSize();
 
-#ifdef WIN32
+#if defined(WIN32)
   HGLRC ctx = ::wglGetCurrentContext();
   if ( !ctx )
     return aList;  
   
-  aFindFont.myViewPortId = (int)ctx;
+  aFindFont.myViewPortId = (LONG_PTR)ctx;
 
   if ( GLViewer_TexFont::BitmapFontCache.contains( aFindFont ) )
     aList = GLViewer_TexFont::BitmapFontCache[aFindFont];
@@ -392,18 +394,44 @@ static GLuint displayListBase( QFont* theFont )
     QMap<GLViewer_TexFindId, GLuint>::iterator it = GLViewer_TexFont::BitmapFontCache.begin();
     for ( ; it != GLViewer_TexFont::BitmapFontCache.end(); ++it )
     {
-      if ( it.key().myViewPortId == (int)ctx && it.value() > listBase )
+      if ( it.key().myViewPortId == (LONG_PTR)ctx && it.value() > listBase )
         listBase = it.value();
     }
     listBase += 256;
 
     HDC glHdc = ::wglGetCurrentDC();
-    ::SelectObject( glHdc, theFont->handle() );
     if ( !::wglUseFontBitmaps( glHdc, 0, 256, listBase ) )
       listBase = 0;
     aList = listBase;
     GLViewer_TexFont::BitmapFontCache[aFindFont] = aList;
   }
+#elif defined(__APPLE__)
+  CGLContextObj ctx = ::CGLGetCurrentContext();
+  if ( !ctx )
+    return aList;
+
+  aFindFont.myViewPortId = (long)ctx;
+
+  if ( GLViewer_TexFont::BitmapFontCache.contains( aFindFont ) )
+    aList = GLViewer_TexFont::BitmapFontCache[aFindFont];
+  else
+  {
+    GLuint listBase = 0;
+    QMap<GLViewer_TexFindId, GLuint>::iterator it = GLViewer_TexFont::BitmapFontCache.begin();
+    for ( ; it != GLViewer_TexFont::BitmapFontCache.end(); ++it )
+    {
+      if ( it.key().myViewPortId == (long)ctx && it.value() > listBase )
+        listBase = it.value();
+    }
+    listBase += 256;
+
+    //HDC glHdc = ::wglGetCurrentDC();
+    //::SelectObject( glHdc, theFont->handle() );
+    //if ( !::wglUseFontBitmaps( glHdc, 0, 256, listBase ) )
+    //  listBase = 0;
+    aList = listBase;
+    GLViewer_TexFont::BitmapFontCache[aFindFont] = aList;
+  }
 #else //X Window
   Display* aDisp = glXGetCurrentDisplay();
   if( !aDisp )
@@ -423,7 +451,7 @@ static GLuint displayListBase( QFont* theFont )
     return aList;
   }
 
-  aFindFont.myViewPortId = size_t(aCont);
+  aFindFont.myViewPortId = (long)aCont;
 
   if ( GLViewer_TexFont::BitmapFontCache.contains( aFindFont ) )
     aList = GLViewer_TexFont::BitmapFontCache[aFindFont];
@@ -433,7 +461,7 @@ static GLuint displayListBase( QFont* theFont )
     QMap<GLViewer_TexFindId, GLuint>::iterator it = GLViewer_TexFont::BitmapFontCache.begin();
     for ( ; it != GLViewer_TexFont::BitmapFontCache.end(); ++it )
     {
-      if ( it.key().myViewPortId == size_t(aCont) && it.value() > listBase )
+      if ( it.key().myViewPortId == (long)aCont && it.value() > listBase )
         listBase = it.value();
     }
     listBase += 256;
@@ -442,30 +470,25 @@ static GLuint displayListBase( QFont* theFont )
     int aFontCont = 0;
     QString aFontDef = theFont->toString();
     char** xFontList = XListFonts( aDisp, aFontDef.toLatin1()/*aFindFont.myFontString.data()*/, 1, &aFontCont  );
-    if( !theFont->handle() )
-    {       
+// TODO (QT5 PORTING) Below is a temporary solution, to allow compiling with Qt 5
 #ifdef _DEBUG_
-      printf( "Can't load font %s. loading default font....\n", aFontDef.toLatin1().data()/*aFindFont.myFontString.data()*/ );
+    printf( "Can't load font %s. loading default font....\n", aFontDef.toLatin1().data()/*aFindFont.myFontString.data()*/ );
 #endif
-      QString aFontMask ("-*-*-*-r-*-*-");
-      aFontMask += aFontDef/*aFindFont.myFontString*/.section( ',', 1, 1 );
+    QString aFontMask ("-*-*-*-r-*-*-");
+    aFontMask += aFontDef/*aFindFont.myFontString*/.section( ',', 1, 1 );
 #ifdef _DEBUG_
-      printf( "Height of Default font: %s\n", aFontDef/*aFindFont.myFontString*/.section( ',', 1, 1 ).data() );
+    printf( "Height of Default font: %s\n", aFontDef/*aFindFont.myFontString*/.section( ',', 1, 1 ).data() );
 #endif
-      aFontMask += "-*-*-*-m-*-*-*";
-      xFontList = XListFonts( aDisp, aFontMask.toLatin1().constData()/*"-*-*-*-r-*-*-12-*-*-*-m-*-*-*"*/, 1, &aFontCont  );
-      if( aFontCont == 0 )
-      {      
+    aFontMask += "-*-*-*-m-*-*-*";
+    xFontList = XListFonts( aDisp, aFontMask.toLatin1().constData()/*"-*-*-*-r-*-*-12-*-*-*-m-*-*-*"*/, 1, &aFontCont  );
+    if( aFontCont == 0 )
+    {
 #ifdef _DEBUG_
-        printf( "Can't load default font\n" );
+      printf( "Can't load default font\n" );
 #endif
-        return 0;
-      }
-      glXUseXFont( (Font)(XLoadFont( aDisp,xFontList[0] )), 0, 256, listBase );
+      return 0;
     }
-    else
-      glXUseXFont( (Font)(theFont->handle()), 0, 256, listBase );
-    
+    glXUseXFont( (Font)(XLoadFont( aDisp,xFontList[0] )), 0, 256, listBase );
     aList = listBase;
     GLViewer_TexFont::BitmapFontCache[aFindFont] = aList;
   }