1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-09-13 14:27:08 +03:00

0023457: Slow text rendering

Added class Font_FTFont wrapper over FreeType face

Unify collections methods NCollection_Array1, NCollection_Sequence, NCollection_Vector:
declare Upper, Lower, First, Last, ChangeFirst, ChangeLast methods for all these collections.

Added method NCollection_DataMap::Find() with check key is bound + retrieve value within single call interface.

OpenGl_Context::ReleaseResource() method now supports lazy release of shared resources.

Added class OpenGl_Font which implements textured fonts support.
Added class OpenGl_TextFormatter for text formatting using OpenGl_Font.

OpenGl_Text was redesigned to use OpenGl_FontFormatter.

OpenGl_FontMgr class was removed.
All methods related to text rendered removed from OpenGl_Display class.

OpenGl_Trihedron and OpenGl_GraduatedTrihedron classes were redesigned
to use OpenGl_Text.

OpenGl_PrinterContext instance was moved to OpenGl_GraphicDriver fields
(eliminated usage of global instance).

Added test cases into 3rdparty/fonts grid to check different font styles
and perform FPS tests (no automated results - requires manual analysis
or snapshots comparisons).

Removed unused CSF_FTGL dependency.
OpenGl_Text::setupMatrix - do not apply floor for myWinZ
This commit is contained in:
kgv
2013-02-08 15:05:16 +04:00
parent 163ef25006
commit a174a3c54f
72 changed files with 5397 additions and 2606 deletions

View File

@@ -1,6 +1,6 @@
// Created on: 2011-07-13
// Created by: Sergey ZERCHANINOV
// Copyright (c) 2011-2012 OPEN CASCADE SAS
// Copyright (c) 2011-2013 OPEN CASCADE SAS
//
// The content of this file is subject to the Open CASCADE Technology Public
// License Version 6.5 (the "License"). You may not use the content of this file
@@ -17,42 +17,147 @@
// purpose or non-infringement. Please see the License for the specific terms
// and conditions governing the rights and limitations under the License.
#ifndef OpenGl_Text_Header
#define OpenGl_Text_Header
#include <OpenGl_Element.hxx>
#include <OpenGl_AspectText.hxx>
#include <OpenGl_TextParam.hxx>
#include <OpenGl_TextFormatter.hxx>
#include <TCollection_ExtendedString.hxx>
#include <Graphic3d_Vertex.hxx>
#include <Graphic3d_HorizontalTextAlignment.hxx>
#include <Graphic3d_VerticalTextAlignment.hxx>
class Handle(OpenGl_PrinterContext);
//! Text rendering
class OpenGl_Text : public OpenGl_Element
{
public:
OpenGl_Text (const TCollection_ExtendedString& AText,
const Graphic3d_Vertex& APoint,
const Standard_Real AHeight,
const Graphic3d_HorizontalTextAlignment AHta,
const Graphic3d_VerticalTextAlignment AVta);
//! Main constructor
Standard_EXPORT OpenGl_Text (const TCollection_ExtendedString& theText,
const OpenGl_Vec3& thePoint,
const OpenGl_TextParam& theParams);
virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
virtual void Release (const Handle(OpenGl_Context)& theContext);
//! Setup new string and position
Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx,
const Standard_Utf8Char* theText,
const OpenGl_Vec3& thePoint);
//! Setup new string and parameters
Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx,
const Standard_Utf8Char* theText,
const OpenGl_Vec3& thePoint,
const OpenGl_TextParam& theParams);
//! Setup new position
Standard_EXPORT void SetPosition (const OpenGl_Vec3& thePoint);
//! Setup new font size
Standard_EXPORT void SetFontSize (const Handle(OpenGl_Context)& theContext,
const Standard_Integer theFontSize);
Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
Standard_EXPORT virtual void Release (const Handle(OpenGl_Context)& theContext);
public: //! @name methods for compatibility with layers
//! Empty constructor
OpenGl_Text();
//! Create key for shared resource
static TCollection_AsciiString FontKey (const OpenGl_AspectText& theAspect,
const Standard_Integer theHeight);
//! Find shared resource for specified font or initialize new one
static Handle(OpenGl_Font) FindFont (const Handle(OpenGl_Context)& theCtx,
const OpenGl_AspectText& theAspect,
const Standard_Integer theHeight,
const TCollection_AsciiString theKey);
//! Compute text width
static void StringSize (const Handle(OpenGl_Context)& theCtx,
const NCollection_String& theText,
const OpenGl_AspectText& theTextAspect,
const OpenGl_TextParam& theParams,
Standard_ShortReal& theWidth,
Standard_ShortReal& theAscent,
Standard_ShortReal& theDescent);
//! Setup new string and parameters
void Init (const Handle(OpenGl_Context)& theCtx,
const TCollection_ExtendedString& theText,
const OpenGl_Vec2& thePoint,
const OpenGl_TextParam& theParams);
//! Perform rendering
void Render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
const Handle(OpenGl_Context)& theCtx,
const OpenGl_AspectText& theTextAspect) const;
protected:
virtual ~OpenGl_Text();
//! Destructor
Standard_EXPORT virtual ~OpenGl_Text();
friend class OpenGl_Trihedron;
friend class OpenGl_GraduatedTrihedron;
private:
//! Release cached VBO resources
void releaseVbos (const Handle(OpenGl_Context)& theCtx);
//! Setup matrix.
void setupMatrix (const Handle(OpenGl_PrinterContext)& thePrintCtx,
const Handle(OpenGl_Context)& theCtx,
const OpenGl_AspectText& theTextAspect,
const OpenGl_Vec3 theDVec) const;
//! Draw arrays of vertices.
void drawText (const Handle(OpenGl_PrinterContext)& thePrintCtx,
const Handle(OpenGl_Context)& theCtx,
const OpenGl_AspectText& theTextAspect) const;
//! Main rendering code
void render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
const Handle(OpenGl_Context)& theCtx,
const OpenGl_AspectText& theTextAspect,
const TEL_COLOUR& theColorText,
const TEL_COLOUR& theColorSubs) const;
protected:
OpenGl_TextParam myParam;
TEL_POINT myAttachPnt;
const wchar_t *myString;
mutable Handle(OpenGl_Font) myFont;
mutable NCollection_Vector<GLuint> myTextures; //!< textures' IDs
mutable NCollection_Vector<Handle(OpenGl_VertexBuffer)> myVertsVbo; //!< VBOs of vertices
mutable NCollection_Vector<Handle(OpenGl_VertexBuffer)> myTCrdsVbo; //!< VBOs of texture coordinates
mutable NCollection_Vector<Handle(OpenGl_Vec2Array)> myVertsArray; //!< arrays of vertices (for compatibility mode)
mutable NCollection_Vector<Handle(OpenGl_Vec2Array)> myTCrdsArray; //!< arrays of vertices (for compatibility mode)
mutable Font_FTFont::Rect myBndBox;
protected:
mutable GLdouble myProjMatrix[16];
mutable GLdouble myModelMatrix[16];
mutable GLint myViewport[4];
mutable GLdouble myWinX;
mutable GLdouble myWinY;
mutable GLdouble myWinZ;
mutable GLdouble myScaleHeight;
mutable GLdouble myExportHeight;
protected:
OpenGl_TextParam myParams;
NCollection_String myString;
OpenGl_Vec3 myPoint;
bool myIs2d;
public: