0032289: Visualization - add NCollection_Mat3 for 3x3 matrix similar to NCollection_Mat4 IR-2021-04-09
authorkgv <kgv@opencascade.com>
Fri, 9 Apr 2021 09:16:55 +0000 (12:16 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 9 Apr 2021 15:12:05 +0000 (18:12 +0300)
Introduced NCollection_Mat3 class similar to NCollection_Mat4.
Added NCollection_Mat4::operator() alias to NCollection_Mat4::Value().
Added NCollection_Mat4::Negated(), ::Subtracted(), ::Added(), ::Divided() operations.
Added a note to NCollection_Mat4::GetData() that matrix values are stored in column-major order.
Removed duplicated operator== operators from NCollection_Mat4/NCollection_Vec4/NCollection_Vec3/NCollection_Vec2 classes.

Removed obsolete and no more used matrix state fields from OpenGl_Workspace.
Removed obsoiete structure OpenGl_Matrix (replaced by OpenGl_Mat4).
OpenGl_ShaderProgram - duplicated methods have been replaced by templates.

21 files changed:
src/BVH/BVH.cxx
src/NCollection/FILES
src/NCollection/NCollection_Mat3.hxx [new file with mode: 0644]
src/NCollection/NCollection_Mat4.hxx
src/NCollection/NCollection_Vec2.hxx
src/NCollection/NCollection_Vec3.hxx
src/NCollection/NCollection_Vec4.hxx
src/OpenGl/FILES
src/OpenGl/OpenGl_CappingAlgo.cxx
src/OpenGl/OpenGl_CappingPlaneResource.cxx
src/OpenGl/OpenGl_CappingPlaneResource.hxx
src/OpenGl/OpenGl_Context.cxx
src/OpenGl/OpenGl_Matrix.hxx [deleted file]
src/OpenGl/OpenGl_ShaderManager.cxx
src/OpenGl/OpenGl_ShaderProgram.cxx
src/OpenGl/OpenGl_ShaderProgram.hxx
src/OpenGl/OpenGl_Structure.hxx
src/OpenGl/OpenGl_View.hxx
src/OpenGl/OpenGl_Workspace.cxx
src/OpenGl/OpenGl_Workspace.hxx
src/Standard/Standard_Dump.hxx

index 671844e..105f71f 100644 (file)
@@ -34,6 +34,8 @@ IMPLEMENT_STANDARD_RTTIEXT(BVH_ObjectTransient,   Standard_Transient)
 template class NCollection_Vec2<Standard_Real>;
 template class NCollection_Vec3<Standard_Real>;
 template class NCollection_Vec4<Standard_Real>;
+template class NCollection_Mat3<Standard_Real>;
+template class NCollection_Mat4<Standard_Real>;
 
 template class BVH_Box<Standard_Real, 2>;
 template class BVH_Box<Standard_Real, 3>;
index 56dceba..6e92b94 100755 (executable)
@@ -51,6 +51,7 @@ NCollection_List.hxx
 NCollection_ListNode.hxx
 NCollection_LocalArray.hxx
 NCollection_Map.hxx
+NCollection_Mat3.hxx
 NCollection_Mat4.hxx
 NCollection_Sequence.hxx
 NCollection_Shared.hxx
diff --git a/src/NCollection/NCollection_Mat3.hxx b/src/NCollection/NCollection_Mat3.hxx
new file mode 100644 (file)
index 0000000..578edd8
--- /dev/null
@@ -0,0 +1,522 @@
+// Copyright (c) 2020 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef _NCollection_Mat3_HeaderFile
+#define _NCollection_Mat3_HeaderFile
+
+#include <NCollection_Vec3.hxx>
+#include <Standard_ConstructionError.hxx>
+
+//! 3x3 Matrix class.
+//! Warning, empty constructor returns an identity matrix.
+template<typename Element_t>
+class NCollection_Mat3
+{
+public:
+
+  //! Return identity matrix.
+  static NCollection_Mat3 Identity()
+  {
+    return NCollection_Mat3();
+  }
+
+  //! Return zero matrix.
+  static NCollection_Mat3 Zero()
+  {
+    NCollection_Mat3 aMat; aMat.InitZero();
+    return aMat;
+  }
+
+public:
+
+  //! Empty constructor for identity matrix.
+  NCollection_Mat3()
+  {
+    InitIdentity();
+  }
+
+  //! Conversion constructor (explicitly converts some 3x3 matrix with other element type
+  //! to a new 3x3 matrix with the element type Element_t,
+  //! whose elements are static_cast'ed corresponding elements of theOtherMat3 matrix)
+  //! @tparam OtherElement_t the element type of the other 3x3 matrix theOtherVec3
+  //! @param theOtherMat3 the 3x3 matrix that needs to be converted
+  template <typename OtherElement_t>
+  explicit NCollection_Mat3 (const NCollection_Mat3<OtherElement_t>& theOtherMat3)
+  {
+    ConvertFrom (theOtherMat3);
+  }
+
+  //! Get element at the specified row and column.
+  //! @param theRow [in] the row.to address.
+  //! @param theCol [in] the column to address.
+  //! @return the value of the addressed element.
+  Element_t GetValue (const size_t theRow, const size_t theCol) const
+  {
+    return myMat[theCol * 3 + theRow];
+  }
+
+  //! Access element at the specified row and column.
+  //! @param theRow [in] the row.to access.
+  //! @param theCol [in] the column to access.
+  //! @return reference on the matrix element.
+  Element_t& ChangeValue (const size_t theRow, const size_t theCol)
+  {
+    return myMat[theCol * 3 + theRow];
+  }
+
+  //! Set value for the element specified by row and columns.
+  //! @param theRow   [in] the row to change.
+  //! @param theCol   [in] the column to change.
+  //! @param theValue [in] the value to set.s
+  void SetValue (const size_t    theRow,
+                 const size_t    theCol,
+                 const Element_t theValue)
+  {
+    myMat[theCol * 3 + theRow] = theValue;
+  }
+
+  //! Return value.
+  Element_t& operator()(const size_t theRow, const size_t theCol) { return ChangeValue (theRow, theCol); }
+
+  //! Return value.
+  Element_t  operator()(const size_t theRow, const size_t theCol) const { return GetValue (theRow, theCol); }
+
+  //! Return the row.
+  NCollection_Vec3<Element_t> GetRow (const size_t theRow) const
+  {
+    return NCollection_Vec3<Element_t> (GetValue (theRow, 0), GetValue (theRow, 1), GetValue (theRow, 2));
+  }
+
+  //! Change first 3 row values by the passed vector.
+  //! @param theRow [in] the row to change.
+  //! @param theVec [in] the vector of values.
+  void SetRow (const size_t theRow, const NCollection_Vec3<Element_t>& theVec)
+  {
+    SetValue (theRow, 0, theVec.x());
+    SetValue (theRow, 1, theVec.y());
+    SetValue (theRow, 2, theVec.z());
+  }
+
+  //! Return the column.
+  NCollection_Vec3<Element_t> GetColumn (const size_t theCol) const
+  {
+    return NCollection_Vec3<Element_t> (GetValue (0, theCol), GetValue (1, theCol), GetValue (2, theCol));
+  }
+
+  //! Change first 3 column values by the passed vector.
+  //! @param theCol [in] the column to change.
+  //! @param theVec [in] the vector of values.
+  void SetColumn (const size_t theCol,
+                  const NCollection_Vec3<Element_t>& theVec)
+  {
+    SetValue (0, theCol, theVec.x());
+    SetValue (1, theCol, theVec.y());
+    SetValue (2, theCol, theVec.z());
+  }
+
+  //! Get vector of diagonal elements.
+  //! @return vector of diagonal elements.
+  NCollection_Vec3<Element_t> GetDiagonal() const
+  {
+    return NCollection_Vec3<Element_t> (GetValue (0, 0), GetValue (1, 1), GetValue (2, 2));
+  }
+
+  //! Change first 3 elements of the diagonal matrix.
+  //! @param theVec the vector of values.
+  void SetDiagonal (const NCollection_Vec3<Element_t>& theVec)
+  {
+    SetValue (0, 0, theVec.x());
+    SetValue (1, 1, theVec.y());
+    SetValue (2, 2, theVec.z());
+  }
+
+  //! Initialize the zero matrix.
+  void InitZero()
+  {
+    std::memcpy (this, MyZeroArray, sizeof (NCollection_Mat3));
+  }
+
+  //! Checks the matrix for zero (without tolerance).
+  bool IsZero() const
+  {
+    return std::memcmp (this, MyZeroArray, sizeof (NCollection_Mat3)) == 0;
+  }
+
+  //! Initialize the identity matrix.
+  void InitIdentity()
+  {
+    std::memcpy (this, MyIdentityArray, sizeof (NCollection_Mat3));
+  }
+
+  //! Checks the matrix for identity (without tolerance).
+  bool IsIdentity() const
+  {
+    return std::memcmp (this, MyIdentityArray, sizeof (NCollection_Mat3)) == 0;
+  }
+
+  //! Check this matrix for equality with another matrix (without tolerance!).
+  bool IsEqual (const NCollection_Mat3& theOther) const
+  {
+    return std::memcmp (this, &theOther, sizeof(NCollection_Mat3)) == 0;
+  }
+
+  //! Comparison operator.
+  bool operator== (const NCollection_Mat3& theMat) const { return IsEqual (theMat); }
+
+  //! Check this vector with another vector for non-equality (without tolerance!).
+  bool operator!= (const NCollection_Mat3& theOther) const { return !IsEqual (theOther); }
+
+  //! Raw access to the data (for OpenGL exchange).
+  //! the data is returned in column-major order.
+  const Element_t* GetData()    const { return myMat; }
+  Element_t*       ChangeData()       { return myMat; }
+
+  //! Multiply by the vector (M * V).
+  //! @param theVec [in] the vector to multiply.
+  NCollection_Vec3<Element_t> operator* (const NCollection_Vec3<Element_t>& theVec) const
+  {
+    return NCollection_Vec3<Element_t> (
+      GetValue (0, 0) * theVec.x() + GetValue (0, 1) * theVec.y() + GetValue (0, 2) * theVec.z(),
+      GetValue (1, 0) * theVec.x() + GetValue (1, 1) * theVec.y() + GetValue (1, 2) * theVec.z(),
+      GetValue (2, 0) * theVec.x() + GetValue (2, 1) * theVec.y() + GetValue (2, 2) * theVec.z());
+  }
+
+  //! Compute matrix multiplication product: A * B.
+  //! @param theMatA [in] the matrix "A".
+  //! @param theMatB [in] the matrix "B".
+  static NCollection_Mat3 Multiply (const NCollection_Mat3& theMatA,
+                                    const NCollection_Mat3& theMatB)
+  {
+    NCollection_Mat3 aMatRes;
+
+    size_t aInputElem;
+    for (size_t aResElem = 0; aResElem < 9; ++aResElem)
+    {
+      aMatRes.myMat[aResElem] = (Element_t )0;
+      for (aInputElem = 0; aInputElem < 3; ++aInputElem)
+      {
+        aMatRes.myMat[aResElem] += theMatA.GetValue(aResElem % 3, aInputElem)
+                                 * theMatB.GetValue(aInputElem, aResElem / 3);
+      }
+    }
+
+    return aMatRes;
+  }
+
+  //! Compute matrix multiplication.
+  //! @param theMat [in] the matrix to multiply.
+  void Multiply (const NCollection_Mat3& theMat)
+  {
+    *this = Multiply(*this, theMat);
+  }
+
+  //! Multiply by the another matrix.
+  //! @param theMat [in] the other matrix.
+  NCollection_Mat3& operator*= (const NCollection_Mat3& theMat)
+  {
+    Multiply (theMat);
+    return *this;
+  }
+
+  //! Compute matrix multiplication product.
+  //! @param theMat [in] the other matrix.
+  //! @return result of multiplication.
+  Standard_NODISCARD NCollection_Mat3 operator* (const NCollection_Mat3& theMat) const
+  {
+    return Multiplied (theMat);
+  }
+
+  //! Compute matrix multiplication product.
+  //! @param theMat [in] the other matrix.
+  //! @return result of multiplication.
+  Standard_NODISCARD NCollection_Mat3 Multiplied (const NCollection_Mat3& theMat) const
+  {
+    NCollection_Mat3 aTempMat (*this);
+    aTempMat *= theMat;
+    return aTempMat;
+  }
+
+  //! Compute per-component multiplication.
+  //! @param theFactor [in] the scale factor.
+  void Multiply (const Element_t theFactor)
+  {
+    for (size_t i = 0; i < 9; ++i)
+    {
+      myMat[i] *= theFactor;
+    }
+  }
+
+  //! Compute per-element multiplication.
+  //! @param theFactor [in] the scale factor.
+  NCollection_Mat3& operator*= (const Element_t theFactor)
+  {
+    Multiply (theFactor);
+    return *this;
+  }
+
+  //! Compute per-element multiplication.
+  //! @param theFactor [in] the scale factor.
+  //! @return the result of multiplication.
+  Standard_NODISCARD NCollection_Mat3 operator* (const Element_t theFactor) const
+  {
+    return Multiplied (theFactor);
+  }
+
+  //! Compute per-element multiplication.
+  //! @param theFactor [in] the scale factor.
+  //! @return the result of multiplication.
+  Standard_NODISCARD NCollection_Mat3 Multiplied (const Element_t theFactor) const
+  {
+    NCollection_Mat3 aTempMat (*this);
+    aTempMat *= theFactor;
+    return aTempMat;
+  }
+
+  //! Compute per-component division.
+  //! @param theFactor [in] the scale factor.
+  void Divide (const Element_t theFactor)
+  {
+    for (size_t i = 0; i < 9; ++i)
+    {
+      myMat[i] /= theFactor;
+    }
+  }
+
+  //! Per-component division.
+  //! @param theScalar [in] the scale factor.
+  NCollection_Mat3& operator/= (const Element_t theScalar)
+  {
+    Divide (theScalar);
+    return *this;
+  }
+
+  //! Divides all the coefficients of the matrix by scalar.
+  Standard_NODISCARD NCollection_Mat3 Divided (const Element_t theScalar) const
+  {
+    NCollection_Mat3 aTempMat (*this);
+    aTempMat /= theScalar;
+    return aTempMat;
+  }
+
+  //! Divides all the coefficients of the matrix by scalar.
+  Standard_NODISCARD NCollection_Mat3 operator/ (const Element_t theScalar) const
+  {
+    return Divided (theScalar);
+  }
+
+  //! Per-component addition of another matrix.
+  void Add (const NCollection_Mat3& theMat)
+  {
+    for (size_t i = 0; i < 9; ++i)
+    {
+      myMat[i] += theMat.myMat[i];
+    }
+  }
+
+  //! Per-component addition of another matrix.
+  NCollection_Mat3& operator+= (const NCollection_Mat3& theMat)
+  {
+    Add (theMat);
+    return *this;
+  }
+
+  //! Per-component subtraction of another matrix.
+  void Subtract (const NCollection_Mat3& theMat)
+  {
+    for (size_t i = 0; i < 9; ++i)
+    {
+      myMat[i] -= theMat.myMat[i];
+    }
+  }
+
+  //! Per-component subtraction of another matrix.
+  NCollection_Mat3& operator-= (const NCollection_Mat3& theMat)
+  {
+    Subtract (theMat);
+    return *this;
+  }
+
+  //! Per-component addition of another matrix.
+  Standard_NODISCARD NCollection_Mat3 Added (const NCollection_Mat3& theMat) const
+  {
+    NCollection_Mat3 aMat (*this);
+    aMat += theMat;
+    return aMat;
+  }
+
+  //! Per-component addition of another matrix.
+  Standard_NODISCARD NCollection_Mat3 operator+ (const NCollection_Mat3& theMat) const
+  {
+    return Added (theMat);
+  }
+
+  //! Per-component subtraction of another matrix.
+  Standard_NODISCARD NCollection_Mat3 Subtracted (const NCollection_Mat3& theMat) const
+  {
+    NCollection_Mat3 aMat (*this);
+    aMat -= theMat;
+    return aMat;
+  }
+
+  //! Per-component subtraction of another matrix.
+  Standard_NODISCARD NCollection_Mat3 operator- (const NCollection_Mat3& theMat) const
+  {
+    return Subtracted (theMat);
+  }
+
+  //! Returns matrix with all components negated.
+  Standard_NODISCARD NCollection_Mat3 Negated() const
+  {
+    NCollection_Mat3 aMat;
+    for (size_t i = 0; i < 9; ++i)
+    {
+      aMat.myMat[i] = -myMat[i];
+    }
+    return aMat;
+  }
+
+  //! Returns matrix with all components negated.
+  Standard_NODISCARD NCollection_Mat3 operator-() const
+  {
+    return Negated();
+  }
+
+  //! Transpose the matrix.
+  //! @return transposed copy of the matrix.
+  Standard_NODISCARD NCollection_Mat3 Transposed() const
+  {
+    NCollection_Mat3 aTempMat;
+    aTempMat.SetRow (0, GetColumn (0));
+    aTempMat.SetRow (1, GetColumn (1));
+    aTempMat.SetRow (2, GetColumn (2));
+    return aTempMat;
+  }
+
+  //! Transpose the matrix.
+  void Transpose()
+  {
+    *this = Transposed();
+  }
+
+  //! Return adjoint (adjugate matrix, e.g. conjugate transpose).
+  Standard_NODISCARD NCollection_Mat3 Adjoint() const
+  {
+    NCollection_Mat3 aMat;
+    aMat.SetRow (0, NCollection_Vec3<Element_t>::Cross (GetRow(1), GetRow(2)));
+    aMat.SetRow (1, NCollection_Vec3<Element_t>::Cross (GetRow(2), GetRow(0)));
+    aMat.SetRow (2, NCollection_Vec3<Element_t>::Cross (GetRow(0), GetRow(1)));
+    return aMat;
+  }
+
+  //! Compute inverted matrix.
+  //! @param theOutMx [out] the inverted matrix
+  //! @param theDet   [out] determinant of matrix
+  //! @return true if reversion success
+  bool Inverted (NCollection_Mat3& theInv, Element_t& theDet) const
+  {
+    const NCollection_Mat3 aMat = Adjoint();
+    theDet = aMat.GetRow(0).Dot (GetRow(0));
+    if (theDet == Element_t(0))
+    {
+      return false;
+    }
+
+    theInv = aMat.Transposed() / theDet;
+    return true;
+  }
+
+  //! Compute inverted matrix.
+  //! @param theOutMx [out] the inverted matrix
+  //! @return true if reversion success
+  bool Inverted (NCollection_Mat3& theInv) const
+  {
+    Element_t aDet;
+    return Inverted (theInv, aDet);
+  }
+
+  //! Return inverted matrix.
+  NCollection_Mat3 Inverted() const
+  {
+    NCollection_Mat3 anInv;
+    if (!Inverted (anInv))
+    {
+      throw Standard_ConstructionError ("NCollection_Mat3::Inverted() - matrix has zero determinant");
+    }
+    return anInv;
+  }
+
+  //! Take values from NCollection_Mat3 with a different element type with type conversion.
+  template <typename Other_t>
+  void ConvertFrom (const NCollection_Mat3<Other_t>& theFrom)
+  {
+    for (int anIdx = 0; anIdx < 9; ++anIdx)
+    {
+      myMat[anIdx] = static_cast<Element_t> (theFrom.myMat[anIdx]);
+    }
+  }
+
+  //! Maps plain C array to matrix type.
+  static NCollection_Mat3<Element_t>& Map (Element_t* theData)
+  {
+    return *reinterpret_cast<NCollection_Mat3<Element_t>*> (theData);
+  }
+
+  //! Maps plain C array to matrix type.
+  static const NCollection_Mat3<Element_t>& Map (const Element_t* theData)
+  {
+    return *reinterpret_cast<const NCollection_Mat3<Element_t>*> (theData);
+  }
+
+  //! Dumps the content of me into the stream
+  void DumpJson (Standard_OStream& theOStream, Standard_Integer) const
+  {
+    OCCT_DUMP_FIELD_VALUES_NUMERICAL (theOStream, "NCollection_Mat3", 9,
+                                      GetValue (0, 0),  GetValue (0, 1), GetValue (0, 2),
+                                      GetValue (1, 0),  GetValue (1, 1), GetValue (1, 2),
+                                      GetValue (2, 0),  GetValue (2, 1), GetValue (2, 2))
+  }
+
+private:
+
+  Element_t myMat[9];
+
+private:
+
+  static const Element_t MyZeroArray[9];
+  static const Element_t MyIdentityArray[9];
+
+  // All instantiations are friend to each other
+  template<class OtherType> friend class NCollection_Mat3;
+};
+
+template<typename Element_t>
+const Element_t NCollection_Mat3<Element_t>::MyZeroArray[] =
+  {0, 0, 0,
+   0, 0, 0,
+   0, 0, 0};
+
+template<typename Element_t>
+const Element_t NCollection_Mat3<Element_t>::MyIdentityArray[] =
+  {1, 0, 0,
+   0, 1, 0,
+   0, 0, 1};
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1900)
+  #include <type_traits>
+
+  static_assert(std::is_trivially_copyable<NCollection_Mat3<float>>::value, "NCollection_Mat3 is not is_trivially_copyable() structure!");
+  static_assert(std::is_standard_layout   <NCollection_Mat3<float>>::value, "NCollection_Mat3 is not is_standard_layout() structure!");
+  static_assert(sizeof(NCollection_Mat3<float>) == sizeof(float)*9,         "NCollection_Mat3 is not packed/aligned!");
+#endif
+
+#endif // _NCollection_Mat3_HeaderFile
index ed308f4..d55f928 100755 (executable)
 #define _NCollection_Mat4_HeaderFile
 
 #include <NCollection_Vec4.hxx>
