0025885: Visualization, ray tracing - Improve layer processing
[occt.git] / src / OpenGl / OpenGl_ShaderProgram.hxx
index 611d2ed..bb6d0ba 100755 (executable)
@@ -1,11 +1,11 @@
 // Created on: 2013-09-19
 // Created by: Denis BOGOLEPOV
-// Copyright (c) 2013 OPEN CASCADE SAS
+// Copyright (c) 2013-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 version 2.1 as published
+// 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.
@@ -50,6 +50,7 @@ enum OpenGl_StateVariable
   // OpenGL clip planes state
   OpenGl_OCC_CLIP_PLANE_EQUATIONS,
   OpenGl_OCC_CLIP_PLANE_SPACES,
+  OpenGl_OCC_CLIP_PLANE_COUNT,
 
   // OpenGL light state
   OpenGl_OCC_LIGHT_SOURCE_COUNT,
@@ -63,6 +64,9 @@ enum OpenGl_StateVariable
   OpenGl_OCCT_DISTINGUISH_MODE,
   OpenGl_OCCT_FRONT_MATERIAL,
   OpenGl_OCCT_BACK_MATERIAL,
+  OpenGl_OCCT_COLOR,
+
+  OpenGl_OCCT_POINT_SIZE,
 
   // DON'T MODIFY THIS ITEM (insert new items before it)
   OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES
@@ -118,7 +122,8 @@ enum OpenGl_UniformStateType
   OpenGl_MODEL_WORLD_STATE,
   OpenGl_WORLD_VIEW_STATE,
   OpenGl_PROJECTION_STATE,
-  OpenGl_MATERIALS_STATE
+  OpenGl_MATERIALS_STATE,
+  OpenGl_SURF_DETAIL_STATE
 };
 
 //! Total number of state types.
@@ -127,6 +132,7 @@ const int MaxStateTypes = 6;
 //! Wrapper for OpenGL program object.
 class OpenGl_ShaderProgram : public OpenGl_Resource
 {
+  friend class OpenGl_View;
 
 public:
 
@@ -155,7 +161,7 @@ public:
   Standard_EXPORT Standard_Boolean Create (const Handle(OpenGl_Context)& theCtx);
 
   //! Destroys shader program.
-  Standard_EXPORT virtual void Release (const OpenGl_Context* theCtx);
+  Standard_EXPORT virtual void Release (OpenGl_Context* theCtx);
 
   //! Attaches shader object to the program object.
   Standard_EXPORT Standard_Boolean AttachShader (const Handle(OpenGl_Context)&      theCtx,
@@ -179,21 +185,18 @@ public:
   //! Fetches uniform variables from proxy shader program.
   Standard_EXPORT Standard_Boolean ApplyVariables (const Handle(OpenGl_Context)& theCtx);
 
-  //! Sets the program object as part of current rendering state.
-  Standard_EXPORT void Bind (const Handle(OpenGl_Context)& theCtx) const;
-
-  //! Binds the program object and applies variables from proxy shader program.
-  Standard_EXPORT Standard_Boolean BindWithVariables (const Handle(OpenGl_Context)& theCtx);
-
-  //! Reverts to fixed-function graphics pipeline (FFP).
-  Standard_EXPORT static void Unbind (const Handle(OpenGl_Context)& theCtx);
-
   //! @return true if current object was initialized
   inline bool IsValid() const
   {
     return myProgramID != NO_PROGRAM;
   }
 
+  //! @return program ID
+  inline GLuint ProgramId() const
+  {
+    return myProgramID;
+  }
+
 private:
 
   //! Returns index of last modification of variables of specified state type.
@@ -259,6 +262,53 @@ public:
                                                  GLint                         theIndex,
                                                  OpenGl_Vec4&                  theValue) const;
 
+public:
+
+  //! Wrapper for glBindAttribLocation()
+  Standard_EXPORT Standard_Boolean SetAttributeName (const Handle(OpenGl_Context)& theCtx,
+                                                     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 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,
+                                                 const OpenGl_Vec4&            theValue);
+
 public:
 
   //! Specifies the value of the integer uniform variable.
@@ -301,6 +351,30 @@ public:
                                                GLint                         theLocation,
                                                const OpenGl_Vec4i&           theValue);
 
+public:
+
+  //! Specifies the value of the 64-bit unsigned integer uniform variable.
+  Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
+                                               const GLchar*                 theName,
+                                               GLuint64                      theValue);
+
+  //! Specifies the value of the 64-bit unsigned integer uniform variable.
+  Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
+                                               GLint                         theLocation,
+                                               GLuint64                      theValue);
+
+  //! Specifies the value of the 64-bit unsigned integer uniform array.
+  Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
+                                               const GLchar*                 theName,
+                                               const GLsizei                 theCount,
+                                               const GLuint64*               theValue);
+
+  //! Specifies the value of the 64-bit unsigned integer uniform array.
+  Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
+                                               GLint                         theLocation,
+                                               const GLsizei                 theCount,
+                                               const GLuint64*               theValue);
+
 public:
 
   //! Specifies the value of the float uniform variable.
@@ -348,25 +422,25 @@ public:
   //! 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,
+                                               const OpenGl_Mat4&            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,
+                                               const OpenGl_Mat4&            theValue,
                                                GLboolean                     theTranspose = GL_FALSE);
 
   //! Specifies the value of the float uniform 4x4 matrix.
   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
                                                const GLchar*                 theName,
-                                               const Tmatrix3&               theValue,
+                                               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 Tmatrix3&               theValue,
+                                               const OpenGl_Matrix&          theValue,
                                                GLboolean                     theTranspose = GL_FALSE);
 
   //! Specifies the value of the float uniform array
@@ -456,8 +530,7 @@ protected:
 
 protected:
 
-  //! Defines last modification for variables of each state type.
-  Standard_Size myCurrentState[MaxStateTypes];
+  Standard_Size myCurrentState[MaxStateTypes];  //!< defines last modification for variables of each state type
 
   //! Stores locations of OCCT state uniform variables.
   GLint myStateLocations[OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES];