/** * @file XTPChartOpenGLDeviceContext.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ /** @cond */ #if !defined(__XTPCHARTOPENGLDEVICECONTEXT_H__) # define __XTPCHARTOPENGLDEVICECONTEXT_H__ # if _MSC_VER >= 1000 # pragma once # endif // _MSC_VER >= 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" template class CXTPMatrix; class CXTPChartContainer; class CXTPChartDeviceCommand; class _XTP_EXT_CLASS CXTPChartOpenGLDeviceContext : public CXTPChart3dDeviceContext { DECLARE_DYNAMIC(CXTPChartOpenGLDeviceContext); public: /** * @brief * Constructs a CXTPChartOpenGLDeviceContext object. * * @param hDC Handle to the windows device context. */ CXTPChartOpenGLDeviceContext(CXTPChartContainer* pContainer, HDC hDC, CRect rcBounds); /** * @brief * Destroys a CXTPChartOpenGLDeviceContext object, handles cleanup. */ ~CXTPChartOpenGLDeviceContext(); public: /** * @brief * Call this function to trigger the drawing. * * @param pCommand A pointer to chart device command object. */ virtual void Execute(CXTPChartDeviceCommand* pCommand); /** * @brief * Initializes device context. */ virtual BOOL Initialize(); /** * @brief * Call this function to get the measurements of texts rendered in a * device context using a specific font. * * @param pText The string to be measured. * @param pFont Pointer to chart font object. * * @return Measured string size. */ virtual CXTPChartSizeF MeasureString(const CXTPChartString* pText, CXTPChartFont* pFont); /** * @brief * Call this function to get the measurements of a markup element rendered in a * device context using a specific font. * * @param pText The string to be measured. * @param pFont Pointer to chart font object. * * @return Measured element size. */ virtual CXTPChartSizeF MeasureMarkupElement(CXTPMarkupUIElement* pMarkupUIElement, CXTPChartFont* pFont); /** * @brief * Rotates current matrix. * * @param rotation Matrix rotation arguments. */ virtual void Rotate(const CXTPChart3dRotation& rotation); /** * @brief * Projects 3D coordinates to 2D space point coordinates. * * @param pt3d 3D space point coordinates. * @param pt2d Result 2D space point coordinates. * @param pdWinZ If specified the result value is within range 0..1 * where 0 defines the near plane and 1 defines the far * plane defined by the view frustum. * * @return TRUE if coordinates are mapped successfully, FALSE otherwise. * * @see * Unproject */ virtual BOOL Project(const CXTPPoint3d& pt3d, CPoint& pt2d, double* pdWinZ = NULL); /** * @brief * Projects 3D coordinates to 2D space point coordinates. * * @param box 3D box to map to the outer 2D rectangle. * @param rc Resuylt 2D outer rectangle for the 3D box specified. * * @return TRUE if coordinates are mapped successfully, FALSE otherwise. * * @see * Unproject */ virtual BOOL Project(const CXTPChart3dBox& box, CRect& rc); /** * @brief * Projects 2D space point coordinates to 3D space point coordinate * on the specified plane. * * @param pt2d 2D space point coordinates. * @param pt3d Result 3D space point coordinates. * @param dWinZ Determines how far the point is from the near plane. * The value must be within 0..1 range where 0 determines * the near frustum plane and 1 determines the far plane. * * @return TRUE is the coordinates are mapped successfully, FALSE otherwise. * * @see * Project */ virtual BOOL Unproject(const CPoint& pt2d, CXTPPoint3d& pt3d, double dWinZ = 0.); /** * @brief * Transforms vector or box coordinates. * * @param v A vector to transform. * @param pTranslation Optional translation offsets to add to the vector or box vertices. * @param pRotation Optional vector opr box vertices rotation parameters. */ virtual void Transform(CXTPPoint3d& v, const CXTPPoint3d* pTranslation = NULL, const CXTPChart3dRotation* pRotation = NULL); /** * @brief * Transforms vector or box coordinates. * * @param box A box to transform. * @param pTranslation Optional translation offsets to add to the vector or box vertices. * @param pRotation Optional vector opr box vertices rotation parameters. */ virtual void Transform(CXTPChart3dBox& box, const CXTPPoint3d* pTranslation = NULL, const CXTPChart3dRotation* pRotation = NULL); /** * @brief * Transforms vector or box coordinates. * * @param v A vector to transform. * @param matrix OpenGL matrix to be used for vector transformation. */ virtual void Transform(CXTPPoint3d& v, const CXTPMatrix& matrix); /** * @brief * Transforms vector or box coordinates. * * @param box A box to transform. * @param matrix OpenGL matrix to be used for vector transformation. */ virtual void Transform(CXTPChart3dBox& box, const CXTPMatrix& matrix); /** * @brief * Performs depth test for 2D point provided. * * @param point Viewport offset for which depth test is to be performed. * @param dWinZ If succeeds the value contains the distance from the near (0) * plane of the view frustum to the fist visible point. * * @return TRUE if depth test is successful, FALSE otherwise. */ virtual BOOL DepthTest(CPoint point, double& dWinZ); /** * @brief * Clamps transparency value in range [0..255] used in chart style * to OpenGL alpha value in the range [0..1]. * * @param nTransparency Transparency value in the range [0..255]. * * @return OpenGL alpha value. */ static float ClampTransparency(int nTransparency); private: BOOL InitializePixelFormat(); void SetOpenGLParameters(); BOOL OnPreRender(); void OnPostRender(); double ComputeAntialiasingJitterFactor() const; void Execute3dCommandTree(CXTPChartDeviceCommand* pCommand); void Execute2dCommandTree(CXTPChartDeviceCommand* pCommand); CXTPMatrix* BuildTransformationMatrix(const CXTPPoint3d* pTranslation = NULL, const CXTPChart3dRotation* pRotation = NULL); void Render3dCommand(CXTPChartDeviceCommand* pCommand, double& dJitterFactor, BOOL bAntialiased = FALSE); void RenderTriangles(double& dJitterFactor, BOOL bAntialiased = FALSE); protected: /** @cond */ HGLRC m_hGLContext; int m_nExecuteNesting; CList m_2dCommands; BOOL m_bHave2dCommands; BOOL m_bIn2dCommandExecutionMode; CXTPChartDeviceContext* m_p2dDC; static const CXTPPoint3d m_arJitter[]; static const float m_fJitterAccumStep; /** @endcond */ }; AFX_INLINE float CXTPChartOpenGLDeviceContext::ClampTransparency(int nTransparency) { _ASSERTE(0 <= nTransparency && nTransparency <= 255); return (1.f - static_cast(nTransparency) / 255); } # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" #endif //#if !defined(__XTPCHARTOPENGLDEVICECONTEXT_H__) /** @endcond */