-#include <Standard_Dump.hxx>
-#include <Standard_OStream.hxx>
+#include <NCollection_Mat3.hxx>
 
 //! Generic matrix of 4 x 4 elements.
 //! To be used in conjunction with NCollection_Vec4 entities.
-//! Originally introduced for 3D space projection and orientation
-//! operations.
+//! Originally introduced for 3D space projection and orientation operations.
+//! Warning, empty constructor returns an identity matrix.
 template<typename Element_t>
 class NCollection_Mat4
 {
-
 public:
 
   //! Get number of rows.
@@ -44,8 +42,23 @@ public:
     return 4;
   }
 
+  //! Return identity matrix.
+  static NCollection_Mat4 Identity()
+  {
+    return NCollection_Mat4();
+  }
+
+  //! Return zero matrix.
+  static NCollection_Mat4 Zero()
+  {
+    NCollection_Mat4 aMat; aMat.InitZero();
+    return aMat;
+  }
+
+public:
+
   //! Empty constructor.
-  //! Construct the zero matrix.
+  //! Construct the identity matrix.
   NCollection_Mat4()
   {
     InitIdentity();
@@ -63,7 +76,7 @@ public:
   }
 
   //! Get element at the specified row and column.
-  //! @param theRow [in] the row.to address.
+  //! @param theRow [in] the row to address.
   //! @param theCol [in] the column to address.
   //! @return the value of the addressed element.
   Element_t GetValue (const size_t theRow, const size_t theCol) const
