0022819: Redesign of OpenGl driver
[occt.git] / src / OpenGl / OpenGl_GraphicDriver_9.cxx
index 30d29a0..5587b7b 100755 (executable)
-// File   OpenGl_GraphicDriver_9.cxx
-// Created  1/08/97
-// Author       PCT
-// Modified
-//    16-09-98 ; BGN : Points d'entree du Triedre (S3819, Phase 1)
-//    22-09-98 ; BGN : S3989 (anciennement S3819)
-//                               TypeOfTriedron* from Aspect (pas Graphic3d)
-
-//-Copyright  MatraDatavision 1997
-
-//-Version  
-
-//-Design Declaration des variables specifiques aux Drivers
-
-//-Warning  Un driver encapsule les Pex et OpenGl drivers
-
-//-References 
-
-//-Language C++ 2.0
-
-//-Declarations
+// File:      OpenGl_GraphicDriver_9.cxx
+// Created:   20 October 2011
+// Author:    Sergey ZERCHANINOV
+// Copyright: OPEN CASCADE 2011
+
+#include <OpenGl_GraphicDriver.hxx>
+#include <OpenGl_CView.hxx>
+#include <OpenGl_Trihedron.hxx>
+#include <OpenGl_GraduatedTrihedron.hxx>
+#include <OpenGl_TextureBox.hxx>
+#include <OpenGl_tgl_funcs.hxx>
 
-// for the class
+#include <Quantity_NameOfColor.hxx>
+#include <TColStd_HArray1OfReal.hxx>
+#include <AlienImage_AlienImage.hxx>
+#include <Image_Image.hxx>
 
-#define IMP131100 //GG_Enable to creates more than one texture
-//      with the same name.
+void OpenGl_GraphicDriver::Environment(const Graphic3d_CView& ACView)
+{
+  const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
+  if (aCView)
+  {
+    aCView->View->SetTextureEnv(ACView.Context.TexEnvId);
+    aCView->View->SetSurfaceDetail((Visual3d_TypeOfSurfaceDetail)ACView.Context.SurfaceDetail);
+  }
+}
 
-#define OCC1188         //SAV added methods to set background image
+//
+// Triedron methods : the Triedron is a non-zoomable object.
+//
 
-#include <OpenGl_GraphicDriver.jxx>
+void OpenGl_GraphicDriver::ZBufferTriedronSetup (
+  const Quantity_NameOfColor XColor,
+  const Quantity_NameOfColor YColor,
+  const Quantity_NameOfColor ZColor,
+  const Standard_Real        SizeRatio,
+  const Standard_Real        AxisDiametr,
+  const Standard_Integer     NbFacettes)
+{
+  OpenGl_Trihedron::Setup(XColor,YColor,ZColor,SizeRatio,AxisDiametr,NbFacettes);
+}
 
-#include <Aspect_DriverDefinitionError.hxx>
-#include <Quantity_NameOfColor.hxx>
-#include <AlienImage.hxx>
-#include <Standard_Integer.hxx>
+void OpenGl_GraphicDriver::TriedronDisplay (
+  const Graphic3d_CView& ACView,
+  const Aspect_TypeOfTriedronPosition APosition,
+  const Quantity_NameOfColor AColor, 
+  const Standard_Real AScale,
+  const Standard_Boolean AsWireframe )
+{
+  const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
+  if (aCView)
+  {
+    aCView->View->TriedronDisplay(APosition, AColor, AScale, AsWireframe);
+    aCView->WS->Invalidate();
+  }
+}
 
-#include <OpenGl_tgl_funcs.hxx>
+void OpenGl_GraphicDriver::TriedronErase (const Graphic3d_CView& ACView) 
+{
+  const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
+  if (aCView)
+  {
+    aCView->View->TriedronErase();
+    aCView->WS->Invalidate();
+  }
+}
 
-#include <stdlib.h>
-#include <stdio.h>
+void OpenGl_GraphicDriver::TriedronEcho (const Graphic3d_CView& ACView,const Aspect_TypeOfTriedronEcho AType )
+{
+  // Do nothing
+}
 
+void OpenGl_GraphicDriver::BackgroundImage( const Standard_CString FileName, 
+                                           const Graphic3d_CView& ACView,
+                                           const Aspect_FillMethod FillStyle )
+{
+  const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
+  if (aCView)
+  {
+    aCView->View->CreateBackgroundTexture( FileName, FillStyle );
+    aCView->WS->Invalidate();
+  }
+}
 
-#include <Image_Image.hxx>
+void OpenGl_GraphicDriver::SetBgImageStyle( const Graphic3d_CView& ACView,
+                                           const Aspect_FillMethod FillStyle )
+{
+  const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
+  if (aCView)
+  {
+    aCView->View->SetBackgroundTextureStyle( FillStyle );
+    aCView->WS->Invalidate();
+  }
+}
 
