Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-06 09:21:50

0001 // Created on: 2011-07-13
0002 // Created by: Sergey ZERCHANINOV
0003 // Copyright (c) 2011-2013 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_Text_HeaderFile
0017 #define OpenGl_Text_HeaderFile
0018 
0019 #include <OpenGl_Element.hxx>
0020 
0021 #include <OpenGl_TextBuilder.hxx>
0022 
0023 #include <Graphic3d_RenderingParams.hxx>
0024 #include <Graphic3d_Text.hxx>
0025 
0026 //! Text rendering
0027 class OpenGl_Text : public OpenGl_Element
0028 {
0029 
0030 public:
0031   //! Creates new text in 3D space.
0032   Standard_EXPORT OpenGl_Text(const occ::handle<Graphic3d_Text>& theTextParams);
0033 
0034   //! Destructor
0035   Standard_EXPORT ~OpenGl_Text() override;
0036 
0037   //! Release cached VBO resources and the previous font if height changed.
0038   //! Cached structures will be refilled by the next render.
0039   //! Call Reset after modifying text parameters.
0040   Standard_EXPORT void Reset(const occ::handle<OpenGl_Context>& theCtx);
0041 
0042   //! Returns text parameters
0043   //! @sa Reset()
0044   const occ::handle<Graphic3d_Text>& Text() const { return myText; }
0045 
0046   //! Sets text parameters
0047   //! @sa Reset()
0048   void SetText(const occ::handle<Graphic3d_Text>& theText) { myText = theText; }
0049 
0050   //! Return true if text is 2D
0051   bool Is2D() const { return myIs2d; }
0052 
0053   //! Set true if text is 2D
0054   void Set2D(const bool theEnable) { myIs2d = theEnable; }
0055 
0056   //! Setup new font size
0057   Standard_EXPORT void SetFontSize(const occ::handle<OpenGl_Context>& theContext,
0058                                    const int                          theFontSize);
0059 
0060   Standard_EXPORT void Render(const occ::handle<OpenGl_Workspace>& theWorkspace) const override;
0061   Standard_EXPORT void Release(OpenGl_Context* theContext) override;
0062 
0063   //! Returns estimated GPU memory usage for holding data without considering overheads and
0064   //! allocation alignment rules.
0065   Standard_EXPORT size_t EstimatedDataSize() const override;
0066 
0067   //! Increment draw calls statistics.
0068   Standard_EXPORT void UpdateDrawStats(Graphic3d_FrameStatsDataTmp& theStats,
0069                                        bool                         theIsDetailed) const override;
0070 
0071 public: //! @name methods for compatibility with layers
0072   //! Empty constructor
0073   Standard_EXPORT OpenGl_Text();
0074 
0075   //! Create key for shared resource
0076   Standard_EXPORT static TCollection_AsciiString FontKey(const OpenGl_Aspects& theAspect,
0077                                                          int                   theHeight,
0078                                                          unsigned int          theResolution,
0079                                                          Font_Hinting          theFontHinting);
0080 
0081   //! Find shared resource for specified font or initialize new one
0082   Standard_EXPORT static occ::handle<OpenGl_Font> FindFont(
0083     const occ::handle<OpenGl_Context>& theCtx,
0084     const OpenGl_Aspects&              theAspect,
0085     int                                theHeight,
0086     unsigned int                       theResolution,
0087     Font_Hinting                       theFontHinting,
0088     const TCollection_AsciiString&     theKey);
0089 
0090   //! Compute text width
0091   Standard_EXPORT static void StringSize(const occ::handle<OpenGl_Context>& theCtx,
0092                                          const NCollection_String&          theText,
0093                                          const OpenGl_Aspects&              theTextAspect,
0094                                          const float                        theHeight,
0095                                          const unsigned int                 theResolution,
0096                                          const Font_Hinting                 theFontHinting,
0097                                          float&                             theWidth,
0098                                          float&                             theAscent,
0099                                          float&                             theDescent);
0100 
0101   //! Perform rendering
0102   Standard_EXPORT void Render(
0103     const occ::handle<OpenGl_Context>& theCtx,
0104     const OpenGl_Aspects&              theTextAspect,
0105     unsigned int theResolution  = Graphic3d_RenderingParams::THE_DEFAULT_RESOLUTION,
0106     Font_Hinting theFontHinting = Font_Hinting_Off) const;
0107 
0108   //! Dumps the content of me into the stream
0109   Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const override;
0110 
0111   //! @name obsolete methods
0112 public:
0113   //! Setup new string and position
0114   Standard_DEPRECATED(
0115     "Deprecated method Init() with obsolete arguments, use Init() and Text() instead of it")
0116   Standard_EXPORT void Init(const occ::handle<OpenGl_Context>& theCtx,
0117                             const char*                        theText,
0118                             const NCollection_Vec3<float>&     thePoint);
0119 
0120   //! Setup new position
0121   Standard_DEPRECATED("Deprecated method SetPosition(), use Graphic3d_Text for it")
0122   Standard_EXPORT void SetPosition(const NCollection_Vec3<float>& thePoint);
0123 
0124 protected:
0125   friend class OpenGl_Trihedron;
0126   friend class OpenGl_GraduatedTrihedron;
0127 
0128   //! Release cached VBO resources
0129   Standard_EXPORT void releaseVbos(OpenGl_Context* theCtx);
0130 
0131 private:
0132   //! Setup matrix.
0133   void setupMatrix(const occ::handle<OpenGl_Context>& theCtx,
0134                    const OpenGl_Aspects&              theTextAspect,
0135                    const NCollection_Vec3<float>&     theDVec) const;
0136 
0137   //! Draw arrays of vertices.
0138   void drawText(const occ::handle<OpenGl_Context>& theCtx,
0139                 const OpenGl_Aspects&              theTextAspect) const;
0140 
0141   //! Draw rectangle from bounding text box.
0142   void drawRect(const occ::handle<OpenGl_Context>& theCtx,
0143                 const OpenGl_Aspects&              theTextAspect,
0144                 const NCollection_Vec4<float>&     theColorSubs) const;
0145 
0146   //! Main rendering code
0147   void render(const occ::handle<OpenGl_Context>& theCtx,
0148               const OpenGl_Aspects&              theTextAspect,
0149               const NCollection_Vec4<float>&     theColorText,
0150               const NCollection_Vec4<float>&     theColorSubs,
0151               unsigned int                       theResolution,
0152               Font_Hinting                       theFontHinting) const;
0153 
0154 protected:
0155   occ::handle<Graphic3d_Text>              myText; //!< text parameters
0156   mutable occ::handle<OpenGl_Font>         myFont;
0157   mutable NCollection_DynamicArray<GLuint> myTextures; //!< textures' IDs
0158   mutable NCollection_DynamicArray<occ::handle<OpenGl_VertexBuffer>>
0159     myVertsVbo; //!< VBOs of vertices
0160                 // clang-format off
0161   mutable NCollection_DynamicArray<occ::handle<OpenGl_VertexBuffer>> myTCrdsVbo;   //!< VBOs of texture coordinates
0162   mutable occ::handle<OpenGl_VertexBuffer>                     myBndVertsVbo;//!< VBOs of vertices for bounding box
0163                                                         // clang-format on
0164   mutable Font_Rect myBndBox;
0165 
0166 protected:
0167   mutable NCollection_Mat4<double> myProjMatrix;
0168   mutable NCollection_Mat4<double> myModelMatrix;
0169   mutable NCollection_Mat4<double> myOrientationMatrix;
0170   mutable NCollection_Vec3<double> myWinXYZ;
0171   mutable GLdouble                 myScaleHeight;
0172 
0173 protected:
0174   bool myIs2d;
0175 
0176 public:
0177   DEFINE_STANDARD_ALLOC
0178 };
0179 
0180 #endif // OpenGl_Text_Header