@@ -72,7 +85,7 @@ public:
   }
 
   //! Access element at the specified row and column.
-  //! @param theRow [in] the row.to access.
+  //! @param theRow [in] the row to access.
   //! @param theCol [in] the column to access.
   //! @return reference on the matrix element.
   Element_t& ChangeValue (const size_t theRow, const size_t theCol)
@@ -83,7 +96,7 @@ public:
   //! Set value for the element specified by row and columns.
   //! @param theRow   [in] the row to change.
   //! @param theCol   [in] the column to change.
-  //! @param theValue [in] the value to set.s
+  //! @param theValue [in] the value to set.
   void SetValue (const size_t    theRow,
                  const size_t    theCol,
                  const Element_t theValue)
@@ -91,6 +104,12 @@ public:
     myMat[theCol * 4 + theRow] = theValue;
   }
 
+  //! Return value.
+  Element_t& operator() (const size_t theRow, const size_t theCol) { return ChangeValue (theRow, theCol); }
+
+  //! Return value.
+  Element_t  operator() (const size_t theRow, const size_t theCol) const { return GetValue (theRow, theCol); }
+
   //! Get vector of elements for the specified row.
   //! @param theRow [in] the row to access.
   //! @return vector of elements.
@@ -158,7 +177,7 @@ public:
   }
 
   //! Get vector of diagonal elements.
-  //! \return vector of diagonal elements.
+  //! @return vector of diagonal elements.
   NCollection_Vec4<Element_t> GetDiagonal() const
   {
     return NCollection_Vec4<Element_t> (GetValue (0, 0),
@@ -186,16 +205,38 @@ public:
     SetValue (3, 3, theVec.w());
   }
 
+  //! Return 3x3 sub-matrix.
+  NCollection_Mat3<Element_t> GetMat3() const
+  {
+    NCollection_Mat3<Element_t> aMat;
+    aMat.SetColumn (0, GetColumn (0).xyz());
+    aMat.SetColumn (1, GetColumn (1).xyz());
+    aMat.SetColumn (2, GetColumn (2).xyz());
+    return aMat;
+  }
+
+  //! Initialize the zero matrix.
+  void InitZero()
+  {
+    std::memcpy (this, MyZeroArray, sizeof (NCollection_Mat4));
+  }
+
+  //! Checks the matrix for zero (without tolerance).
+  bool IsZero() const
+  {
+    return std::memcmp (this, MyZeroArray, sizeof (NCollection_Mat4)) == 0;
+  }
+
   //! Initialize the identity matrix.
   void InitIdentity()
   {
-    std::memcpy (this, myIdentityArray, sizeof (NCollection_Mat4));
+    std::memcpy (this, MyIdentityArray, sizeof (NCollection_Mat4));
   }
 
-  //! Checks the matrix for identity.
+  //! Checks the matrix for identity (without tolerance).
   bool IsIdentity() const
   {
-    return std::memcmp (this, myIdentityArray, sizeof (NCollection_Mat4)) == 0;
+    return std::memcmp (this, MyIdentityArray, sizeof (NCollection_Mat4)) == 0;
   }
 
   //! Check this matrix for equality with another matrix (without tolerance!).
@@ -205,18 +246,15 @@ public:
   }
 
   //! Check this matrix for equality with another matrix (without tolerance!).
-  bool operator== (const NCollection_Mat4& theOther)       { return IsEqual (theOther); }
   bool operator== (const NCollection_Mat4& theOther) const { return IsEqual (theOther); }
 
   //! Check this matrix for non-equality with another matrix (without tolerance!).
-  bool operator!= (const NCollection_Mat4& theOther)       { return !IsEqual (theOther); }
   bool operator!= (const NCollection_Mat4& theOther) const { return !IsEqual (theOther); }
 
-  //! Raw access to the data (for OpenGL exchange).
+  //! Raw access to the data (for OpenGL exchange);
+  //! the data is returned in column-major order.
   const Element_t* GetData()    const { return myMat; }
   Element_t*       ChangeData()       { return myMat; }
-  operator const   Element_t*() const { return myMat; }
-  operator         Element_t*()       { return myMat; }
 
   //! Multiply by the vector (M * V).
   //! @param theVec [in] the vector to multiply.
@@ -232,19 +270,19 @@ public:
   //! Compute matrix multiplication product: A * B.
   //! @param theMatA [in] the matrix "A".
   //! @param theMatB [in] the matrix "B".