+void OpenGl_GraphicDriver::SetBgGradientStyle(const Graphic3d_CView& ACView,const Aspect_GradientFillMethod FillType)
+{
+  const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
+  if (aCView)
+  {
+    aCView->View->SetBackgroundGradientType(FillType);
+    aCView->WS->Invalidate();
+  }
+}
 
-//-Aliases
+void OpenGl_GraphicDriver::GraduatedTrihedronDisplay(const Graphic3d_CView& ACView, const Graphic3d_CGraduatedTrihedron& cubic)
+{
+  const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
+  if (aCView)
+  {
+    aCView->View->GraduatedTrihedronDisplay(cubic);
+    aCView->WS->Invalidate();
+  }
+}
 
-//-Global data definitions
+void OpenGl_GraphicDriver::GraduatedTrihedronErase(const Graphic3d_CView& ACView)
+{
+  const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
+  if (aCView)
+  {
+    aCView->View->GraduatedTrihedronErase();
+    aCView->WS->Invalidate();
+  }
+}
 
-//-Methods, in order
+void OpenGl_GraphicDriver::GraduatedTrihedronMinMaxValues(const Standard_ShortReal xmin,
+                                                         const Standard_ShortReal ymin,
+                                                         const Standard_ShortReal zmin,
+                                                         const Standard_ShortReal xmax,
+                                                         const Standard_ShortReal ymax,
+                                                         const Standard_ShortReal zmax)
+{
+  OpenGl_GraduatedTrihedron::SetMinMax(xmin, ymin, zmin, xmax, ymax, zmax);
+}
 
 // Helper function, returns the nearest power of two greater than the argument value
 inline Standard_Integer GetNearestPow2(Standard_Integer theValue)
@@ -59,13 +143,13 @@ inline Standard_Integer GetNearestPow2(Standard_Integer theValue)
   return aRes;
 }
 
-Standard_Integer OpenGl_GraphicDriver::CreateTexture(const Graphic3d_TypeOfTexture Type,const Handle_AlienImage_AlienImage &Image,const Standard_CString FileName,const Handle(TColStd_HArray1OfReal)& TexUpperBounds) const
+Standard_Integer OpenGl_GraphicDriver::CreateTexture (const Graphic3d_TypeOfTexture Type,
+                                                      const Handle_AlienImage_AlienImage &Image,
+                                                                                                         const Standard_CString FileName,
+                                                                                                         const Handle(TColStd_HArray1OfReal)& TexUpperBounds) const
 {
-  // transmutation de l'image en un bon tableau RGBA pour la toolkit des textures
-  // lamentable d'un point de vue vitesse...
   Handle(Image_Image) MyPic = Image->ToImage();
 
-  //TODO: The temporary fix in order to make AIS_TexturedShape work. To be improved in next release.
   Standard_Integer aGlWidth  = (Type == Graphic3d_TOT_2D_MIPMAP) ? MyPic->Width() : GetNearestPow2(MyPic->Width());
   Standard_Integer aGlHeight = (Type == Graphic3d_TOT_2D_MIPMAP) ? MyPic->Height() : GetNearestPow2(MyPic->Height());
 
@@ -81,15 +165,10 @@ Standard_Integer OpenGl_GraphicDriver::CreateTexture(const Graphic3d_TypeOfTextu
   if (MyImageData == NULL)
     return -1;
 
-#ifdef IMP131100
-
   static Standard_Integer textureRank=0;  
   char textureName[16];
   Standard_PCharacter fileName = textureName; 
   sprintf(fileName,"Tex%d",++textureRank);
-#else
-  Standard_CString fileName = FileName
-#endif
 
     for (j = MyPic->Height() - 1; j >= 0; j--)
       for (i = 0; i < aGlWidth; i++){
@@ -150,141 +229,3 @@ void OpenGl_GraphicDriver::ModifyTexture(const Standard_Integer TexId,const Grap
 {
   call_togl_modify_texture(TexId, (CALL_DEF_INIT_TEXTURE *)&AValue);
 }
-
-
-
-
-void OpenGl_GraphicDriver::Environment(const Graphic3d_CView& ACView)
-{
-  call_togl_environment((CALL_DEF_VIEW *)&ACView);
-}
-
-
-//
-// Triedron methods : the Triedron is a non-zoomable object.
-//
-
-void OpenGl_GraphicDriver::ZBufferTriedronSetup (
-  const Quantity_NameOfColor XColor,
-  const Quantity_NameOfColor YColor,
-  const Quantity_NameOfColor ZColor,
-  const Standard_Real        SizeRatio,
-  const Standard_Real        AxisDiametr,
-  const Standard_Integer     NbFacettes)
-{
-  float Xrgb[3];
-  float Yrgb[3];
-  float Zrgb[3];
-  Standard_Real R,G,B;
-  Quantity_Color(XColor).Values(R, G, B, Quantity_TOC_RGB);
-  Xrgb[0] = float (R);
-  Xrgb[1] = float (G);
-  Xrgb[2] = float (B);
-  Quantity_Color(YColor).Values(R, G, B, Quantity_TOC_RGB);
-  Yrgb[0] = float (R);
-  Yrgb[1] = float (G);
-  Yrgb[2] = float (B);
-  Quantity_Color(ZColor).Values(R, G, B, Quantity_TOC_RGB);
-  Zrgb[0] = float (R);
-  Zrgb[1] = float (G);
-  Zrgb[2] = float (B);
-
-  call_togl_ztriedron_setup(Xrgb, Yrgb, Zrgb, 
-    (Standard_ShortReal)(SizeRatio), (Standard_ShortReal)(AxisDiametr), NbFacettes);
-}
-
-void OpenGl_GraphicDriver::TriedronDisplay (
-  const Graphic3d_CView& ACView,
-  const Aspect_TypeOfTriedronPosition APosition,
-  const Quantity_NameOfColor AColor, 
-  const Standard_Real AScale,
-  const Standard_Boolean AsWireframe )
-{
-  Standard_Real R,G,B;
-  float r,g,b;
-  Quantity_Color Color(AColor);
-  Color.Values(R,G,B,Quantity_TOC_RGB);
-  r = float (R);
-  g = float (G);
-  b = float (B);
-
-  call_togl_triedron_display((CALL_DEF_VIEW *)&ACView,(int)APosition, r,g,b, (float)AScale, AsWireframe);
-}
-
-void OpenGl_GraphicDriver::TriedronErase (const Graphic3d_CView& ACView) 
-{
-  call_togl_triedron_erase((CALL_DEF_VIEW *)&ACView);
-}
-
-void OpenGl_GraphicDriver::TriedronEcho (const Graphic3d_CView& ACView,const Aspect_TypeOfTriedronEcho AType )
-{
-  call_togl_triedron_echo( (CALL_DEF_VIEW *)&ACView,AType );
-}
-
-void OpenGl_GraphicDriver::BackgroundImage( const Standard_CString FileName, 
-                                            const Graphic3d_CView& ACView,
-                                            const Aspect_FillMethod FillStyle )
-{
-#ifdef OCC1188
-  Graphic3d_CView MyCView = ACView;
-  Standard_Integer width, height;
-  Handle(Image_Image) image;
-
-  Standard_Boolean result = AlienImage::LoadImageFile( FileName, image, width, height );
-
-  if ( result ) {
-    unsigned char *data = (unsigned char*)malloc( width * height * 3 );
-    unsigned char *pdata = data;
-    Standard_Integer i,j;
-    Quantity_Color color;
-
-    if ( data != NULL ) {
-      for ( j = height - 1; j >= 0; j-- )
-        for ( i = 0; i < width; i++ ) {
-          color = image->PixelColor( i, j );
-          *pdata++ = (int)( 255 * color.Red() );
-          *pdata++ = (int)( 255 * color.Green() );
-          *pdata++ = (int)( 255 * color.Blue() );
-        }
-        call_togl_create_bg_texture( (CALL_DEF_VIEW*)&MyCView, width, height, data, (int)FillStyle );
-        // delete data here
-        free( data );
-    }
-  }
-#endif // OCC1188
-}
-
-void OpenGl_GraphicDriver::SetBgImageStyle( const Graphic3d_CView& ACView,
-                                            const Aspect_FillMethod FillStyle )
-{
-#ifdef OCC1188
-  Graphic3d_CView MyCView = ACView;
-  call_togl_set_bg_texture_style( (CALL_DEF_VIEW*)&MyCView, (int)FillStyle );
-#endif //OCC1188
-}
-
-void OpenGl_GraphicDriver::SetBgGradientStyle(const Graphic3d_CView& ACView,const Aspect_GradientFillMethod FillType)
-{ 
-  call_togl_set_gradient_type( ACView.WsId, FillType);
-}
-
-void OpenGl_GraphicDriver::GraduatedTrihedronDisplay(const Graphic3d_CView& view,
-                                                     const Graphic3d_CGraduatedTrihedron& cubic)
-{
-    call_togl_graduatedtrihedron_display((CALL_DEF_VIEW*)&view, cubic);
-}
-
-void OpenGl_GraphicDriver::GraduatedTrihedronErase(const Graphic3d_CView& view)
-{
-    call_togl_graduatedtrihedron_erase((CALL_DEF_VIEW*)&view);
-}
-
-void OpenGl_GraphicDriver::GraduatedTrihedronMinMaxValues(const Standard_ShortReal xmin,
-                                                          const Standard_ShortReal ymin,
-                                                          const Standard_ShortReal zmin,
-                                                          const Standard_ShortReal xmax,
-                                                          const Standard_ShortReal ymax,
-                                                          const Standard_ShortReal zmax)
-{
-    call_togl_graduatedtrihedron_minmaxvalues(xmin, ymin, zmin, xmax, ymax, zmax);
-}
\ No newline at end of file