Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:21

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 
0033   //! Main constructor.
0034   Standard_EXPORT OpenGl_BackgroundArray (const Graphic3d_TypeOfBackground theType);
0035 
0036   //! Render primitives to the window
0037   Standard_EXPORT void Render (const Handle(OpenGl_Workspace)& theWorkspace,
0038                                Graphic3d_Camera::Projection theProjection) const;
0039 
0040   //! Check if background parameters are set properly
0041   Standard_EXPORT bool IsDefined() const;
0042 
0043   //! Sets background texture parameters
0044   Standard_EXPORT void SetTextureParameters (const Aspect_FillMethod theFillMethod);
0045 
0046   //! Sets texture fill method
0047   Standard_EXPORT void SetTextureFillMethod (const Aspect_FillMethod theFillMethod);
0048 
0049   //! Gets background texture fill method
0050   Aspect_FillMethod TextureFillMethod() const { return myFillMethod; }
0051 
0052   //! Gets background gradient fill method
0053   Aspect_GradientFillMethod GradientFillMethod() const { return myGradientParams.type; }
0054 
0055   //! Returns color of gradient background for the given index.
0056   const OpenGl_Vec4& GradientColor (const Standard_Integer theIndex) const { return (&myGradientParams.color1)[theIndex]; }
0057 
0058   //! Sets type of gradient fill method
0059   Standard_EXPORT void SetGradientFillMethod (const Aspect_GradientFillMethod theType);
0060 
0061   //! Sets background gradient parameters
0062   Standard_EXPORT void SetGradientParameters (const Quantity_Color&           theColor1,
0063                                               const Quantity_Color&           theColor2,
0064                                               const Aspect_GradientFillMethod theType);
0065 
0066 protected: //! @name Internal structure for storing gradient parameters
0067 
0068   struct OpenGl_GradientParameters
0069   {
0070     OpenGl_Vec4 color1;
0071     OpenGl_Vec4 color2;
0072     Aspect_GradientFillMethod type;
0073   };
0074 
0075 protected:
0076 
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 Standard_Boolean init (const Handle(OpenGl_Workspace)& theWorkspace) const;
0081 
0082   //! Initializes gradient arrays.
0083   Standard_EXPORT Standard_Boolean createGradientArray (const 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 Standard_Boolean createTextureArray (const Handle(OpenGl_Workspace)& theWorkspace) const;
0088 
0089   //! Initializes cubemap arrays.
0090   Standard_EXPORT Standard_Boolean 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 
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 Standard_Integer          myViewWidth;      //!< view width  used for array initialization
0104   mutable Standard_Integer          myViewHeight;     //!< view height used for array initialization
0105   mutable Standard_Boolean          myToUpdate;       //!< Shows if array parameters were changed and data (myAttribs storage) is to be updated
0106 
0107 };
0108 
0109 #endif // OpenGl_BackgroundArray_Header