-  NCollection_Mat4 Multiply (const NCollection_Mat4& theMatA,
-                             const NCollection_Mat4& theMatB)
+  static NCollection_Mat4 Multiply (const NCollection_Mat4& theMatA,
+                                    const NCollection_Mat4& theMatB)
   {
     NCollection_Mat4 aMatRes;
 
     size_t aInputElem;
     for (size_t aResElem = 0; aResElem < 16; ++aResElem)
     {
-      aMatRes[aResElem] = (Element_t )0;
+      aMatRes.myMat[aResElem] = (Element_t )0;
       for (aInputElem = 0; aInputElem < 4; ++aInputElem)
       {
-        aMatRes[aResElem] += theMatA.GetValue(aResElem % 4, aInputElem)
-                           * theMatB.GetValue(aInputElem, aResElem / 4);
+        aMatRes.myMat[aResElem] += theMatA.GetValue(aResElem % 4, aInputElem)
+                                 * theMatB.GetValue(aInputElem, aResElem / 4);
       }
     }
 
@@ -269,7 +307,7 @@ public:
   //! Compute matrix multiplication product.
   //! @param theMat [in] the other matrix.
   //! @return result of multiplication.
-  NCollection_Mat4 operator* (const NCollection_Mat4& theMat) const
+  Standard_NODISCARD NCollection_Mat4 operator* (const NCollection_Mat4& theMat) const
   {
     return Multiplied (theMat);
   }
@@ -277,7 +315,7 @@ public:
   //! Compute matrix multiplication product.
   //! @param theMat [in] the other matrix.
   //! @return result of multiplication.
-  NCollection_Mat4 Multiplied (const NCollection_Mat4& theMat) const
+  Standard_NODISCARD NCollection_Mat4 Multiplied (const NCollection_Mat4& theMat) const
   {
     NCollection_Mat4 aTempMat (*this);
     aTempMat *= theMat;
@@ -296,7 +334,7 @@ public:
 
   //! Compute per-element multiplication.
   //! @param theFactor [in] the scale factor.
-  NCollection_Mat4& operator*=(const Element_t theFactor)
+  NCollection_Mat4& operator*= (const Element_t theFactor)
   {
     Multiply (theFactor);
     return *this;
@@ -304,22 +342,122 @@ public:
 
   //! Compute per-element multiplication.
   //! @param theFactor [in] the scale factor.
-  //! @return the result of multiplicaton.
-  NCollection_Mat4 operator* (const Element_t theFactor) const
+  //! @return the result of multiplication.
+  Standard_NODISCARD NCollection_Mat4 operator* (const Element_t theFactor) const
   {
     return Multiplied (theFactor);
   }
 
   //! Compute per-element multiplication.
   //! @param theFactor [in] the scale factor.
-  //! @return the result of multiplicaton.
-  NCollection_Mat4 Multiplied (const Element_t theFactor) const
+  //! @return the result of multiplication.
+  Standard_NODISCARD NCollection_Mat4 Multiplied (const Element_t theFactor) const
   {
     NCollection_Mat4 aTempMat (*this);
     aTempMat *= theFactor;
     return aTempMat;
   }
 
+  //! Compute per-component division.
+  //! @param theFactor [in] the scale factor.
+  void Divide (const Element_t theFactor)
+  {
+    for (size_t i = 0; i < 16; ++i)
+    {
+      myMat[i] /= theFactor;
+    }
+  }
+
+  //! Per-component division.
+  //! @param theScalar [in] the scale factor.
+  NCollection_Mat4& operator/= (const Element_t theScalar)
+  {
+    Divide (theScalar);
+    return *this;
+  }
+
+  //! Divides all the coefficients of the matrix by scalar.
+  Standard_NODISCARD NCollection_Mat4 Divided (const Element_t theScalar) const
+  {
+    NCollection_Mat4 aTempMat (*this);
+    aTempMat /= theScalar;
+    return aTempMat;
+  }
+
+  //! Divides all the coefficients of the matrix by scalar.
+  Standard_NODISCARD NCollection_Mat4 operator/ (const Element_t theScalar) const
+  {
+    return Divided (theScalar);
+  }
+
+  //! Per-component addition of another matrix.
+  void Add (const NCollection_Mat4& theMat)
+  {
+    for (size_t i = 0; i < 16; ++i)
+    {
+      myMat[i] += theMat.myMat[i];
+    }
+  }
+
+  //! Per-component addition of another matrix.
+  NCollection_Mat4& operator+= (const NCollection_Mat4& theMat)
+  {
+    Add (theMat);
+    return *this;
+  }
+
+  //! Per-component subtraction of another matrix.
+  void Subtract (const NCollection_Mat4& theMat)
+  {
+    for (size_t i = 0; i < 16; ++i)
+    {
+      myMat[i] -= theMat.myMat[i];
+    }
+  }
+
+  //! Per-component subtraction of another matrix.
+  NCollection_Mat4& operator-= (const NCollection_Mat4& theMat)
+  {
+    Subtract (theMat);
+    return *this;
+  }
+
+  //! Per-component addition of another matrix.
+  Standard_NODISCARD NCollection_Mat4 Added (const NCollection_Mat4& theMat) const
+  {
+    NCollection_Mat4 aMat (*this);
+    aMat += theMat;
+    return aMat;
+  }
+
+  //! Per-component addition of another matrix.
+  Standard_NODISCARD NCollection_Mat4 operator+ (const NCollection_Mat4& theMat) const { return Added (theMat); }
+
+  //! Per-component subtraction of another matrix.
+  Standard_NODISCARD NCollection_Mat4 Subtracted (const NCollection_Mat4& theMat) const
+  {
+    NCollection_Mat4 aMat (*this);
+    aMat -= theMat;
+    return aMat;
+  }
+
+  //! Per-component subtraction of another matrix.
+  Standard_NODISCARD NCollection_Mat4 operator- (const NCollection_Mat4& theMat) const { return Subtracted (theMat); }
+
+  //! Returns matrix with all components negated.
+  Standard_NODISCARD NCollection_Mat4 Negated() const
+  {
+    NCollection_Mat4 aMat;
+    for (size_t i = 0; i < 16; ++i)
+    {
+      aMat.myMat[i] = -myMat[i];
+    }
+    return aMat;
+  }
+
+  //! Returns matrix with all components negated.
+  Standard_NODISCARD NCollection_Mat4 operator-() const { return Negated(); }
+
   //! Translate the matrix on the passed vector.
   //! @param theVec [in] the translation vector.
   void Translate (const NCollection_Vec3<Element_t>& theVec)
@@ -331,7 +469,7 @@ public:
 
   //! Transpose the matrix.
   //! @return transposed copy of the matrix.
-  NCollection_Mat4 Transposed() const
+  Standard_NODISCARD NCollection_Mat4 Transposed() const
   {
     NCollection_Mat4 aTempMat;
     aTempMat.SetRow (0, GetColumn (0));
@@ -348,9 +486,10 @@ public:
   }
 
   //! Compute inverted matrix.
-  //! @param theOutMx [out] the inverted matrix.
-  //! @return true if reversion success.
-  bool Inverted (NCollection_Mat4<Element_t>& theOutMx) const
+  //! @param theOutMx [out] the inverted matrix
+  //! @param theDet   [out] determinant of matrix
+  //! @return true if reversion success
+  bool Inverted (NCollection_Mat4<Element_t>& theOutMx, Element_t& theDet) const
   {
     Element_t* inv = theOutMx.myMat;
 
@@ -421,22 +560,54 @@ public:
               m[ 4] * (m[ 1] * m[10] - m[ 2] * m[ 9]) -
               m[ 8] * (m[ 2] * m[ 5] - m[ 1] * m[ 6]);
 
-    Element_t aDet = m[0] * inv[ 0] +
-                     m[1] * inv[ 4] +
-                     m[2] * inv[ 8] +
-                     m[3] * inv[12];
-
-    if (aDet == 0)
+    theDet = m[0] * inv[ 0] +
+             m[1] * inv[ 4] +
+             m[2] * inv[ 8] +
+             m[3] * inv[12];
+    if (theDet == 0)
+    {
       return false;
+    }
 
-    aDet = (Element_t) 1. / aDet;
-
+    const Element_t aDiv = (Element_t) 1. / theDet;
     for (int i = 0; i < 16; ++i)
-      inv[i] *= aDet;
-
+    {
+      inv[i] *= aDiv;
+    }
     return true;
   }
 
+  //! Compute inverted matrix.
+  //! @param theOutMx [out] the inverted matrix
+  //! @return true if reversion success
+  bool Inverted (NCollection_Mat4<Element_t>& theOutMx) const
+  {
+    Element_t aDet;
+    return Inverted (theOutMx, aDet);
+  }
+
+  //! Return inverted matrix.
+  NCollection_Mat4 Inverted() const
+  {
+    NCollection_Mat4 anInv;
+    if (!Inverted (anInv))
+    {
+      throw Standard_ConstructionError ("NCollection_Mat4::Inverted() - matrix has zero determinant");
+    }
+    return anInv;
+  }
+
+  //! Return adjoint (adjugate matrix, e.g. conjugate transpose).
+  Standard_NODISCARD NCollection_Mat4<Element_t> Adjoint() const
+  {
+    NCollection_Mat4<Element_t> aMat;
+    aMat.SetRow (0, crossVec4 ( GetRow (1), GetRow (2), GetRow (3)));
+    aMat.SetRow (1, crossVec4 (-GetRow (0), GetRow (2), GetRow (3)));
+    aMat.SetRow (2, crossVec4 ( GetRow (0), GetRow (1), GetRow (3)));
+    aMat.SetRow (3, crossVec4 (-GetRow (0), GetRow (1), GetRow (2)));
+    return aMat;
+  }
+
   //! Take values from NCollection_Mat4 with a different element type with type conversion.
   template <typename Other_t>
   void ConvertFrom (const NCollection_Mat4<Other_t>& theFrom)
@@ -473,13 +644,36 @@ public:
       GetValue (3, 0),  GetValue (3, 1), GetValue (3, 2),  GetValue (3, 3))
   }
 
+private:
+
+  //! Cross-product has no direct meaning in 4D space - provided for local usage.
+  static NCollection_Vec4<Element_t> crossVec4 (const NCollection_Vec4<Element_t>& theA,
+                                                const NCollection_Vec4<Element_t>& theB,
+                                                const NCollection_Vec4<Element_t>& theC)
+  {
+    const Element_t aD1 = (theB.z() * theC.w()) - (theB.w() * theC.z());
+    const Element_t aD2 = (theB.y() * theC.w()) - (theB.w() * theC.y());
+    const Element_t aD3 = (theB.y() * theC.z()) - (theB.z() * theC.y());
+    const Element_t aD4 = (theB.x() * theC.w()) - (theB.w() * theC.x());
+    const Element_t aD5 = (theB.x() * theC.z()) - (theB.z() * theC.x());
+    const Element_t aD6 = (theB.x() * theC.y()) - (theB.y() * theC.x());
+
+    NCollection_Vec4<Element_t> aVec;
+    aVec.x() = -theA.y() * aD1 + theA.z() * aD2 - theA.w() * aD3;
+    aVec.y() =  theA.x() * aD1 - theA.z() * aD4 + theA.w() * aD5;
+    aVec.z() = -theA.x() * aD2 + theA.y() * aD4 - theA.w() * aD6;
+    aVec.w() =  theA.x() * aD3 - theA.y() * aD5 + theA.z() * aD6;
+    return aVec;
+  }
+
 private:
 
   Element_t myMat[16];
 
 private:
 
-  static Element_t myIdentityArray[16];
+  static const Element_t MyZeroArray[16];
+  static const Element_t MyIdentityArray[16];
 
   // All instantiations are friend to each other
   template<class OtherType> friend class NCollection_Mat4;
@@ -487,7 +681,14 @@ private:
 };
 
 template<typename Element_t>
-Element_t NCollection_Mat4<Element_t>::myIdentityArray[] =
+const Element_t NCollection_Mat4<Element_t>::MyZeroArray[] =
+  {0, 0, 0, 0,
+   0, 0, 0, 0,
+   0, 0, 0, 0,
+   0, 0, 0, 0};
+
+template<typename Element_t>
+const Element_t NCollection_Mat4<Element_t>::MyIdentityArray[] =
   {1, 0, 0, 0,
    0, 1, 0, 0,
    0, 0, 1, 0,
@@ -498,6 +699,7 @@ Element_t NCollection_Mat4<Element_t>::myIdentityArray[] =
 
   static_assert(std::is_trivially_copyable<NCollection_Mat4<float>>::value, "NCollection_Mat4 is not is_trivially_copyable() structure!");
   static_assert(std::is_standard_layout   <NCollection_Mat4<float>>::value, "NCollection_Mat4 is not is_standard_layout() structure!");
+  static_assert(sizeof(NCollection_Mat4<float>) == sizeof(float)*16,        "NCollection_Mat4 is not packed/aligned!");
 #endif
 
 #endif // _NCollection_Mat4_HeaderFile
index 38b354d..12e8fe5 100644 (file)
@@ -102,11 +102,9 @@ public:
   }
 
   //! Check this vector with another vector for equality (without tolerance!).
-  bool operator== (const NCollection_Vec2& theOther)       { return IsEqual (theOther); }
   bool operator== (const NCollection_Vec2& theOther) const { return IsEqual (theOther); }
 
   //! Check this vector with another vector for non-equality (without tolerance!).
-  bool operator!= (const NCollection_Vec2& theOther)       { return !IsEqual (theOther); }
   bool operator!= (const NCollection_Vec2& theOther) const { return !IsEqual (theOther); }
 
   //! Raw access to the data (for OpenGL exchange).
index 108349f..4677408 100644 (file)
@@ -157,11 +157,9 @@ public:
   }
 
   //! Check this vector with another vector for equality (without tolerance!).
-  bool operator== (const NCollection_Vec3& theOther)       { return IsEqual (theOther); }
   bool operator== (const NCollection_Vec3& theOther) const { return IsEqual (theOther); }
 
   //! Check this vector with another vector for non-equality (without tolerance!).
-  bool operator!= (const NCollection_Vec3& theOther)       { return !IsEqual (theOther); }
   bool operator!= (const NCollection_Vec3& theOther) const { return !IsEqual (theOther); }
 
   //! Raw access to the data (for OpenGL exchange).
index 995033f..d00d84b 100644 (file)
@@ -183,11 +183,9 @@ public:
   }
 
   //! Check this vector with another vector for equality (without tolerance!).
-  bool operator== (const NCollection_Vec4& theOther)       { return IsEqual (theOther); }
   bool operator== (const NCollection_Vec4& theOther) const { return IsEqual (theOther); }
 
   //! Check this vector with another vector for non-equality (without tolerance!).
-  bool operator!= (const NCollection_Vec4& theOther)       { return !IsEqual (theOther); }
   bool operator!= (const NCollection_Vec4& theOther) const { return !IsEqual (theOther); }
 
   //! Raw access to the data (for OpenGL exchange).
index 2ec64a1..ba46db0 100755 (executable)
@@ -41,7 +41,6 @@ OpenGl_GraduatedTrihedron.hxx
 OpenGl_GraduatedTrihedron.cxx
 OpenGl_Material.hxx
 OpenGl_MaterialState.hxx
-OpenGl_Matrix.hxx
 OpenGl_MatrixState.hxx
 OpenGl_LineAttributes.hxx
 OpenGl_LineAttributes.cxx
index 743a809..eed9011 100755 (executable)
@@ -69,7 +69,7 @@ namespace
 
     // set identity model matrix
     aContext->ModelWorldState.Push();
-    aContext->ModelWorldState.SetCurrent (OpenGl_Mat4::Map (*thePlane->Orientation()->mat));
+    aContext->ModelWorldState.SetCurrent (thePlane->Orientation());
     aContext->ApplyModelViewMatrix();
 
     thePlane->Primitives().Render (theWorkspace);
index 6b1ce90..bc2c23a 100755 (executable)
@@ -46,26 +46,15 @@ namespace
     1.0f, 0.0f, 0.0f, 0.0f,  0.0f,-1.0f, 0.0f, 0.0f,   1.0f, 0.0f, 0.0f, 0.0f,
     0.0f, 0.0f,-1.0f, 0.0f,  0.0f,-1.0f, 0.0f, 0.0f,   0.0f, 1.0f, 0.0f, 0.0f
   };
-
-  static const OpenGl_Matrix OpenGl_IdentityMatrix =
-  {
-    // mat[4][4]
-    { { 1.0f, 0.0f, 0.0f, 0.0f },
-      { 0.0f, 1.0f, 0.0f, 0.0f },
-      { 0.0f, 0.0f, 1.0f, 0.0f },
-      { 0.0f, 0.0f, 0.0f, 1.0f } }
-  };
-
 }
 
-
 // =======================================================================
 // function : OpenGl_CappingPlaneResource
 // purpose  :
 // =======================================================================
 OpenGl_CappingPlaneResource::OpenGl_CappingPlaneResource (const Handle(Graphic3d_ClipPlane)& thePlane)
 : myPrimitives  (NULL),
-  myOrientation (OpenGl_IdentityMatrix),
+  myOrientation (OpenGl_Mat4::Identity()),
   myAspect      (NULL),
   myPlaneRoot   (thePlane),
   myEquationMod ((unsigned int )-1),
@@ -210,24 +199,8 @@ void OpenGl_CappingPlaneResource::updateTransform (const Handle(OpenGl_Context)&
   }
 
   const Graphic3d_Vec3 F = Graphic3d_Vec3::Cross (-aLeft, aNorm);
-
-  myOrientation.mat[0][0] = aLeft[0];
-  myOrientation.mat[0][1] = aLeft[1];
-  myOrientation.mat[0][2] = aLeft[2];
-  myOrientation.mat[0][3] = 0.0f;
-
-  myOrientation.mat[1][0] = aNorm[0];
-  myOrientation.mat[1][1] = aNorm[1];
-  myOrientation.mat[1][2] = aNorm[2];
-  myOrientation.mat[1][3] = 0.0f;
-
-  myOrientation.mat[2][0] = F[0];
-  myOrientation.mat[2][1] = F[1];
-  myOrientation.mat[2][2] = F[2];
-  myOrientation.mat[2][3] = 0.0f;
-
-  myOrientation.mat[3][0] = T[0];
-  myOrientation.mat[3][1] = T[1];
-  myOrientation.mat[3][2] = T[2];
-  myOrientation.mat[3][3] = 1.0f;
+  myOrientation.SetColumn (0, aLeft);
+  myOrientation.SetColumn (1, aNorm);
+  myOrientation.SetColumn (2, F);
+  myOrientation.SetColumn (3, T);
 }
index 9547b82..a3486d0 100755 (executable)
@@ -19,7 +19,7 @@
 #include <OpenGl_PrimitiveArray.hxx>
 #include <OpenGl_Resource.hxx>
 #include <OpenGl_Aspects.hxx>
-#include <OpenGl_Matrix.hxx>
+#include <OpenGl_Vec.hxx>
 #include <Graphic3d_ClipPlane.hxx>
 
 class OpenGl_CappingPlaneResource;
@@ -64,7 +64,7 @@ public:
   inline const OpenGl_Aspects* AspectFace() const { return myAspect; }
 
   //! @return evaluated orientation matrix to transform infinite plane.
-  inline const OpenGl_Matrix* Orientation() const { return &myOrientation; }
+  inline const OpenGl_Mat4& Orientation() const { return myOrientation; }
 
   //! @return primitive array of vertices to render infinite plane.
   inline const OpenGl_PrimitiveArray& Primitives() const { return myPrimitives; }
@@ -80,7 +80,7 @@ private:
 private:
 
   OpenGl_PrimitiveArray       myPrimitives;    //!< vertices and texture coordinates for rendering
-  OpenGl_Matrix               myOrientation;   //!< plane transformation matrix.
+  OpenGl_Mat4                 myOrientation;   //!< plane transformation matrix.
   OpenGl_Aspects*             myAspect;        //!< capping face aspect.
   Handle(Graphic3d_ClipPlane) myPlaneRoot;     //!< parent clipping plane structure.
   Handle(Graphic3d_Aspects)   myFillAreaAspect;//!< own capping aspect
index 3303db6..736704b 100644 (file)
@@ -2657,7 +2657,7 @@ void OpenGl_Context::SetTextureMatrix (const Handle(Graphic3d_TextureParams)& th
       Graphic3d_TransformUtils::Translate (aTextureMat, -aTrans.x(), -aTrans.y(), 0.0f);
     }
     Graphic3d_TransformUtils::Rotate (aTextureMat, -theParams->Rotation(), 0.0f, 0.0f, 1.0f);
-    core11ffp->glLoadMatrixf (aTextureMat);
+    core11ffp->glLoadMatrixf (aTextureMat.GetData());
     core11ffp->glMatrixMode (aMatrixMode);
   }
 #endif
