0024345: TKOpenGl - GLSL compatibility issues on NV40 (GeForce 6xxx/7xxx)
[occt.git] / src / OpenGl / OpenGl_telem_util.cxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 //
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
8 //
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 //
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
18
19 /***********************************************************************
20
21 FONCTION :
22 ----------
23 File OpenGl_telem_util :
24
25
26 REMARQUES:
27 ---------- 
28
29
30 HISTORIQUE DES MODIFICATIONS   :
31 --------------------------------
32 xx-xx-xx : xxx ; Creation.
33 07-02-96 : FMN ; - Ajout trace
34 - Suppression code inutile
35 08-03-96 : FMN ; - Ajout include manquant 
36 01-04-96 : CAL ; Integration MINSK portage WNT
37 15-04-96 : CAL ; Integration travail PIXMAP de Jim ROTH
38 22-04-96 : FMN ; Ajout TelReadImage TelDrawImage
39 10-05-96 : CAL ; Ajout d'un nouveau delta dans les copies
40 de pixels (voir CALL_DEF_DELTA)
41 25-06-96 : FMN ; Suppression utilisation de glScissor.
42 02-07-96 : FMN ; Suppression WSWSHeight et WSWSWidth
43 Suppression glViewport inutile.
44 18-07-96 : FMN ; Suppression TelFlush inutile.
45 08-07-96 : FMN ; Suppression de OPENGL_DEBUG inutile avec la nouvelle
46 version de ogldebug.
47 24-10-96 : CAL ; Portage WNT
48 23-01-97 : CAL ; Suppression de TelClearViews dans TelCopyBuffers
49 30-01-97 : FMN ; Ajout commentaires + WNT.
50 12-02-97 : FMN ; Suppression TelEnquireFacilities()
51 22-04-97 : FMN ; Ajout affichage du cadre pour la copie de buffer
52 30-06-97 : FMN ; Suppression OpenGl_telem_light.h
53 18-07-97 : FMN ; Utilisation de la toolkit sur les lights
54 07-10-97 : FMN ; Simplification WNT + correction Transient
55 05-12-97 : FMN ; PRO11168: Suppression TglActiveWs pour project/unproject
56 23-12-97 : FMN ; Suppression TelSetFrontFaceAttri et TelSetBackFaceAttri 
57 30-12-97 : FMN ; CTS18312: Correction back material
58 04-05-98 : CAL ; Contournement bug SGI octane bavure de pixels (PRO12899)
59 30-09-98 : CAL ; Optimisation pour eviter de charger inutilement
60 les matrices de la vue.
61 19-10-98 : FMN ; Suppression de glPixelTransferi dans TelEnable() car cela
62 rentre en conflit avec l'utilisation d'une image de fond.
63 02.14.100 : JR : Warnings on WNT truncations from double to float
64 08-03-01 : GG  ; BUC60823 Avoid crash in the normal computation method
65 when a face has confused or aligned points.
66
67 ************************************************************************/
68
69 #include <stdio.h>
70
71 #include <OpenGl_GlCore11.hxx>
72
73 #include <OpenGl_telem_util.hxx>
74 #include <InterfaceGraphic_Graphic3d.hxx>
75 #include <InterfaceGraphic_Visual3d.hxx>
76
77 #define GPRECIS 0.000001
78 Tint TelGetPolygonNormal(tel_point pnts, Tint* indexs, Tint npnt, Tfloat *norm ) {
79   Tint status=0;
80
81   norm[0] = norm[1] = norm[2] = 0.;
82   if( npnt > 2 ) { 
83     Tfloat a[3], b[3], c[3];
84     Tint i,j,i0,ii=0,jj;
85
86     i0 = 0; if( indexs ) i0 = indexs[0];
87     for( i=1 ; i<npnt ; i++ ) {
88       ii = i; if( indexs ) ii = indexs[i];
89       vecsub( a, pnts[ii].xyz, pnts[i0].xyz );
90       if( vecmg2(a) > GPRECIS ) break;
91     }
92     if( i < npnt-1 ) {
93       for( j=i+1 ; j<npnt ; j++ ) {
94         jj = j; if( indexs ) jj = indexs[j];
95         vecsub( b, pnts[jj].xyz, pnts[i0].xyz );
96         vecsub( c, pnts[jj].xyz, pnts[ii].xyz );
97         if( (vecmg2(b) > GPRECIS) && (vecmg2(c) > GPRECIS) ) break;
98       }
99       if( j < npnt ) {
100         Tfloat d;
101         veccrs( norm, a, b );
102         d = vecnrmd( norm, d );
103         status = (d > 0.) ? 1 : 0;
104       }
105     }
106   }
107 #ifdef DEB
108   if( !status )
109     printf(" *** OpenGl_TelGetPolygonNormal.has found confused or aligned points\n");
110 #endif
111
112   return status;
113 }
114
115 Tint TelGetNormal(Tfloat *data1, Tfloat *data2, Tfloat *data3, Tfloat *norm ) {
116   Tfloat a[3], b[3];
117   Tint status=0;
118
119   norm[0] = norm[1] = norm[2] = 0.;
120   vecsub( a, data2, data1 );
121   vecsub( b, data3, data2 );
122   if( (vecmg2(a) > GPRECIS) && (vecmg2(b) > GPRECIS) ) {
123     Tfloat d;
124     veccrs( norm, a, b );
125     d = vecnrmd( norm, d );
126     status = (d > 0.) ? 1 : 0;
127   }
128 #ifdef DEB
129   if( !status )
130     printf(" *** OpenGl_TelGetNormal.has found confused or aligned points\n");
131 #endif
132
133   return status;
134 }
135
136 void TelMultiplymat3 (Tmatrix3 c, Tmatrix3 a, Tmatrix3 b)
137 {
138   Tint row, col, i;
139   Tmatrix3 res;
140   Tint dim = 4;
141
142   /* on multiplie d'abord les 2 matrices dim x dim */
143   for (row = 0; row < dim; row++) {
144     for (col = 0; col < dim; col++) {
145       Tfloat sum = ( float )0.0;
146       for (i = 0; i < dim; i++)
147         sum += a[row][i] * b[i][col];
148       res[row][col] = sum;
149     }
150   }
151
152   /* on copie ensuite le resultat */
153   matcpy (c, res);
154
155   return;
156 }