Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-26 09:04:08

0001 // Created on: 2015-01-16
0002 // Created by: Anastasia BORISOVA
0003 // Copyright (c) 2015 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef OpenGl_BackgroundArray_Header
0017 #define OpenGl_BackgroundArray_Header
0018 
0019 #include <Aspect_GradientFillMethod.hxx>
0020 #include <Aspect_FillMethod.hxx>
0021 #include <Graphic3d_Camera.hxx>
0022 #include <Graphic3d_TypeOfBackground.hxx>
0023 #include <OpenGl_Aspects.hxx>
0024 #include <OpenGl_PrimitiveArray.hxx>
0025 #include <OpenGl_Vec.hxx>
0026 
0027 //! Tool class for generating reusable data for
0028 //! gradient or texture background rendering.
0029 class OpenGl_BackgroundArray : public OpenGl_PrimitiveArray
0030 {
0031 public:
0032   //! Main constructor.
0033   Standard_EXPORT OpenGl_BackgroundArray(const Graphic3d_TypeOfBackground theType);
0034 
0035   //! Render primitives to the window
0036   Standard_EXPORT void Render(const occ::handle<OpenGl_Workspace>& theWorkspace,
0037                               Graphic3d_Camera::Projection         theProjection) const;
0038 
0039   //! Check if background parameters are set properly
0040   Standard_EXPORT bool IsDefined() const;
0041 
0042   //! Sets background texture parameters
0043   Standard_EXPORT void SetTextureParameters(const Aspect_FillMethod theFillMethod);
0044 
0045   //! Sets texture fill method
0046   Standard_EXPORT void SetTextureFillMethod(const Aspect_FillMethod theFillMethod);
0047 
0048   //! Gets background texture fill method
0049   Aspect_FillMethod TextureFillMethod() const { return myFillMethod; }
0050 
0051   //! Gets background gradient fill method
0052   Aspect_GradientFillMethod GradientFillMethod() const { return myGradientParams.type; }
0053 
0054   //! Returns color of gradient background for the given index.
0055   const NCollection_Vec4<float>& GradientColor(const int theIndex) const
0056   {
0057     return (&myGradientParams.color1)[theIndex];
0058   }
0059 
0060   //! Sets type of gradient fill method
0061   Standard_EXPORT void SetGradientFillMethod(const Aspect_GradientFillMethod theType);
0062 
0063   //! Sets background gradient parameters
0064   Standard_EXPORT void SetGradientParameters(const Quantity_Color&           theColor1,
0065                                              const Quantity_Color&           theColor2,
0066                                              const Aspect_GradientFillMethod theType);
0067 
0068 protected: //! @name Internal structure for storing gradient parameters
0069   struct OpenGl_GradientParameters
0070   {
0071     NCollection_Vec4<float>   color1;
0072     NCollection_Vec4<float>   color2;
0073     Aspect_GradientFillMethod type;
0074   };
0075 
0076 protected:
0077   //! Fill attributes arrays for background array according to its type:
0078   //! - for gradient background its attributes consist of colors and gradient coordinates
0079   //! - for texture one its attributes consist of position and texture coordinates.
0080   Standard_EXPORT bool init(const occ::handle<OpenGl_Workspace>& theWorkspace) const;
0081 
0082   //! Initializes gradient arrays.
0083   Standard_EXPORT bool createGradientArray(const occ::handle<OpenGl_Context>& theCtx) const;
0084 
0085   //! Initializes texture arrays.
0086   //! @param theWorkspace OpenGl workspace that stores texture in the current enabled face aspect.
0087   Standard_EXPORT bool createTextureArray(const occ::handle<OpenGl_Workspace>& theWorkspace) const;
0088 
0089   //! Initializes cubemap arrays.
0090   Standard_EXPORT bool createCubeMapArray() const;
0091 
0092   //! Marks array parameters as changed,
0093   //! on next rendering stage array data is to be updated.
0094   Standard_EXPORT void invalidateData();
0095 
0096   using OpenGl_PrimitiveArray::Render;
0097 
0098 protected:
0099   // clang-format off
0100   Graphic3d_TypeOfBackground        myType;           //!< Type of background: texture or gradient.
0101   Aspect_FillMethod                 myFillMethod;     //!< Texture parameters
0102   mutable OpenGl_GradientParameters myGradientParams; //!< Gradient parameters
0103   mutable int          myViewWidth;      //!< view width  used for array initialization
0104   mutable int          myViewHeight;     //!< view height used for array initialization
0105   mutable bool          myToUpdate;       //!< Shows if array parameters were changed and data (myAttribs storage) is to be updated
0106   // clang-format on
0107 };
0108 
0109 #endif // OpenGl_BackgroundArray_Header