diff --git a/src/OpenGl/OpenGl_Matrix.hxx b/src/OpenGl/OpenGl_Matrix.hxx
deleted file mode 100644 (file)
index 47b84af..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-// Created on: 2011-09-20
-// Created by: Sergey ZERCHANINOV
-// Copyright (c) 2011-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#ifndef OpenGl_Matrix_Header
-#define OpenGl_Matrix_Header
-
-#include <Standard_Type.hxx>
-
-struct OpenGl_Matrix
-{
-  float mat[4][4];
-  DEFINE_STANDARD_ALLOC
-};
-
-#endif //OpenGl_Matrix_Header
index aaae4e6..a1cc8c7 100644 (file)
@@ -597,7 +597,7 @@ void OpenGl_ShaderManager::pushProjectionState (const Handle(OpenGl_ShaderProgra
     if (myContext->core11ffp != NULL)
     {
       myContext->core11ffp->glMatrixMode (GL_PROJECTION);
-      myContext->core11ffp->glLoadMatrixf (myProjectionState.ProjectionMatrix());
+      myContext->core11ffp->glLoadMatrixf (myProjectionState.ProjectionMatrix().GetData());
     }
   #endif
     return;
index c46ead0..55971d5 100755 (executable)
@@ -821,17 +821,6 @@ GLint OpenGl_ShaderProgram::GetAttributeLocation (const Handle(OpenGl_Context)&
        : INVALID_LOCATION;
 }
 
-// =======================================================================
-// function : GetUniform
-// purpose  : Returns the value of the integer uniform variable
-// =======================================================================
-Standard_Boolean OpenGl_ShaderProgram::GetUniform (const Handle(OpenGl_Context)& theCtx,
-                                                   const GLchar*                 theName,
-                                                   OpenGl_Vec4i&                 theValue) const
-{
-  return GetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
-}
-
 // =======================================================================
 // function : GetUniform
 // purpose  : Returns the value of the integer uniform variable
@@ -849,17 +838,6 @@ Standard_Boolean OpenGl_ShaderProgram::GetUniform (const Handle(OpenGl_Context)&
   return Standard_True;
 }
 
-// =======================================================================
-// function : GetUniform
-// purpose  : Returns the value of the floating-point uniform variable
-// =======================================================================
-Standard_Boolean OpenGl_ShaderProgram::GetUniform (const Handle(OpenGl_Context)& theCtx,
-                                                   const GLchar*                 theName,
-                                                   OpenGl_Vec4&                  theValue) const
-{
-  return GetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
-}
-
 // =======================================================================
 // function : GetUniform
 // purpose  : Returns the value of the floating-point uniform variable
@@ -877,17 +855,6 @@ Standard_Boolean OpenGl_ShaderProgram::GetUniform (const Handle(OpenGl_Context)&
   return Standard_True;
 }
 
-// =======================================================================
-// function : GetAttribute
-// purpose  : Returns the integer vertex attribute
-// =======================================================================
-Standard_Boolean OpenGl_ShaderProgram::GetAttribute (const Handle(OpenGl_Context)& theCtx,
-                                                     const GLchar*                 theName,
-                                                     OpenGl_Vec4i&                 theValue) const
-{
-  return GetAttribute (theCtx, GetAttributeLocation (theCtx, theName), theValue);
-}
-
 // =======================================================================
 // function : GetAttribute
 // purpose  : Returns the integer vertex attribute
@@ -905,17 +872,6 @@ Standard_Boolean OpenGl_ShaderProgram::GetAttribute (const Handle(OpenGl_Context
   return Standard_True;
 }
 
-// =======================================================================
-// function : GetAttribute
-// purpose  : Returns the floating-point vertex attribute
-// =======================================================================
-Standard_Boolean OpenGl_ShaderProgram::GetAttribute (const Handle(OpenGl_Context)& theCtx,
-                                                     const GLchar*                 theName,
-                                                     OpenGl_Vec4&                  theValue) const
-{
-  return GetAttribute (theCtx, GetAttributeLocation (theCtx, theName), theValue);
-}
-
 // =======================================================================
 // function : GetAttribute
 // purpose  : Returns the floating-point vertex attribute
@@ -945,17 +901,6 @@ Standard_Boolean OpenGl_ShaderProgram::SetAttributeName (const Handle(OpenGl_Con
   return Standard_True;
 }
 
-// =======================================================================
-// function : SetAttribute
-// purpose  :
-// =======================================================================
-Standard_Boolean OpenGl_ShaderProgram::SetAttribute (const Handle(OpenGl_Context)& theCtx,
-                                                     const GLchar*                 theName,
-                                                     GLfloat                       theValue)
-{
-  return SetAttribute (theCtx, GetAttributeLocation (theCtx, theName), theValue);
-}
-
 // =======================================================================
 // function : SetAttribute
 // purpose  :
@@ -973,17 +918,6 @@ Standard_Boolean OpenGl_ShaderProgram::SetAttribute (const Handle(OpenGl_Context
   return Standard_True;
 }
 
-// =======================================================================
-// function : SetAttribute
-// purpose  :
-// =======================================================================
-Standard_Boolean OpenGl_ShaderProgram::SetAttribute (const Handle(OpenGl_Context)& theCtx,
-                                                     const GLchar*                 theName,
-                                                     const OpenGl_Vec2&            theValue)
-{
-  return SetAttribute (theCtx, GetAttributeLocation (theCtx, theName), theValue);
-}
-
 // =======================================================================
 // function : SetAttribute
 // purpose  :
@@ -1001,17 +935,6 @@ Standard_Boolean OpenGl_ShaderProgram::SetAttribute (const Handle(OpenGl_Context
   return Standard_True;
 }
 
-// =======================================================================
-// function : SetAttribute
-// purpose  :
-// =======================================================================
-Standard_Boolean OpenGl_ShaderProgram::SetAttribute (const Handle(OpenGl_Context)& theCtx,
-                                                     const GLchar*                 theName,
-                                                     const OpenGl_Vec3&            theValue)
-{
-  return SetAttribute (theCtx, GetAttributeLocation (theCtx, theName), theValue);
-}
-
 // =======================================================================
 // function : SetAttribute
 // purpose  :
@@ -1029,17 +952,6 @@ Standard_Boolean OpenGl_ShaderProgram::SetAttribute (const Handle(OpenGl_Context
   return Standard_True;
 }
 
-// =======================================================================
-// function : SetAttribute
-// purpose  :
-// =======================================================================
-Standard_Boolean OpenGl_ShaderProgram::SetAttribute (const Handle(OpenGl_Context)& theCtx,
-                                                     const GLchar*                 theName,
-                                                     const OpenGl_Vec4&            theValue)
-{
-  return SetAttribute (theCtx, GetAttributeLocation (theCtx, theName), theValue);
-}
-
 // =======================================================================
 // function : SetAttribute
 // purpose  :
@@ -1057,17 +969,6 @@ Standard_Boolean OpenGl_ShaderProgram::SetAttribute (const Handle(OpenGl_Context
   return Standard_True;
 }
 
-// =======================================================================
-// function : SetUniform
-// purpose  : Specifies the value of the integer uniform variable
-// =======================================================================
-Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
-                                                   const GLchar*                 theName,
-                                                   GLint                         theValue)
-{
-  return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
-}
-
 // =======================================================================
 // function : SetUniform
 // purpose  : Specifies the value of the integer uniform variable
@@ -1085,17 +986,6 @@ Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)&
   return Standard_True;
 }
 
-// =======================================================================
-// function : SetUniform
-// purpose  :
-// =======================================================================
-Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
-                                                   const GLchar*                 theName,
-                                                   const OpenGl_Vec2u&           theValue)
-{
-  return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
-}
-
 // =======================================================================
 // function : SetUniform
 // purpose  :
@@ -1167,17 +1057,6 @@ Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)&
   return false;
 }
 
-// =======================================================================
-// function : SetUniform
-// purpose  : Specifies the value of the floating-point uniform variable
-// =======================================================================
-Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
-                                                   const GLchar*                 theName,
-                                                   GLfloat                       theValue)
-{
-  return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
-}
-
 // =======================================================================
 // function : SetUniform
 // purpose  : Specifies the value of the floating-point uniform variable
@@ -1195,17 +1074,6 @@ Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)&
   return Standard_True;
 }
 
-// =======================================================================
-// function : SetUniform
-// purpose  : Specifies the value of the integer uniform 2D vector
-// =======================================================================
-Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
-                                                   const GLchar*                 theName,
-                                                   const OpenGl_Vec2i&           theValue)
-{
-  return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
-}
-
 // =======================================================================
 // function : SetUniform
 // purpose  : Specifies the value of the integer uniform 2D vector
@@ -1223,17 +1091,6 @@ Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)&
   return Standard_True;
 }
 
-// =======================================================================
-// function : SetUniform
-// purpose  : Specifies the value of the integer uniform 3D vector
-// =======================================================================
-Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
-                                                   const GLchar*                 theName,
-                                                   const OpenGl_Vec3i&           theValue)
-{
-  return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
-}
-
 // =======================================================================
 // function : SetUniform
 // purpose  : Specifies the value of the integer uniform 3D vector
@@ -1251,17 +1108,6 @@ Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)&
   return Standard_True;
 }
 
-// =======================================================================
-// function : SetUniform
-// purpose  : Specifies the value of the integer uniform 4D vector
-// =======================================================================
-Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
-                                                   const GLchar*                 theName,
-                                                   const OpenGl_Vec4i&           theValue)
-{
-  return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
-}
-
 // =======================================================================
 // function : SetUniform
 // purpose  : Specifies the value of the integer uniform 4D vector
@@ -1279,17 +1125,6 @@ Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)&
   return Standard_True;
 }
 
-// =======================================================================
-// function : SetUniform
-// purpose  : Specifies the value of the floating-point uniform 2D vector
-// =======================================================================
-Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
-                                                   const GLchar*                 theName,
-                                                   const OpenGl_Vec2&            theValue)
-{
-  return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
-}
-
 // =======================================================================
 // function : SetUniform
 // purpose  : Specifies the value of the floating-point uniform 2D vector
@@ -1307,17 +1142,6 @@ Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)&
   return Standard_True;
 }
 
-// =======================================================================
-// function : SetUniform
-// purpose  : Specifies the value of the floating-point uniform 3D vector
-// =======================================================================
-Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
-                                                   const GLchar*                 theName,
-                                                   const OpenGl_Vec3&            theValue)
-{
-  return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
-}
-
 // =======================================================================
 // function : SetUniform
 // purpose  : Specifies the value of the floating-point uniform 3D vector
@@ -1335,17 +1159,6 @@ Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)&
   return Standard_True;
 }
 
-// =======================================================================
-// function : SetUniform
-// purpose  : Specifies the value of the floating-point uniform 4D vector
-// =======================================================================
-Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
-                                                   const GLchar*                 theName,
-                                                   const OpenGl_Vec4&            theValue)
-{
-  return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
-}
-
 // =======================================================================
 // function : SetUniform
 // purpose  : Specifies the value of the floating-point uniform 4D vector
@@ -1365,14 +1178,20 @@ Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)&
 
 // =======================================================================
 // function : SetUniform
