const Standard_Integer theSizeX,
const Standard_Integer theSizeY)
{
+ Release (theCtx.operator->());
+
myVPSizeX = theSizeX;
myVPSizeY = theSizeY;
const Standard_Integer aSizeX = theSizeX > 0 ? theSizeX : 2;
const Standard_Integer aSizeY = theSizeY > 0 ? theSizeY : 2;
- Release (theCtx.operator->());
-
// Render target surface should be lockable on
// Windows XP and non-lockable on Windows Vista or higher
if (theD3DDevice->CreateRenderTarget (aSizeX, aSizeY,
#include <OpenGl_FrameBuffer.hxx>
struct IDirect3DDevice9;
+struct IDirect3DSurface9;
//! Implements bridge FBO for direct rendering to Direct3D surfaces.
class D3DHost_FrameBuffer : public OpenGl_FrameBuffer
IDirect3DSurface9* D3dColorSurface() { return myD3dSurf; }
//! Returns WDDM hande for D3D color surface.
- HANDLE D3dColorSurfaceShare() { return myD3dSurfShare; }
+ void* D3dColorSurfaceShare() { return myD3dSurfShare; }
protected:
protected:
IDirect3DSurface9* myD3dSurf; //!< D3D surface
- HANDLE myD3dSurfShare; //!< D3D surface share handle in WDDM
- HANDLE myGlD3dDevice; //!< WGL/D3D device handle
- HANDLE myGlD3dSurf; //!< WGL/D3D surface handle
+ void* myD3dSurfShare; //!< D3D surface share handle in WDDM
+ void* myGlD3dDevice; //!< WGL/D3D device handle
+ void* myGlD3dSurf; //!< WGL/D3D surface handle
Standard_Integer myLockCount; //!< locking counter
public:
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
+#include <d3d9.h>
+
#include <D3DHost_View.hxx>
#include <D3DHost_GraphicDriver.hxx>
// function : d3dFormatError
// purpose :
// =======================================================================
-TCollection_AsciiString D3DHost_View::d3dFormatError (HRESULT theErrCode)
+TCollection_AsciiString D3DHost_View::d3dFormatError (const long theErrCode)
{
switch (theErrCode)
{
: OpenGl_View (theMgr, theDriver, theCaps, theDeviceLostFlag, theCounter),
myD3dLib (NULL),
myD3dDevice (NULL),
+ myD3dParams (new D3DPRESENT_PARAMETERS()),
myRefreshRate (D3DPRESENT_RATE_DEFAULT),
myIsD3dEx (false)
{
- memset(&myD3dParams, 0, sizeof(myD3dParams));
- memset(&myCurrMode, 0, sizeof(myCurrMode));
-
- myD3dParams.Windowed = TRUE;
- myD3dParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
- myD3dParams.BackBufferFormat = D3DFMT_X8R8G8B8;
- myD3dParams.BackBufferCount = 1;
- myD3dParams.BackBufferHeight = 2;
- myD3dParams.BackBufferWidth = 2;
- myD3dParams.EnableAutoDepthStencil = FALSE;
- myD3dParams.AutoDepthStencilFormat = D3DFMT_D16_LOCKABLE;
- myD3dParams.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
- myD3dParams.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
+ memset(myD3dParams.operator->(), 0, sizeof(D3DPRESENT_PARAMETERS));
+
+ myD3dParams->Windowed = TRUE;
+ myD3dParams->SwapEffect = D3DSWAPEFFECT_DISCARD;
+ myD3dParams->BackBufferFormat = D3DFMT_X8R8G8B8;
+ myD3dParams->BackBufferCount = 1;
+ myD3dParams->BackBufferHeight = 2;
+ myD3dParams->BackBufferWidth = 2;
+ myD3dParams->EnableAutoDepthStencil = FALSE;
+ myD3dParams->AutoDepthStencilFormat = D3DFMT_D16_LOCKABLE;
+ myD3dParams->FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
+ myD3dParams->PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
}
// =======================================================================
UINT anAdapterId = D3DADAPTER_DEFAULT;
// setup the present parameters
- if (myD3dLib->GetAdapterDisplayMode (anAdapterId, &myCurrMode) == D3D_OK)
+ D3DDISPLAYMODE aCurrMode;
+ memset(&aCurrMode, 0, sizeof(aCurrMode));
+ if (myD3dLib->GetAdapterDisplayMode (anAdapterId, &aCurrMode) == D3D_OK)
{
- myD3dParams.BackBufferFormat = myCurrMode.Format;
- myRefreshRate = myCurrMode.RefreshRate;
+ myD3dParams->BackBufferFormat = aCurrMode.Format;
+ myRefreshRate = aCurrMode.RefreshRate;
}
- myD3dParams.Windowed = TRUE;
- myD3dParams.BackBufferWidth = myWindow->Width();
- myD3dParams.BackBufferHeight = myWindow->Height();
- myD3dParams.hDeviceWindow = (HWND )myWindow->PlatformWindow()->NativeHandle();
+ myD3dParams->Windowed = TRUE;
+ myD3dParams->BackBufferWidth = myWindow->Width();
+ myD3dParams->BackBufferHeight = myWindow->Height();
+ myD3dParams->hDeviceWindow = (HWND )myWindow->PlatformWindow()->NativeHandle();
// create the Video Device
HRESULT isOK = myD3dLib->CreateDevice (anAdapterId, D3DDEVTYPE_HAL,
(HWND )myWindow->PlatformWindow()->NativeHandle(),
D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE,
- &myD3dParams, &myD3dDevice);
+ myD3dParams.get(), &myD3dDevice);
if (isOK < 0)
{
return false;
return false;
}
- myD3dParams.Windowed = TRUE;
- myD3dParams.BackBufferWidth = myWindow->Width();
- myD3dParams.BackBufferHeight = myWindow->Height();
- myD3dParams.hDeviceWindow = (HWND )myWindow->PlatformWindow()->NativeHandle();
- myD3dParams.FullScreen_RefreshRateInHz = !myD3dParams.Windowed ? myRefreshRate : 0;
+ myD3dParams->Windowed = TRUE;
+ myD3dParams->BackBufferWidth = myWindow->Width();
+ myD3dParams->BackBufferHeight = myWindow->Height();
+ myD3dParams->hDeviceWindow = (HWND )myWindow->PlatformWindow()->NativeHandle();
+ myD3dParams->FullScreen_RefreshRateInHz = !myD3dParams->Windowed ? myRefreshRate : 0;
- HRESULT isOK = myD3dDevice->Reset(&myD3dParams);
+ HRESULT isOK = myD3dDevice->Reset(myD3dParams.get());
return isOK == D3D_OK;
}
{
return;
}
+ else if (myFBO != NULL)
+ {
+ OpenGl_View::Redraw();
+ return;
+ }
Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
myToFlipOutput = Standard_True;
myD3dWglFbo->LockSurface (aCtx);
+ myFBO = myD3dWglFbo.get();
OpenGl_View::Redraw();
+ myFBO = NULL;
myD3dWglFbo->UnlockSurface (aCtx);
myToFlipOutput = Standard_False;
if (aCtx->caps->buffersNoSwap)
{
return;
}
+ else if (myFBO != NULL)
+ {
+ OpenGl_View::Redraw();
+ return;
+ }
myToFlipOutput = Standard_True;
myD3dWglFbo->LockSurface (aCtx);
+ myFBO = myD3dWglFbo.get();
OpenGl_View::RedrawImmediate();
+ myFBO = NULL;
myD3dWglFbo->UnlockSurface (aCtx);
myToFlipOutput = Standard_False;
if (aCtx->caps->buffersNoSwap)
#ifndef _D3DHost_View_HeaderFile
#define _D3DHost_View_HeaderFile
-#include <d3d9.h>
-
#include <D3DHost_FrameBuffer.hxx>
#include <OpenGl_View.hxx>
#include <OpenGl_Workspace.hxx>
class D3DHost_GraphicDriver;
+struct IDirect3D9;
+struct IDirect3DDevice9;
+typedef struct _D3DPRESENT_PARAMETERS_ D3DPRESENT_PARAMETERS;
//! The D3D host view implementation that overrides rendering methods.
class D3DHost_View : public OpenGl_View
protected:
//! Auxiliary method.
- Standard_EXPORT static TCollection_AsciiString d3dFormatError (HRESULT theErrCode);
+ Standard_EXPORT static TCollection_AsciiString d3dFormatError (const long theErrCode);
//! Initialize the D3D library.
Standard_EXPORT bool d3dInitLib();
IDirect3D9* myD3dLib; //!< Direct3D library instance
IDirect3DDevice9* myD3dDevice; //!< Direct3D device object
- D3DPRESENT_PARAMETERS myD3dParams; //!< parameters for created Direct3D device
- D3DDISPLAYMODE myCurrMode; //!< temporary variable
- UINT myRefreshRate; //!< refresh rate in fullscreen mode
+ NCollection_Handle<D3DPRESENT_PARAMETERS>
+ myD3dParams; //!< parameters for created Direct3D device
+ unsigned int myRefreshRate; //!< refresh rate in fullscreen mode
bool myIsD3dEx; //!< D3dEx flag for WDDM
Handle(D3DHost_FrameBuffer) myD3dWglFbo; //!< D3D/WGL interop FBO
Font_FTLibrary.hxx
Font_NameOfFont.hxx
Font_NListOfSystemFont.hxx
+Font_Rect.hxx
Font_SystemFont.cxx
Font_SystemFont.hxx
Font_NameOfFont.hxx
// function : BoundingBox
// purpose :
// =======================================================================
-Font_FTFont::Rect Font_FTFont::BoundingBox (const NCollection_String& theString,
- const Graphic3d_HorizontalTextAlignment theAlignX,
- const Graphic3d_VerticalTextAlignment theAlignY)
+Font_Rect Font_FTFont::BoundingBox (const NCollection_String& theString,
+ const Graphic3d_HorizontalTextAlignment theAlignX,
+ const Graphic3d_VerticalTextAlignment theAlignY)
{
Font_TextFormatter aFormatter;
aFormatter.SetupAlignment (theAlignX, theAlignY);
aFormatter.Append (theString, *this);
aFormatter.Format();
- Rect aBndBox;
-
+ Font_Rect aBndBox;
aFormatter.BndBox (aBndBox);
-
return aBndBox;
}
#include <Font_FontAspect.hxx>
#include <Font_FTLibrary.hxx>
+#include <Font_Rect.hxx>
#include <Graphic3d_HorizontalTextAlignment.hxx>
#include <Graphic3d_VerticalTextAlignment.hxx>
#include <Image_PixMap.hxx>
#include <NCollection_String.hxx>
-#include <NCollection_Vec2.hxx>
//! Wrapper over FreeType font.
//! Notice that this class uses internal buffers for loaded glyphs
//! and it is absolutely UNSAFE to load/read glyph from concurrent threads!
class Font_FTFont : public Standard_Transient
{
-
-public:
-
- //! Auxiliary structure - rectangle definition
- struct Rect
- {
- float Left;
- float Right;
- float Top;
- float Bottom;
-
- NCollection_Vec2<float> TopLeft() const
- {
- return NCollection_Vec2<float> (Left, Top);
- }
-
- NCollection_Vec2<float>& TopLeft (NCollection_Vec2<float>& theVec) const
- {
- theVec.x() = Left;
- theVec.y() = Top;
- return theVec;
- }
-
- NCollection_Vec2<float>& TopRight (NCollection_Vec2<float>& theVec) const
- {
- theVec.x() = Right;
- theVec.y() = Top;
- return theVec;
- }
-
- NCollection_Vec2<float>& BottomLeft (NCollection_Vec2<float>& theVec) const
- {
- theVec.x() = Left;
- theVec.y() = Bottom;
- return theVec;
- }
-
- NCollection_Vec2<float>& BottomRight (NCollection_Vec2<float>& theVec) const
- {
- theVec.x() = Right;
- theVec.y() = Bottom;
- return theVec;
- }
-
- float Width () const
- {
- return Right - Left;
- }
-
- float Height () const
- {
- return Top - Bottom;
- }
-
- };
-
public:
//! Create uninitialized instance.
}
//! Retrieve glyph bitmap rectangle
- inline void GlyphRect (Font_FTFont::Rect& theRect) const
+ inline void GlyphRect (Font_Rect& theRect) const
{
const FT_Bitmap& aBitmap = myFTFace->glyph->bitmap;
theRect.Left = float(myFTFace->glyph->bitmap_left);
//! Computes bounding box of the given text using plain-text formatter (Font_TextFormatter).
//! Note that bounding box takes into account the text alignment options.
//! Its corners are relative to the text alignment anchor point, their coordinates can be negative.
- Standard_EXPORT Rect BoundingBox (const NCollection_String& theString,
- const Graphic3d_HorizontalTextAlignment theAlignX,
- const Graphic3d_VerticalTextAlignment theAlignY);
+ Standard_EXPORT Font_Rect BoundingBox (const NCollection_String& theString,
+ const Graphic3d_HorizontalTextAlignment theAlignX,
+ const Graphic3d_VerticalTextAlignment theAlignY);
protected:
--- /dev/null
+// Created by: Kirill GAVRILOV
+// Copyright (c) 2013-2015 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef _Font_Rect_H__
+#define _Font_Rect_H__
+
+#include <NCollection_Vec2.hxx>
+
+//! Auxiliary POD structure - 2D rectangle definition.
+struct Font_Rect
+{
+
+ float Left; //!< left position
+ float Right; //!< right position
+ float Top; //!< top position
+ float Bottom; //!< bottom position
+
+ //! Top-left corner as vec2.
+ NCollection_Vec2<float> TopLeft() const
+ {
+ return NCollection_Vec2<float> (Left, Top);
+ }
+
+ //! Top-left corner as vec2.
+ NCollection_Vec2<float>& TopLeft (NCollection_Vec2<float>& theVec) const
+ {
+ theVec.x() = Left;
+ theVec.y() = Top;
+ return theVec;
+ }
+
+ //! Top-right corner as vec2.
+ NCollection_Vec2<float>& TopRight (NCollection_Vec2<float>& theVec) const
+ {
+ theVec.x() = Right;
+ theVec.y() = Top;
+ return theVec;
+ }
+
+ //! Bottom-left corner as vec2.
+ NCollection_Vec2<float>& BottomLeft (NCollection_Vec2<float>& theVec) const
+ {
+ theVec.x() = Left;
+ theVec.y() = Bottom;
+ return theVec;
+ }
+
+ //! Bottom-right corner as vec2.
+ NCollection_Vec2<float>& BottomRight (NCollection_Vec2<float>& theVec) const
+ {
+ theVec.x() = Right;
+ theVec.y() = Bottom;
+ return theVec;
+ }
+
+ //! Rectangle width.
+ float Width() const
+ {
+ return Right - Left;
+ }
+
+ //! Rectangle height.
+ float Height() const
+ {
+ return Top - Bottom;
+ }
+
+};
+
+#endif // _Font_Rect_H__
#include <Font_TextFormatter.hxx>
+#include <Font_FTFont.hxx>
+
namespace
{
typedef NCollection_Vec2<Standard_ShortReal> Vec2f;
#ifndef Font_TextFormatter_Header
#define Font_TextFormatter_Header
-#include <Font_FTFont.hxx>
+#include <Font_Rect.hxx>
+#include <Graphic3d_HorizontalTextAlignment.hxx>
+#include <Graphic3d_VerticalTextAlignment.hxx>
#include <NCollection_DataMap.hxx>
#include <NCollection_Vector.hxx>
+#include <NCollection_String.hxx>
+
+class Font_FTFont;
//! This class intended to prepare formatted text.
class Font_TextFormatter
}
//! @param bounding box.
- inline void BndBox (Font_FTFont::Rect& theBndBox) const
+ inline void BndBox (Font_Rect& theBndBox) const
{
theBndBox.Left = 0.0f;
switch (myAlignX)
#include <OpenGl_Font.hxx>
#include <OpenGl_Context.hxx>
+#include <Font_FTFont.hxx>
#include <Graphic3d_TextureParams.hxx>
#include <Standard_Assert.hxx>
#include <TCollection_ExtendedString.hxx>
#include <OpenGl_Texture.hxx>
#include <OpenGl_Vec.hxx>
-#include <Font_FTFont.hxx>
+#include <Font_Rect.hxx>
#include <NCollection_DataMap.hxx>
#include <NCollection_Vector.hxx>
#include <TCollection_AsciiString.hxx>
+class Font_FTFont;
+
//! Texture font.
class OpenGl_Font : public OpenGl_Resource
{
//! Simple structure stores tile rectangle.
struct Tile
{
- Font_FTFont::Rect uv; //!< UV coordinates in texture
- Font_FTFont::Rect px; //!< pixel displacement coordinates
- GLuint texture; //!< GL texture ID
+ Font_Rect uv; //!< UV coordinates in texture
+ Font_Rect px; //!< pixel displacement coordinates
+ GLuint texture; //!< GL texture ID
};
struct RectI
return myFont;
}
- //! @return FreeType font instance specified on construction.
- inline Handle(Font_FTFont)& FTFont()
- {
- return myFont;
- }
-
//! @return true if font was loaded successfully.
inline bool IsValid() const
{
//! FreeType font instance should be already initialized!
Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theCtx);
- //! Compute advance to the next character with kerning applied when applicable.
- //! Assuming text rendered horizontally.
- inline float AdvanceX (const Standard_Utf32Char theUChar,
- const Standard_Utf32Char theUCharNext)
- {
- return myFont->AdvanceX (theUChar, theUCharNext);
- }
-
//! @return vertical distance from the horizontal baseline to the highest character coordinate
inline float Ascender() const
{
#include <OpenGl_View.hxx>
#include <Font_FontMgr.hxx>
+#include <Font_FTFont.hxx>
#include <Graphic3d_TransformUtils.hxx>
#include <TCollection_HAsciiString.hxx>
}
else if (aCharThis == ' ')
{
- aWidth += aFont->AdvanceX (aCharThis, aCharNext);
+ aWidth += aFont->FTFont()->AdvanceX (aCharThis, aCharNext);
continue;
}
else if (aCharThis == '\t')
{
- aWidth += aFont->AdvanceX (' ', aCharNext) * 8.0f;
+ aWidth += aFont->FTFont()->AdvanceX (' ', aCharNext) * 8.0f;
continue;
}
- aWidth += aFont->AdvanceX (aCharThis, aCharNext);
+ aWidth += aFont->FTFont()->AdvanceX (aCharThis, aCharNext);
}
theWidth = Max (theWidth, aWidth);
aFormatter.SetupAlignment (myParams.HAlign, myParams.VAlign);
aFormatter.Reset();
- aFormatter.Append (myString, *myFont->FTFont());
+ aFormatter.Append (myString, *myFont->FTFont().operator->());
aFormatter.Format();
OpenGl_TextBuilder aBuilder;
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 Font_FTFont::Rect myBndBox;
+ mutable Font_Rect myBndBox;
protected:
#include <OpenGl_TextBuilder.hxx>
#include <OpenGl_VertexBufferCompat.hxx>
+#include <Font_FTFont.hxx>
+
namespace
{
//! Apply floor to vector components.
else if (aCharThis == ' ')
{
++aSymbolsCounter;
- aPen.x() += theFont.AdvanceX (' ', aCharNext);
+ aPen.x() += theFont.FTFont()->AdvanceX (' ', aCharNext);
continue;
}
else if (aCharThis == '\t')
{
const Standard_Integer aSpacesNum = (theFormatter.TabSize() - (aSymbolsCounter - 1) % theFormatter.TabSize());
- aPen.x() += theFont.AdvanceX (' ', aCharNext) * Standard_ShortReal(aSpacesNum);
+ aPen.x() += theFont.FTFont()->AdvanceX (' ', aCharNext) * Standard_ShortReal(aSpacesNum);
aSymbolsCounter += aSpacesNum;
continue;
}
aTile.px.Left += aTopLeft.x();
aTile.px.Bottom += aTopLeft.y();
aTile.px.Top += aTopLeft.y();
- const Font_FTFont::Rect& aRectUV = aTile.uv;
- const GLuint aTexture = aTile.texture;
+ const Font_Rect& aRectUV = aTile.uv;
+ const GLuint aTexture = aTile.texture;
Standard_Integer aListId = 0;
for (aListId = 0; aListId < theTextures.Length(); ++aListId)
Standard_EXPORT virtual void Invalidate() Standard_OVERRIDE;
//! Return true if view content cache has been invalidated.
- virtual Standard_Boolean IsInvalidated() Standard_OVERRIDE { return myBackBufferRestored; }
+ virtual Standard_Boolean IsInvalidated() Standard_OVERRIDE { return !myBackBufferRestored; }
//! Displays z-buffer trihedron.
Standard_EXPORT virtual void TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition = Aspect_TOTP_CENTER,