#define _OpenGl_Context_H__
#include <Aspect_Handle.hxx>
+#include <Aspect_HatchStyle.hxx>
#include <Aspect_Drawable.hxx>
#include <Aspect_Display.hxx>
#include <Aspect_RenderingContext.hxx>
-#include <Handle_OpenGl_Context.hxx>
-#include <Handle_OpenGl_Sampler.hxx>
-#include <Handle_OpenGl_ShaderManager.hxx>
-#include <Handle_OpenGl_ShaderProgram.hxx>
+#include <Aspect_TypeOfLine.hxx>
#include <NCollection_DataMap.hxx>
+#include <Graphic3d_DiagnosticInfo.hxx>
+#include <Graphic3d_TextureUnit.hxx>
#include <NCollection_Map.hxx>
#include <NCollection_Handle.hxx>
#include <NCollection_List.hxx>
+#include <NCollection_SparseArray.hxx>
#include <Message.hxx>
#include <OpenGl_Caps.hxx>
+#include <OpenGl_LineAttributes.hxx>
+#include <OpenGl_Material.hxx>
+#include <OpenGl_MatrixState.hxx>
#include <OpenGl_Vec.hxx>
#include <OpenGl_Resource.hxx>
+#include <OpenGl_TextureSet.hxx>
#include <Standard_Transient.hxx>
-#include <TCollection_AsciiString.hxx>
-#include <Handle_OpenGl_Context.hxx>
+#include <TColStd_IndexedDataMapOfStringString.hxx>
+#include <TColStd_PackedMapOfInteger.hxx>
#include <OpenGl_Clipping.hxx>
#include <OpenGl_GlCore11.hxx>
-#include <OpenGl_Utils.hxx>
+
+#include <NCollection_Shared.hxx>
//! Forward declarations
+#if defined(__APPLE__)
+ #import <TargetConditionals.h>
+ #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
+ #ifdef __OBJC__
+ @class EAGLContext;
+ #else
+ struct EAGLContext;
+ #endif
+ #else
+ #ifdef __OBJC__
+ @class NSOpenGLContext;
+ #else
+ struct NSOpenGLContext;
+ #endif
+ #endif
+#endif
+
struct OpenGl_GlFunctions;
struct OpenGl_ArbTBO;
struct OpenGl_ArbIns;
struct OpenGl_ArbDbg;
struct OpenGl_ArbFBO;
struct OpenGl_ArbFBOBlit;
-struct OpenGl_ExtGS;
+struct OpenGl_ArbSamplerObject;
struct OpenGl_ArbTexBindless;
+struct OpenGl_ExtGS;
template<typename theBaseClass_t> struct OpenGl_TmplCore12;
typedef OpenGl_TmplCore12<OpenGl_GlCore11> OpenGl_GlCore12;
typedef OpenGl_TmplCore44<OpenGl_GlCore43Back> OpenGl_GlCore44Back;
typedef OpenGl_TmplCore44<OpenGl_GlCore43> OpenGl_GlCore44;
+template<typename theBaseClass_t> struct OpenGl_TmplCore45;
+typedef OpenGl_TmplCore45<OpenGl_GlCore44Back> OpenGl_GlCore45Back;
+typedef OpenGl_TmplCore45<OpenGl_GlCore44> OpenGl_GlCore45;
+
+class Graphic3d_PresentationAttributes;
+class OpenGl_Aspects;
+class OpenGl_FrameBuffer;
+class OpenGl_Sampler;
+class OpenGl_ShaderProgram;
+class OpenGl_ShaderManager;
+class OpenGl_FrameStats;
+
+enum OpenGl_FeatureFlag
+{
+ OpenGl_FeatureNotAvailable = 0, //!< Feature is not supported by OpenGl implementation.
+ OpenGl_FeatureInExtensions = 1, //!< Feature is supported as extension.
+ OpenGl_FeatureInCore = 2 //!< Feature is supported as part of core profile.
+};
+
+DEFINE_STANDARD_HANDLE(OpenGl_Context, Standard_Transient)
+
//! This class generalize access to the GL context and available extensions.
//!
//! Functions related to specific OpenGL version or extension are grouped into structures which can be accessed as fields of this class.
//! For this reason OpenGl_Context should be initialized and used for each GL context independently.
class OpenGl_Context : public Standard_Transient
{
+ DEFINE_STANDARD_RTTIEXT(OpenGl_Context, Standard_Transient)
+ friend class OpenGl_Window;
public:
+ typedef NCollection_Shared< NCollection_DataMap<TCollection_AsciiString, Handle(OpenGl_Resource)> > OpenGl_ResourcesMap;
+
//! Function for getting power of to number larger or equal to input number.
//! @param theNumber number to 'power of two'
//! @param theThreshold upper threshold
}
#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
+ #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
+
+ //! Initialize class from specified OpenGL ES context (EAGLContext). Method should be called only once.
+ Standard_EXPORT Standard_Boolean Init (EAGLContext* theGContext,
+ const Standard_Boolean theIsCoreProfile = Standard_False);
+ #else
+
//! Initialize class from specified OpenGL context (NSOpenGLContext). Method should be called only once.
- Standard_EXPORT Standard_Boolean Init (const void* theGContext,
+ Standard_EXPORT Standard_Boolean Init (NSOpenGLContext* theGContext,
const Standard_Boolean theIsCoreProfile = Standard_False);
+ #endif
#else
+
//! Initialize class from specified window and rendering context. Method should be called only once.
//! @return false if OpenGL context can not be bound to specified window
Standard_EXPORT Standard_Boolean Init (const Aspect_Drawable theWindow,
//! Pointer to function retrieved from library is statically casted
//! to requested type - there no way to check real signature of exported function.
//! The context should be bound before call.
+ //! @param theLastFailFuncName [out] set to theFuncName in case of failure, unmodified on success
+ //! @param theFuncName [in] function name to find
+ //! @param theFuncPtr [out] retrieved function pointer
+ //! @return TRUE on success
+ template <typename FuncType_t>
+ Standard_Boolean FindProcVerbose (const char*& theLastFailFuncName,
+ const char* theFuncName,
+ FuncType_t& theFuncPtr)
+ {
+ theFuncPtr = (FuncType_t )findProc (theFuncName);
+ if (theFuncPtr == NULL)
+ {
+ theLastFailFuncName = theFuncName;
+ return Standard_False;
+ }
+ return Standard_True;
+ }
+
+ //! Auxiliary template to retrieve GL function pointer.
+ //! Same as FindProcVerbose() but without auxiliary last function name argument.
template <typename FuncType_t>
Standard_Boolean FindProc (const char* theFuncName,
FuncType_t& theFuncPtr)
|| (myGlVerMajor == theVerMajor && myGlVerMinor >= theVerMinor);
}
+ //! Return cached GL version major number.
+ Standard_Integer VersionMajor() const { return myGlVerMajor; }
+
+ //! Return cached GL version minor number.
+ Standard_Integer VersionMinor() const { return myGlVerMinor; }
+
+ //! Access entire map of loaded OpenGL functions.
+ const OpenGl_GlFunctions* Functions() const { return myFuncs.operator->(); }
+
//! Clean up errors stack for this GL context (glGetError() in loop).
- Standard_EXPORT void ResetErrors();
+ //! @return true if some error has been cleared
+ Standard_EXPORT bool ResetErrors (const bool theToPrintErrors = false);
//! This method uses system-dependent API to retrieve information
//! about GL context bound to the current thread.
//! Swap front/back buffers for this GL context (should be activated before!).
Standard_EXPORT void SwapBuffers();
+ //! Setup swap interval (VSync).
+ Standard_EXPORT Standard_Boolean SetSwapInterval (const Standard_Integer theInterval);
+
//! Return true if active mode is GL_RENDER (cached state)
Standard_Boolean IsRender() const
{
//! and contains more vendor-specific values than AvailableMemory().
Standard_EXPORT TCollection_AsciiString MemoryInfo() const;
+ //! This function retrieves information from GL about GPU memory.
+ Standard_EXPORT void MemoryInfo (TColStd_IndexedDataMapOfStringString& theDict) const;
+
+ //! Fill in the dictionary with OpenGL info.
+ //! Should be called with bound context.
+ Standard_EXPORT void DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict,
+ Graphic3d_DiagnosticInfo theFlags) const;
+
//! Access shared resource by its name.
//! @param theKey - unique identifier;
//! @return handle to shared resource or NULL.
//! Append resource to queue for delayed clean up.
//! Resources in this queue will be released at next redraw call.
- Standard_EXPORT void DelayedRelease (Handle(OpenGl_Resource)& theResource);
+ template <class T>
+ void DelayedRelease (Handle(T)& theResource)
+ {
+ myUnusedResources->Prepend (theResource);
+ theResource.Nullify();
+ }
//! Clean up the delayed release queue.
Standard_EXPORT void ReleaseDelayed();
+ //! Return map of shared resources.
+ const OpenGl_ResourcesMap& SharedResources() const { return *mySharedResources; }
+
//! @return tool for management of clippings within this context.
inline OpenGl_Clipping& ChangeClipping() { return myClippingState; }
Standard_Integer TextureWrapClamp() const { return myTexClamp; }
//! @return maximum degree of anisotropy texture filter
- Standard_EXPORT Standard_Integer MaxDegreeOfAnisotropy() const;
+ Standard_Integer MaxDegreeOfAnisotropy() const { return myAnisoMax; }
//! @return value for GL_MAX_TEXTURE_SIZE
- Standard_EXPORT Standard_Integer MaxTextureSize() const;
+ Standard_Integer MaxTextureSize() const { return myMaxTexDim; }
+
+ //! @return value for GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS
+ Standard_Integer MaxCombinedTextureUnits() const { return myMaxTexCombined; }
+
+ //! @return texture unit to be used for sprites
+ Graphic3d_TextureUnit SpriteTextureUnit() const { return mySpriteTexUnit; }
+
+ //! @return value for GL_MAX_SAMPLES
+ Standard_Integer MaxMsaaSamples() const { return myMaxMsaaSamples; }
+
+ //! @return maximum FBO width for image dump
+ Standard_Integer MaxDumpSizeX() const { return myMaxDumpSizeX; }
+
+ //! @return maximum FBO height for image dump
+ Standard_Integer MaxDumpSizeY() const { return myMaxDumpSizeY; }
+
+ //! @return value for GL_MAX_DRAW_BUFFERS
+ Standard_Integer MaxDrawBuffers() const { return myMaxDrawBuffers; }
+
+ //! @return value for GL_MAX_COLOR_ATTACHMENTS
+ Standard_Integer MaxColorAttachments() const { return myMaxColorAttachments; }
//! Get maximum number of clip planes supported by OpenGl.
//! This value is implementation dependent. At least 6
//! planes should be supported by OpenGl (see specs).
//! @return value for GL_MAX_CLIP_PLANES
- Standard_EXPORT Standard_Integer MaxClipPlanes() const;
+ Standard_Integer MaxClipPlanes() const { return myMaxClipPlanes; }
+
+ //! @return TRUE if ray tracing mode is supported
+ Standard_Boolean HasRayTracing() const { return myHasRayTracing; }
+
+ //! @return TRUE if textures in ray tracing mode are supported
+ Standard_Boolean HasRayTracingTextures() const { return myHasRayTracingTextures; }
+
+ //! @return TRUE if adaptive screen sampling in ray tracing mode is supported
+ Standard_Boolean HasRayTracingAdaptiveSampling() const { return myHasRayTracingAdaptiveSampling; }
+
+ //! @return TRUE if atomic adaptive screen sampling in ray tracing mode is supported
+ Standard_Boolean HasRayTracingAdaptiveSamplingAtomic() const { return myHasRayTracingAdaptiveSamplingAtomic; }
//! Returns true if VBO is supported and permitted.
inline bool ToUseVbo() const
//! @return old value of the flag
Standard_EXPORT Standard_Boolean SetGlNormalizeEnabled (Standard_Boolean isEnabled);
+ //! @return cached state of polygon rasterization mode (glPolygonMode()).
+ Standard_Integer PolygonMode() const { return myPolygonMode; }
+
+ //! Sets polygon rasterization mode (glPolygonMode() function).
+ //! @return old value of the rasterization mode.
+ Standard_EXPORT Standard_Integer SetPolygonMode (const Standard_Integer theMode);
+
+ //! @return cached enabled state of polygon hatching rasterization.
+ bool IsPolygonHatchEnabled() const
+ {
+ return !myHatchStyles.IsNull() && myHatchStyles->TypeOfHatch() != 0;
+ }
+
+ //! Sets enabled state of polygon hatching rasterization
+ //! without affecting currently selected hatching pattern.
+ //! @return previous state of polygon hatching mode.
+ Standard_EXPORT bool SetPolygonHatchEnabled (const bool theIsEnabled);
+
+ //! @return cached state of polygon hatch type.
+ Standard_Integer PolygonHatchStyle() const
+ {
+ return myHatchStyles.IsNull() ? Aspect_HS_SOLID : myHatchStyles->TypeOfHatch();
+ }
+
+ //! Sets polygon hatch pattern.
+ //! Zero-index value is a default alias for solid filling.
+ //! @param the type of hatch supported by base implementation of
+ //! OpenGl_LineAttributes (Aspect_HatchStyle) or the type supported by custom
+ //! implementation derived from OpenGl_LineAttributes class.
+ //! @return old type of hatch.
+ Standard_EXPORT Standard_Integer SetPolygonHatchStyle (const Handle(Graphic3d_HatchStyle)& theStyle);
+
+ //! Sets and applies current polygon offset.
+ Standard_EXPORT void SetPolygonOffset (const Graphic3d_PolygonOffset& theOffset);
+
+ //! Returns currently applied polygon offset parameters.
+ const Graphic3d_PolygonOffset& PolygonOffset() const { return myPolygonOffset; }
+
//! Applies matrix stored in ModelWorldState to OpenGl.
- void ApplyModelWorldMatrix();
+ Standard_EXPORT void ApplyModelWorldMatrix();
//! Applies matrix stored in WorldViewState to OpenGl.
- void ApplyWorldViewMatrix();
+ Standard_EXPORT void ApplyWorldViewMatrix();
//! Applies combination of matrices stored in ModelWorldState and WorldViewState to OpenGl.
- void ApplyModelViewMatrix();
+ Standard_EXPORT void ApplyModelViewMatrix();
//! Applies matrix stored in ProjectionState to OpenGl.
- void ApplyProjectionMatrix();
+ Standard_EXPORT void ApplyProjectionMatrix();
public:
const unsigned int theSeverity,
const TCollection_ExtendedString& theMessage);
+ //! Adds a filter for messages with theId and theSource (GL_DEBUG_SOURCE_)
+ Standard_EXPORT Standard_Boolean ExcludeMessage (const unsigned int theSource,
+ const unsigned int theId);
+ //! Removes a filter for messages with theId and theSource (GL_DEBUG_SOURCE_)
+ Standard_EXPORT Standard_Boolean IncludeMessage (const unsigned int theSource,
+ const unsigned int theId);
//! @return true if OpenGl context supports left and
//! right rendering buffers.
public: //! @name methods to alter or retrieve current state
- //! Switch to left stereographic rendering buffer.
- //! This method can be used to keep unchanged choise
- //! of front/back/both buffer rendering.
- Standard_EXPORT void SetDrawBufferLeft();
+ //! Return structure holding frame statistics.
+ const Handle(OpenGl_FrameStats)& FrameStats() const { return myFrameStats; }
+
+ //! Set structure holding frame statistics.
+ //! This call makes sense only if application defines OpenGl_FrameStats sub-class.
+ void SetFrameStats (const Handle(OpenGl_FrameStats)& theStats) { myFrameStats = theStats; }
+
+ //! Return cached viewport definition (x, y, width, height).
+ const Standard_Integer* Viewport() const { return myViewport; }
+
+ //! Resize the viewport (alias for glViewport).
+ //! @param theRect viewport definition (x, y, width, height)
+ Standard_EXPORT void ResizeViewport (const Standard_Integer theRect[4]);
- //! Switch to right stereographic rendering buffer.
- //! This method can be used to keep unchanged choise
- //! of front/back/both buffer rendering.
- Standard_EXPORT void SetDrawBufferRight();
+ //! Return virtual viewport definition (x, y, width, height).
+ const Standard_Integer* VirtualViewport() const { return myViewportVirt; }
- //! Switch to non-stereographic rendering buffer.
- //! This method can be used to keep unchanged choise
- //! of front/back/both buffer rendering.
- Standard_EXPORT void SetDrawBufferMono();
+ //! Return active read buffer.
+ Standard_Integer ReadBuffer() { return myReadBuffer; }
+
+ //! Switch read buffer, wrapper for ::glReadBuffer().
+ Standard_EXPORT void SetReadBuffer (const Standard_Integer theReadBuffer);
+
+ //! Return active draw buffer attached to a render target referred by index (layout location).
+ Standard_Integer DrawBuffer (Standard_Integer theIndex = 0) const
+ {
+ return theIndex >= myDrawBuffers.Lower()
+ && theIndex <= myDrawBuffers.Upper()
+ ? myDrawBuffers.Value (theIndex)
+ : GL_NONE;
+ }
+
+ //! Switch draw buffer, wrapper for ::glDrawBuffer().
+ Standard_EXPORT void SetDrawBuffer (const Standard_Integer theDrawBuffer);
+
+ //! Switch draw buffer, wrapper for ::glDrawBuffers (GLsizei, const GLenum*).
+ Standard_EXPORT void SetDrawBuffers (const Standard_Integer theNb, const Standard_Integer* theDrawBuffers);
+
+ //! Switch read/draw buffers.
+ void SetReadDrawBuffer (const Standard_Integer theBuffer)
+ {
+ SetReadBuffer (theBuffer);
+ SetDrawBuffer (theBuffer);
+ }
+
+ //! Return cached flag indicating writing into color buffer is enabled or disabled (glColorMask).
+ bool ColorMask() const { return myColorMask; }
+
+ //! Enable/disable writing into color buffer (wrapper for glColorMask).
+ Standard_EXPORT bool SetColorMask (bool theToWriteColor);
+
+ //! Return TRUE if GL_SAMPLE_ALPHA_TO_COVERAGE usage is allowed.
+ bool AllowSampleAlphaToCoverage() const { return myAllowAlphaToCov; }
+
+ //! Allow GL_SAMPLE_ALPHA_TO_COVERAGE usage.
+ void SetAllowSampleAlphaToCoverage (bool theToEnable) { myAllowAlphaToCov = theToEnable; }
+
+ //! Return GL_SAMPLE_ALPHA_TO_COVERAGE state.
+ bool SampleAlphaToCoverage() const { return myAlphaToCoverage; }
+
+ //! Enable/disable GL_SAMPLE_ALPHA_TO_COVERAGE.
+ Standard_EXPORT bool SetSampleAlphaToCoverage (bool theToEnable);
+
+ //! Return back face culling state.
+ bool ToCullBackFaces() const { return myToCullBackFaces; }
+
+ //! Enable or disable back face culling (glEnable (GL_CULL_FACE)).
+ Standard_EXPORT void SetCullBackFaces (bool theToEnable);
//! Fetch OpenGl context state. This class tracks value of several OpenGl
//! state variables. Consulting the cached values is quicker than
//! OpenGl state variables has a possibility of being out-of-date.
Standard_EXPORT void FetchState();
+ //! @return active textures
+ const Handle(OpenGl_TextureSet)& ActiveTextures() const { return myActiveTextures; }
+
+ //! Bind specified texture set to current context,
+ //! or unbind previous one when NULL specified.
+ Standard_EXPORT Handle(OpenGl_TextureSet) BindTextures (const Handle(OpenGl_TextureSet)& theTextures);
+
//! @return active GLSL program
const Handle(OpenGl_ShaderProgram)& ActiveProgram() const
{
return myActiveProgram;
}
- //! @return OpenGL sampler object used to override default texture parameters
- const Handle(OpenGl_Sampler)& TextureSampler()
- {
- return myTexSampler;
- }
-
//! Bind specified program to current context,
//! or unbind previous one when NULL specified.
//! @return true if some program is bound to context
Standard_EXPORT Standard_Boolean BindProgram (const Handle(OpenGl_ShaderProgram)& theProgram);
+ //! Setup current shading material.
+ Standard_EXPORT void SetShadingMaterial (const OpenGl_Aspects* theAspect,
+ const Handle(Graphic3d_PresentationAttributes)& theHighlight);
+
+ //! Checks if transparency is required for the given aspect and highlight style.
+ Standard_EXPORT static Standard_Boolean CheckIsTransparent (const OpenGl_Aspects* theAspect,
+ const Handle(Graphic3d_PresentationAttributes)& theHighlight,
+ Standard_ShortReal& theAlphaFront,
+ Standard_ShortReal& theAlphaBack);
+
+ //! Checks if transparency is required for the given aspect and highlight style.
+ static Standard_Boolean CheckIsTransparent (const OpenGl_Aspects* theAspect,
+ const Handle(Graphic3d_PresentationAttributes)& theHighlight)
+ {
+ Standard_ShortReal anAlphaFront = 1.0f, anAlphaBack = 1.0f;
+ return CheckIsTransparent (theAspect, theHighlight, anAlphaFront, anAlphaBack);
+ }
+
//! Setup current color.
Standard_EXPORT void SetColor4fv (const OpenGl_Vec4& theColor);
+ //! Setup type of line.
+ Standard_EXPORT void SetTypeOfLine (const Aspect_TypeOfLine theType,
+ const Standard_ShortReal theFactor = 1.0f);
+
+ //! Setup width of line.
+ Standard_EXPORT void SetLineWidth (const Standard_ShortReal theWidth);
+
//! Setup point size.
Standard_EXPORT void SetPointSize (const Standard_ShortReal theSize);
+ //! Setup point sprite origin using GL_POINT_SPRITE_COORD_ORIGIN state:
+ //! - GL_UPPER_LEFT when GLSL program is active;
+ //! flipping should be handled in GLSL program for compatibility with OpenGL ES
+ //! - GL_LOWER_LEFT for FFP
+ Standard_EXPORT void SetPointSpriteOrigin();
+
+ //! Setup texture matrix to active GLSL program or to FFP global state using glMatrixMode (GL_TEXTURE).
+ Standard_EXPORT void SetTextureMatrix (const Handle(Graphic3d_TextureParams)& theParams);
+
//! Bind default Vertex Array Object
Standard_EXPORT void BindDefaultVao();
+ //! Default Frame Buffer Object.
+ const Handle(OpenGl_FrameBuffer)& DefaultFrameBuffer() const
+ {
+ return myDefaultFbo;
+ }
+
+ //! Setup new Default Frame Buffer Object and return previously set.
+ //! This call doesn't change Active FBO!
+ Standard_EXPORT Handle(OpenGl_FrameBuffer) SetDefaultFrameBuffer (const Handle(OpenGl_FrameBuffer)& theFbo);
+
//! Return debug context initialization state.
Standard_Boolean IsDebugContext() const
{
return myIsGlDebugCtx;
}
+ Standard_EXPORT void EnableFeatures() const;
+
+ Standard_EXPORT void DisableFeatures() const;
+
+ //! Return resolution for rendering text.
+ unsigned int Resolution() const { return myResolution; }
+
+ //! Resolution scale factor (rendered resolution to standard resolution).
+ //! This scaling factor for parameters like text size to be properly displayed on device (screen / printer).
+ Standard_ShortReal ResolutionRatio() const { return myResolutionRatio; }
+
+ //! Rendering scale factor (rendering viewport height to real window buffer height).
+ Standard_ShortReal RenderScale() const { return myRenderScale; }
+
+ //! Return TRUE if rendering scale factor is not 1.
+ Standard_Boolean HasRenderScale() const { return Abs (myRenderScale - 1.0f) > 0.0001f; }
+
+ //! Rendering scale factor (inverted value).
+ Standard_ShortReal RenderScaleInv() const { return myRenderScaleInv; }
+
+ //! Return scale factor for line width.
+ Standard_ShortReal LineWidthScale() const { return myLineWidthScale; }
+
+ //! Set resolution ratio.
+ //! Note that this method rounds @theRatio to nearest integer.
+ void SetResolution (unsigned int theResolution,
+ Standard_ShortReal theRatio,
+ Standard_ShortReal theScale)
+ {
+ myResolution = (unsigned int )(theScale * theResolution + 0.5f);
+ myRenderScale = theScale;
+ myRenderScaleInv = 1.0f / theScale;
+ SetResolutionRatio (theRatio * theScale);
+ }
+
+ //! Set resolution ratio.
+ //! Note that this method rounds @theRatio to nearest integer.
+ void SetResolutionRatio (const Standard_ShortReal theRatio)
+ {
+ myResolutionRatio = theRatio;
+ myLineWidthScale = Max (1.0f, std::floor (theRatio + 0.5f));
+ }
+
+ //! Return line feater width in pixels.
+ Standard_ShortReal LineFeather() const { return myLineFeather; }
+
+ //! Set line feater width.
+ void SetLineFeather(Standard_ShortReal theValue) { myLineFeather = theValue; }
+
+ //! Return Graphics Driver's vendor.
+ const TCollection_AsciiString& Vendor() const { return myVendor; }
+
private:
//! Wrapper to system function to retrieve GL function pointer by name.
Standard_EXPORT void* findProc (const char* theFuncName);
+ //! Print error if not all functions have been exported by context for reported version.
+ //! Note that this will never happen when using GLX, since returned functions can not be validated.
+ //! @param theGlVerMajor the OpenGL major version with missing functions
+ //! @param theGlVerMinor the OpenGL minor version with missing functions
+ //! @param theLastFailedProc function name which cannot be found
+ Standard_EXPORT void checkWrongVersion (Standard_Integer theGlVerMajor, Standard_Integer theGlVerMinor,
+ const char* theLastFailedProc);
+
//! Private initialization function that should be called only once.
Standard_EXPORT void init (const Standard_Boolean theIsCoreProfile);
OpenGl_GlCore43Back* core43back; //!< OpenGL 4.3 backward compatibility profile
OpenGl_GlCore44* core44; //!< OpenGL 4.4 core profile
OpenGl_GlCore44Back* core44back; //!< OpenGL 4.4 backward compatibility profile
+ OpenGl_GlCore45* core45; //!< OpenGL 4.5 core profile
+ OpenGl_GlCore45Back* core45back; //!< OpenGL 4.5 backward compatibility profile
Handle(OpenGl_Caps) caps; //!< context options
public: //! @name extensions
- Standard_Boolean hasHighp; //!< highp in GLSL ES fragment shader is supported
- Standard_Boolean hasTexRGBA8; //!< always available on desktop; on OpenGL ES - since 3.0 or as extension GL_OES_rgb8_rgba8
- Standard_Boolean arbNPTW; //!< GL_ARB_texture_non_power_of_two
- Standard_Boolean arbTexRG; //!< GL_ARB_texture_rg
- OpenGl_ArbTexBindless* arbTexBindless; //!< GL_ARB_bindless_texture
- OpenGl_ArbTBO* arbTBO; //!< GL_ARB_texture_buffer_object
- Standard_Boolean arbTboRGB32; //!< GL_ARB_texture_buffer_object_rgb32 (3-component TBO), in core since 4.0
- OpenGl_ArbIns* arbIns; //!< GL_ARB_draw_instanced
- OpenGl_ArbDbg* arbDbg; //!< GL_ARB_debug_output
- OpenGl_ArbFBO* arbFBO; //!< GL_ARB_framebuffer_object
- OpenGl_ArbFBOBlit* arbFBOBlit; //!< glBlitFramebuffer function, moved out from OpenGl_ArbFBO structure for compatibility with OpenGL ES 2.0
- OpenGl_ExtGS* extGS; //!< GL_EXT_geometry_shader4
- Standard_Boolean extBgra; //!< GL_EXT_bgra or GL_EXT_texture_format_BGRA8888 on OpenGL ES
- Standard_Boolean extAnis; //!< GL_EXT_texture_filter_anisotropic
- Standard_Boolean extPDS; //!< GL_EXT_packed_depth_stencil
- Standard_Boolean atiMem; //!< GL_ATI_meminfo
- Standard_Boolean nvxMem; //!< GL_NVX_gpu_memory_info
+ Standard_Boolean hasHighp; //!< highp in GLSL ES fragment shader is supported
+ Standard_Boolean hasUintIndex; //!< GLuint for index buffer is supported (always available on desktop; on OpenGL ES - since 3.0 or as extension GL_OES_element_index_uint)
+ Standard_Boolean hasTexRGBA8; //!< always available on desktop; on OpenGL ES - since 3.0 or as extension GL_OES_rgb8_rgba8
+ OpenGl_FeatureFlag hasFlatShading; //!< Complex flag indicating support of Flat shading (Graphic3d_TOSM_FACET) (always available on desktop; on OpenGL ES - since 3.0 or as extension GL_OES_standard_derivatives)
+ OpenGl_FeatureFlag hasDrawBuffers; //!< Complex flag indicating support of multiple draw buffers (desktop OpenGL 2.0, OpenGL ES 3.0, GL_ARB_draw_buffers, GL_EXT_draw_buffers)
+ OpenGl_FeatureFlag hasFloatBuffer; //!< Complex flag indicating support of float color buffer format (desktop OpenGL 3.0, GL_ARB_color_buffer_float, GL_EXT_color_buffer_float)
+ OpenGl_FeatureFlag hasHalfFloatBuffer; //!< Complex flag indicating support of half-float color buffer format (desktop OpenGL 3.0, GL_ARB_color_buffer_float, GL_EXT_color_buffer_half_float)
+ OpenGl_FeatureFlag hasSampleVariables; //!< Complex flag indicating support of MSAA variables in GLSL shader (desktop OpenGL 4.0, GL_ARB_sample_shading)
+ OpenGl_FeatureFlag hasGeometryStage; //!< Complex flag indicating support of Geometry shader (desktop OpenGL 3.2, OpenGL ES 3.2, GL_EXT_geometry_shader)
+ Standard_Boolean arbDrawBuffers; //!< GL_ARB_draw_buffers
+ Standard_Boolean arbNPTW; //!< GL_ARB_texture_non_power_of_two
+ Standard_Boolean arbTexRG; //!< GL_ARB_texture_rg
+ Standard_Boolean arbTexFloat; //!< GL_ARB_texture_float (on desktop OpenGL - since 3.0 or as extension GL_ARB_texture_float; on OpenGL ES - since 3.0)
+ OpenGl_ArbSamplerObject* arbSamplerObject; //!< GL_ARB_sampler_objects (on desktop OpenGL - since 3.3 or as extension GL_ARB_sampler_objects; on OpenGL ES - since 3.0)
+ OpenGl_ArbTexBindless* arbTexBindless; //!< GL_ARB_bindless_texture
+ OpenGl_ArbTBO* arbTBO; //!< GL_ARB_texture_buffer_object
+ Standard_Boolean arbTboRGB32; //!< GL_ARB_texture_buffer_object_rgb32 (3-component TBO), in core since 4.0
+ OpenGl_ArbIns* arbIns; //!< GL_ARB_draw_instanced
+ OpenGl_ArbDbg* arbDbg; //!< GL_ARB_debug_output
+ OpenGl_ArbFBO* arbFBO; //!< GL_ARB_framebuffer_object
+ OpenGl_ArbFBOBlit* arbFBOBlit; //!< glBlitFramebuffer function, moved out from OpenGl_ArbFBO structure for compatibility with OpenGL ES 2.0
+ Standard_Boolean arbSampleShading; //!< GL_ARB_sample_shading
+ Standard_Boolean extFragDepth; //!< GL_EXT_frag_depth on OpenGL ES 2.0 (gl_FragDepthEXT built-in variable, before OpenGL ES 3.0)
+ Standard_Boolean extDrawBuffers; //!< GL_EXT_draw_buffers
+ OpenGl_ExtGS* extGS; //!< GL_EXT_geometry_shader4
+ Standard_Boolean extBgra; //!< GL_EXT_bgra or GL_EXT_texture_format_BGRA8888 on OpenGL ES
+ Standard_Boolean extAnis; //!< GL_EXT_texture_filter_anisotropic
+ Standard_Boolean extPDS; //!< GL_EXT_packed_depth_stencil
+ Standard_Boolean atiMem; //!< GL_ATI_meminfo
+ Standard_Boolean nvxMem; //!< GL_NVX_gpu_memory_info
+ Standard_Boolean oesSampleVariables; //!< GL_OES_sample_variables
+ Standard_Boolean oesStdDerivatives; //!< GL_OES_standard_derivatives
+
+public: //! @name public properties tracking current state
+
+ OpenGl_MatrixState<Standard_ShortReal> ModelWorldState; //!< state of orientation matrix
+ OpenGl_MatrixState<Standard_ShortReal> WorldViewState; //!< state of orientation matrix
+ OpenGl_MatrixState<Standard_ShortReal> ProjectionState; //!< state of projection matrix
private: // system-dependent fields
Aspect_Handle myWindowDC; //!< Device Descriptor handle : HDC
Aspect_RenderingContext myGContext; //!< Rendering Context handle : HGLRC
#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
- void* myGContext; //!< Rendering Context handle : NSOpenGLContext
+ #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
+ EAGLContext* myGContext; //!< Rendering Context handle
+ #else
+ NSOpenGLContext* myGContext; //!< Rendering Context handle
+ #endif
#else
Aspect_Drawable myWindow; //!< window handle (owner of GL context) : GLXDrawable
Aspect_Display myDisplay; //!< connection to the X-server : Display*
private: // context info
- typedef NCollection_DataMap<TCollection_AsciiString, Standard_Integer> OpenGl_DelayReleaseMap;
- typedef NCollection_Handle<OpenGl_DelayReleaseMap> Handle(OpenGl_DelayReleaseMap);
- typedef NCollection_DataMap<TCollection_AsciiString, Handle(OpenGl_Resource)> OpenGl_ResourcesMap;
- typedef NCollection_Handle<OpenGl_ResourcesMap> Handle(OpenGl_ResourcesMap);
- typedef NCollection_List<Handle(OpenGl_Resource)> OpenGl_ResourcesStack;
- typedef NCollection_Handle<OpenGl_ResourcesStack> Handle(OpenGl_ResourcesStack);
+ typedef NCollection_Shared< NCollection_DataMap<TCollection_AsciiString, Standard_Integer> > OpenGl_DelayReleaseMap;
+ typedef NCollection_Shared< NCollection_List<Handle(OpenGl_Resource)> > OpenGl_ResourcesStack;
Handle(OpenGl_ResourcesMap) mySharedResources; //!< shared resources with unique identification key
Handle(OpenGl_DelayReleaseMap) myDelayed; //!< shared resources for delayed release
Standard_Integer myAnisoMax; //!< maximum level of anisotropy texture filter
Standard_Integer myTexClamp; //!< either GL_CLAMP_TO_EDGE (1.2+) or GL_CLAMP (1.1)
Standard_Integer myMaxTexDim; //!< value for GL_MAX_TEXTURE_SIZE
+ Standard_Integer myMaxTexCombined; //!< value for GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS
+ Standard_Integer myMaxDumpSizeX; //!< maximum FBO width for image dump
+ Standard_Integer myMaxDumpSizeY; //!< maximum FBO height for image dump
Standard_Integer myMaxClipPlanes; //!< value for GL_MAX_CLIP_PLANES
+ Standard_Integer myMaxMsaaSamples; //!< value for GL_MAX_SAMPLES
+ Standard_Integer myMaxDrawBuffers; //!< value for GL_MAX_DRAW_BUFFERS
+ Standard_Integer myMaxColorAttachments; //!< value for GL_MAX_COLOR_ATTACHMENTS
Standard_Integer myGlVerMajor; //!< cached GL version major number
Standard_Integer myGlVerMinor; //!< cached GL version minor number
Standard_Boolean myIsInitialized; //!< flag indicates initialization state
Standard_Boolean myIsStereoBuffers; //!< context supports stereo buffering
Standard_Boolean myIsGlNormalizeEnabled; //!< GL_NORMALIZE flag
//!< Used to tell OpenGl that normals should be normalized
+ Graphic3d_TextureUnit mySpriteTexUnit; //!< texture unit for point sprite texture
+
+ Standard_Boolean myHasRayTracing; //! indicates whether ray tracing mode is supported
+ Standard_Boolean myHasRayTracingTextures; //! indicates whether textures in ray tracing mode are supported
+ Standard_Boolean myHasRayTracingAdaptiveSampling; //! indicates whether adaptive screen sampling in ray tracing mode is supported
+ Standard_Boolean myHasRayTracingAdaptiveSamplingAtomic; //! indicates whether atomic adaptive screen sampling in ray tracing mode is supported
Handle(OpenGl_ShaderManager) myShaderManager; //! support object for managing shader programs
private: //! @name fields tracking current state
- Handle(OpenGl_ShaderProgram) myActiveProgram; //!< currently active GLSL program
- Handle(OpenGl_Sampler) myTexSampler; //!< currently active sampler object
- Standard_Integer myRenderMode; //!< value for active rendering mode
- Standard_Integer myDrawBuffer; //!< current draw buffer
- unsigned int myDefaultVao; //!< default Vertex Array Object
- Standard_Boolean myIsGlDebugCtx; //!< debug context initialization state
-
-public:
-
- OpenGl_Utils::MatrixState<Standard_ShortReal> ModelWorldState; //!< state of orientation matrix
- OpenGl_Utils::MatrixState<Standard_ShortReal> WorldViewState; //!< state of orientation matrix
- OpenGl_Utils::MatrixState<Standard_ShortReal> ProjectionState; //!< state of projection matrix
+ Handle(OpenGl_FrameStats) myFrameStats; //!< structure accumulating frame statistics
+ Handle(OpenGl_ShaderProgram) myActiveProgram; //!< currently active GLSL program
+ Handle(OpenGl_TextureSet) myActiveTextures; //!< currently bound textures
+ //!< currently active sampler objects
+ Handle(OpenGl_FrameBuffer) myDefaultFbo; //!< default Frame Buffer Object
+ Handle(OpenGl_LineAttributes) myHatchStyles; //!< resource holding predefined hatch styles patterns
+ Standard_Integer myViewport[4]; //!< current viewport
+ Standard_Integer myViewportVirt[4]; //!< virtual viewport
+ Standard_Integer myPointSpriteOrig; //!< GL_POINT_SPRITE_COORD_ORIGIN state (GL_UPPER_LEFT by default)
+ Standard_Integer myRenderMode; //!< value for active rendering mode
+ Standard_Integer myPolygonMode; //!< currently used polygon rasterization mode (glPolygonMode)
+ Graphic3d_PolygonOffset myPolygonOffset; //!< currently applied polygon offset
+ bool myToCullBackFaces; //!< back face culling mode enabled state (glIsEnabled (GL_CULL_FACE))
+ Standard_Integer myReadBuffer; //!< current read buffer
+ NCollection_Array1<Standard_Integer>
+ myDrawBuffers; //!< current draw buffers
+ unsigned int myDefaultVao; //!< default Vertex Array Object
+ Standard_Boolean myColorMask; //!< flag indicating writing into color buffer is enabled or disabled (glColorMask)
+ Standard_Boolean myAllowAlphaToCov; //!< flag allowing GL_SAMPLE_ALPHA_TO_COVERAGE usage
+ Standard_Boolean myAlphaToCoverage; //!< flag indicating GL_SAMPLE_ALPHA_TO_COVERAGE state
+ Standard_Boolean myIsGlDebugCtx; //!< debug context initialization state
+ TCollection_AsciiString myVendor; //!< Graphics Driver's vendor
+ TColStd_PackedMapOfInteger myFilters[6]; //!< messages suppressing filter (for sources from GL_DEBUG_SOURCE_API_ARB to GL_DEBUG_SOURCE_OTHER_ARB)
+ unsigned int myResolution; //!< Pixels density (PPI), defines scaling factor for parameters like text size
+ Standard_ShortReal myResolutionRatio; //!< scaling factor for parameters like text size
+ //! to be properly displayed on device (screen / printer)
+ Standard_ShortReal myLineWidthScale; //!< scaling factor for line width
+ Standard_ShortReal myLineFeather; //!< line feater width in pixels
+ Standard_ShortReal myRenderScale; //!< scaling factor for rendering resolution
+ Standard_ShortReal myRenderScaleInv; //!< scaling factor for rendering resolution (inverted value)
+ OpenGl_Material myMatFront; //!< current front material state (cached to reduce GL context updates)
+ OpenGl_Material myMatBack; //!< current back material state
private:
OpenGl_Context (const OpenGl_Context& );
OpenGl_Context& operator= (const OpenGl_Context& );
-public:
-
- DEFINE_STANDARD_RTTI(OpenGl_Context) // Type definition
-
- friend class OpenGl_Window;
-
};
#endif // _OpenGl_Context_H__