-// purpose  : Specifies the value of the floating-point uniform 4x4 matrix
+// purpose  :
 // =======================================================================
-Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
-                                                   const GLchar*                 theName,
-                                                   const OpenGl_Mat4&            theValue,
-                                                   GLboolean                     theTranspose)
+Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)&  theCtx,
+                                                   GLint                          theLocation,
+                                                   GLuint                         theCount,
+                                                   const NCollection_Mat3<float>* theData)
 {
-  return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue, theTranspose);
+  if (myProgramID == NO_PROGRAM || theLocation == INVALID_LOCATION)
+  {
+    return Standard_False;
+  }
+
+  theCtx->core20fwd->glUniformMatrix3fv (theLocation, theCount, GL_FALSE, theData->GetData());
+  return Standard_True;
 }
 
 // =======================================================================
@@ -1389,34 +1208,10 @@ Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)&
     return Standard_False;
   }
 
-  theCtx->core20fwd->glUniformMatrix4fv (theLocation, 1, GL_FALSE, theTranspose ? theValue.Transposed() : theValue);
+  theCtx->core20fwd->glUniformMatrix4fv (theLocation, 1, GL_FALSE, theTranspose ? theValue.Transposed().GetData() : theValue.GetData());
   return Standard_True;
 }
 
-// =======================================================================
-// function : SetUniform
-// purpose  : Specifies the value of the floating-point uniform 4x4 matrix
-// =======================================================================
-Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
-                                                   const GLchar*                 theName,
-                                                   const OpenGl_Matrix&          theValue,
-                                                   GLboolean                     theTranspose)
-{
-  return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue, theTranspose);
-}
-
-// =======================================================================
-// function : SetUniform
-// purpose  : Specifies the value of the floating-point uniform 4x4 matrix
-// =======================================================================
-Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)& theCtx,
-                                                   GLint                         theLocation,
-                                                   const OpenGl_Matrix&          theValue,
-                                                   GLboolean                     theTranspose)
-{
-  return SetUniform (theCtx, theLocation, OpenGl_Mat4::Map (*theValue.mat), theTranspose);
-}
-
 // =======================================================================
 // function : SetUniform
 // purpose  :
@@ -1579,17 +1374,6 @@ Standard_Boolean OpenGl_ShaderProgram::SetUniform (const Handle(OpenGl_Context)&
   return Standard_True;
 }
 
-// =======================================================================
-// function : SetSampler
-// purpose  : Specifies the value of the sampler uniform variable
-// =======================================================================
-Standard_Boolean OpenGl_ShaderProgram::SetSampler (const Handle(OpenGl_Context)& theCtx,
-                                                   const GLchar*                 theName,
-                                                   const Graphic3d_TextureUnit   theTextureUnit)
-{
-  return SetSampler (theCtx, GetUniformLocation (theCtx, theName), theTextureUnit);
-}
-
 // =======================================================================
 // function : SetSampler
 // purpose  : Specifies the value of the sampler uniform variable
index 78e3d1c..736ecaa 100755 (executable)
@@ -25,7 +25,6 @@
 #include <Graphic3d_TextureSetBits.hxx>
 
 #include <OpenGl_Vec.hxx>
-#include <OpenGl_Matrix.hxx>
 #include <OpenGl_NamedResource.hxx>
 #include <OpenGl_ShaderObject.hxx>
 
@@ -340,43 +339,46 @@ public:
 
 public:
 
-  //! Returns the value of the integer uniform variable.
-  Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
-                                               const GLchar*                 theName,
-                                               OpenGl_Vec4i&                 theValue) const;
+  //! Returns the value of the uniform variable from given name.
+  template<typename ValueType>
+  bool GetUniform (const Handle(OpenGl_Context)& theCtx,
+                   const GLchar* theName,
+                   ValueType& theValue) const
+  {
+    return GetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
+  }
 
+  //! Returns the value of the integer uniform variable.
+  //! Wrapper for glGetUniformiv()
   Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
                                                GLint                         theLocation,
                                                OpenGl_Vec4i&                 theValue) const;
 
   //! Returns the value of the float uniform variable.
-  Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
-                                               const GLchar*                 theName,
-                                               OpenGl_Vec4&                  theValue) const;
-
-  //! Returns the value of the float uniform variable.
+  //! Wrapper for glGetUniformfv()
   Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
                                                GLint                         theLocation,
                                                OpenGl_Vec4&                  theValue) const;
 
 public:
 
-  //! Returns the integer vertex attribute.
-  Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
-                                                 const GLchar*                 theName,
-                                                 OpenGl_Vec4i&                 theValue) const;
+  //! Returns the vertex attribute from given name.
+  template<typename ValueType>
+  bool GetAttribute (const Handle(OpenGl_Context)& theCtx,
+                     const GLchar* theName,
+                     ValueType& theValue) const
+  {
+    return GetAttribute (theCtx, GetAttributeLocation (theCtx, theName), theValue);
+  }
 
   //! Returns the integer vertex attribute.
+  //! Wrapper for glGetVertexAttribiv()
   Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
                                                  GLint                         theIndex,
                                                  OpenGl_Vec4i&                 theValue) const;
 
   //! Returns the float vertex attribute.
-  Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
-                                                 const GLchar*                 theName,
-                                                 OpenGl_Vec4&                  theValue) const;
-
-  //! Returns the float vertex attribute.
+  //! Wrapper for glGetVertexAttribfv()
   Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
                                                  GLint                         theIndex,
                                                  OpenGl_Vec4&                  theValue) const;
@@ -388,41 +390,30 @@ public:
                                                      GLint                         theIndex,
                                                      const GLchar*                 theName);
 
-  //! Wrapper for glVertexAttrib1f()
-  Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
-                                                 const GLchar*                 theName,
-                                                 GLfloat                       theValue);
+  //! Wrapper for glVertexAttrib*() for attribute with the given name.
+  template<typename ValueType>
+  bool SetAttribute (const Handle(OpenGl_Context)& theCtx,
+                     const GLchar* theName,
+                     const ValueType& theValue)
+  {
+    return SetAttribute (theCtx, GetAttributeLocation (theCtx, theName), theValue);
+  }
 
   //! Wrapper for glVertexAttrib1f()
   Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
                                                  GLint                         theIndex,
                                                  GLfloat                       theValue);
 
-  //! Wrapper for glVertexAttrib2fv()
-  Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
-                                                 const GLchar*                 theName,
-                                                 const OpenGl_Vec2&            theValue);
-
   //! Wrapper for glVertexAttrib2fv()
   Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
                                                  GLint                         theIndex,
                                                  const OpenGl_Vec2&            theValue);
 
-  //! Wrapper for glVertexAttrib3fv()
-  Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
-                                                 const GLchar*                 theName,
-                                                 const OpenGl_Vec3&            theValue);
-
   //! Wrapper for glVertexAttrib3fv()
   Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
                                                  GLint                         theIndex,
                                                  const OpenGl_Vec3&            theValue);
 
-  //! Wrapper for glVertexAttrib4fv()
-  Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
-                                                 const GLchar*                 theName,
-                                                 const OpenGl_Vec4&            theValue);
-
   //! Wrapper for glVertexAttrib4fv()
   Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
                                                  GLint                         theIndex,
@@ -430,42 +421,35 @@ public:
 
 public:
 
-  //! Specifies the value of the integer uniform variable.
-  Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
-                                               const GLchar*                 theName,
-                                               GLint                         theValue);
+  //! Specifies the value of the uniform variable with given name.
+  template<typename ValueType>
+  bool SetUniform (const Handle(OpenGl_Context)& theCtx,
+                   const GLchar* theName,
+                   const ValueType& theValue)
+  {
+    return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
+  }
 
   //! Specifies the value of the integer uniform variable.
+  //! Wrapper for glUniform1i()
   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
                                                GLint                         theLocation,
                                                GLint                         theValue);
 
   //! Specifies the value of the integer uniform 2D vector.
-  Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
-                                               const GLchar*                 theName,
-                                               const OpenGl_Vec2i&           theValue);
-
-  //! Specifies the value of the integer uniform 2D vector.
+  //! Wrapper for glUniform2iv()
   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
                                                GLint                         theLocation,
                                                const OpenGl_Vec2i&           theValue);
 
   //! Specifies the value of the integer uniform 3D vector.
-  Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
-                                               const GLchar*                 theName,
-                                               const OpenGl_Vec3i&           theValue);
-
-  //! Specifies the value of the integer uniform 3D vector.
+  //! Wrapper for glUniform3iv()
   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
                                                GLint                         theLocation,
                                                const OpenGl_Vec3i&           theValue);
 
   //! Specifies the value of the integer uniform 4D vector.
-  Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
-                                               const GLchar*                 theName,
-                                               const OpenGl_Vec4i&           theValue);
-
-  //! Specifies the value of the integer uniform 4D vector.
+  //! Wrapper for glUniform4iv()
   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
                                                GLint                         theLocation,
                                                const OpenGl_Vec4i&           theValue);
@@ -473,22 +457,20 @@ public:
 public:
 
   //! Specifies the value of the unsigned integer uniform 2D vector (uvec2).
-  Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
-                                               const GLchar*                 theName,
-                                               const OpenGl_Vec2u&           theValue);
-
-  //! Specifies the value of the unsigned integer uniform 2D vector (uvec2).
+  //! Wrapper for glUniform2uiv()
   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
                                                GLint                         theLocation,
                                                const OpenGl_Vec2u&           theValue);
 
   //! Specifies the value of the uvec2 uniform array
+  //! Wrapper for glUniform2uiv()
   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
                                                const GLchar*                 theName,
                                                const GLsizei                 theCount,
                                                const OpenGl_Vec2u*           theValue);
 
   //! Specifies the value of the uvec2 uniform array
+  //! Wrapper for glUniform2uiv()
   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
                                                GLint                         theLocation,
                                                const GLsizei                 theCount,
@@ -497,54 +479,50 @@ public:
 public:
 
   //! Specifies the value of the float uniform variable.
