Back to home page

EIC code displayed by LXR

 
 

    


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

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