-  Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
-                                               const GLchar*                 theName,
-                                               GLfloat                       theValue);
-
-  //! Specifies the value of the float uniform variable.
+  //! Wrapper for glUniform1f()
   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
                                                GLint                         theLocation,
                                                GLfloat                       theValue);
 
   //! Specifies the value of the float uniform 2D vector.
-  Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
-                                               const GLchar*                 theName,
-                                               const OpenGl_Vec2&            theValue);
-
-  //! Specifies the value of the float uniform 2D vector.
+  //! Wrapper for glUniform2fv()
   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
                                                GLint                         theLocation,
                                                const OpenGl_Vec2&            theValue);
 
   //! Specifies the value of the float uniform 3D vector.
-  Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
-                                               const GLchar*                 theName,
-                                               const OpenGl_Vec3&            theValue);
-
-  //! Specifies the value of the float uniform 3D vector.
+  //! Wrapper for glUniform3fv()
   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
                                                GLint                         theLocation,
                                                const OpenGl_Vec3&            theValue);
 
   //! Specifies the value of the float uniform 4D vector.
-  Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
-                                               const GLchar*                 theName,
-                                               const OpenGl_Vec4&            theValue);
-
-  //! Specifies the value of the float uniform 4D vector.
+  //! Wrapper for glUniform4fv()
   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
                                                GLint                         theLocation,
                                                const OpenGl_Vec4&            theValue);
 
 public:
 
+  //! Specifies the value of the array of float uniform 3x3 matrices.
+  //! Wrapper over glUniformMatrix3fv().
+  Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)&  theCtx,
+                                               GLint                          theLocation,
+                                               GLuint                         theCount,
+                                               const NCollection_Mat3<float>* theData);
+
   //! Specifies the value of the float uniform 4x4 matrix.
-  Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
-                                               const GLchar*                 theName,
-                                               const OpenGl_Mat4&            theValue,
-                                               GLboolean                     theTranspose = GL_FALSE);
+  //! Wrapper for glUniformMatrix4fv()
+  bool SetUniform (const Handle(OpenGl_Context)& theCtx,
+                   const GLchar*                 theName,
+                   const OpenGl_Mat4&            theValue,
+                   GLboolean                     theTranspose = GL_FALSE)
+  {
+    return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue, theTranspose);
+  }
 
   //! Specifies the value of the float uniform 4x4 matrix.
+  //! Wrapper for glUniformMatrix4fv()
   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
                                                GLint                         theLocation,
                                                const OpenGl_Mat4&            theValue,
@@ -557,61 +535,57 @@ public:
                                                GLuint                        theCount,
                                                const OpenGl_Mat4*            theData);
 
-  //! Specifies the value of the float uniform 4x4 matrix.
-  Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
-                                               const GLchar*                 theName,
-                                               const OpenGl_Matrix&          theValue,
-                                               GLboolean                     theTranspose = GL_FALSE);
-
-  //! Specifies the value of the float uniform 4x4 matrix.
-  Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
-                                               GLint                         theLocation,
-                                               const OpenGl_Matrix&          theValue,
-                                               GLboolean                     theTranspose = GL_FALSE);
-
   //! Specifies the value of the float uniform array
+  //! Wrapper over glUniform1fv()
   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
                                                GLint                         theLocation,
                                                GLuint                        theCount,
                                                const Standard_ShortReal*     theData);
 
   //! Specifies the value of the float2 uniform array
+  //! Wrapper over glUniform2fv()
   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
                                                GLint                         theLocation,
                                                GLuint                        theCount,
                                                const OpenGl_Vec2*            theData);
 
   //! Specifies the value of the float3 uniform array
+  //! Wrapper over glUniform3fv()
   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
                                                GLint                         theLocation,
                                                GLuint                        theCount,
                                                const OpenGl_Vec3*            theData);
 
   //! Specifies the value of the float4 uniform array
+  //! Wrapper over glUniform4fv()
   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
                                                GLint                         theLocation,
                                                GLuint                        theCount,
                                                const OpenGl_Vec4*            theData);
 
   //! Specifies the value of the integer uniform array
+  //! Wrapper over glUniform1iv()
   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
                                                GLint                         theLocation,
                                                GLuint                        theCount,
                                                const Standard_Integer*       theData);
 
   //! Specifies the value of the int2 uniform array
+  //! Wrapper over glUniform2iv()
   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
                                                GLint                         theLocation,
                                                GLuint                        theCount,
                                                const OpenGl_Vec2i*           theData);
 
   //! Specifies the value of the int3 uniform array
+  //! Wrapper over glUniform3iv()
   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
                                                GLint                         theLocation,
                                                GLuint                        theCount,
                                                const OpenGl_Vec3i*           theData);
 
   //! Specifies the value of the int4 uniform array
+  //! Wrapper over glUniform4iv()
   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
                                                GLint                         theLocation,
                                                GLuint                        theCount,
@@ -620,9 +594,12 @@ public:
 public:
 
   //! Specifies the value of the sampler uniform variable.
-  Standard_EXPORT Standard_Boolean SetSampler (const Handle(OpenGl_Context)& theCtx,
-                                               const GLchar*                 theName,
-                                               const Graphic3d_TextureUnit   theTextureUnit);
+  bool SetSampler (const Handle(OpenGl_Context)& theCtx,
+                   const GLchar*                 theName,
+                   const Graphic3d_TextureUnit   theTextureUnit)
+  {
+    return SetSampler (theCtx, GetUniformLocation (theCtx, theName), theTextureUnit);
+  }
 
   //! Specifies the value of the sampler uniform variable.
   Standard_EXPORT Standard_Boolean SetSampler (const Handle(OpenGl_Context)& theCtx,
index b031d31..e603e30 100644 (file)
@@ -23,7 +23,6 @@
 
 #include <OpenGl_GraphicDriver.hxx>
 #include <OpenGl_Group.hxx>
-#include <OpenGl_Matrix.hxx>
 #include <OpenGl_Vec.hxx>
 #include <OpenGl_Workspace.hxx>
 
index a564109..8fe6df4 100644 (file)
@@ -53,8 +53,6 @@
 #include <map>
 #include <set>
 
-struct OpenGl_Matrix;
-
 class Graphic3d_StructureManager;
 class OpenGl_DepthPeeling;
 class OpenGl_GraphicDriver;
index 0bc8348..f4f8774 100644 (file)
 
 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Workspace,Standard_Transient)
 
-namespace
-{
-  static const OpenGl_Vec4 THE_WHITE_COLOR (1.0f, 1.0f, 1.0f, 1.0f);
-  static const OpenGl_Vec4 THE_BLACK_COLOR (0.0f, 0.0f, 0.0f, 1.0f);
-
-  static const OpenGl_Matrix myDefaultMatrix =
-  {
-    {{ 1.0F, 0.0F, 0.0F, 0.0F },
-     { 0.0F, 1.0F, 0.0F, 0.0F },
-     { 0.0F, 0.0F, 1.0F, 0.0F },
-     { 0.0F, 0.0F, 0.0F, 1.0F }}
-  };
-
-}
-
 // =======================================================================
 // function : Init
 // purpose  :
@@ -133,10 +118,7 @@ OpenGl_Workspace::OpenGl_Workspace (OpenGl_View* theView, const Handle(OpenGl_Wi
   //
   myAspectsSet (&myDefaultAspects),
   //
-  ViewMatrix_applied (&myDefaultMatrix),
-  StructureMatrix_applied (&myDefaultMatrix),
-  myToAllowFaceCulling (false),
-  myModelViewMatrix (myDefaultMatrix)
+  myToAllowFaceCulling (false)
 {
   if (!myGlContext.IsNull() && myGlContext->MakeCurrent())
   {
@@ -186,9 +168,6 @@ Standard_Boolean OpenGl_Workspace::Activate()
     return Standard_False;
   }
 
-  ViewMatrix_applied      = &myDefaultMatrix;
-  StructureMatrix_applied = &myDefaultMatrix;
-
   if (myGlContext->core11ffp == NULL)
   {
     if (myGlContext->caps->ffpEnable)
index 98a7969..af0b920 100644 (file)
@@ -22,7 +22,6 @@
 #include <OpenGl_CappingAlgo.hxx>
 #include <OpenGl_FrameBuffer.hxx>
 #include <OpenGl_Material.hxx>
-#include <OpenGl_Matrix.hxx>
 #include <OpenGl_ShaderObject.hxx>
 #include <OpenGl_ShaderProgram.hxx>
 #include <OpenGl_TextureBufferArb.hxx>
@@ -188,12 +187,6 @@ public:
   //! @sa OpenGl_LayerList::Render()
   void ResetSkippedCounter() { myNbSkippedTranspElems = 0; }
 
-  //! @return applied view matrix.
-  inline const OpenGl_Matrix* ViewMatrix() const { return ViewMatrix_applied; }
-
-  //! @return applied model structure matrix.
-  inline const OpenGl_Matrix* ModelMatrix() const { return StructureMatrix_applied; }
-
   //! Returns face aspect for none culling mode.
   const OpenGl_Aspects& NoneCulling() const { return myNoneCulling; }
 
@@ -230,14 +223,9 @@ protected: //! @name fields related to status
 
   Handle(Graphic3d_PresentationAttributes) myAspectFaceAppliedWithHL;
 
-  const OpenGl_Matrix* ViewMatrix_applied;
-  const OpenGl_Matrix* StructureMatrix_applied;
-
   bool            myToAllowFaceCulling; //!< allow back face culling
   Handle(Graphic3d_PresentationAttributes) myHighlightStyle; //!< active highlight style
 
-  OpenGl_Matrix myModelViewMatrix; //!< Model matrix with applied structure transformations
-
   OpenGl_Aspects myAspectFaceHl; //!< Hiddenline aspect
 
   Handle(OpenGl_TextureSet) myEnvironmentTexture;
index a6935be..6bce994 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <NCollection_IndexedDataMap.hxx>
 #include <NCollection_List.hxx>
+#include <Standard_OStream.hxx>
 #include <Standard_SStream.hxx>
 #include <TCollection_AsciiString.hxx>