mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-09-03 14:10:33 +03:00
0023226: Extend OpenGl_Context to store map of shared GPU resources
OpenGl_Resource was slightly corrected and OpenGl_Element was extended with Release method to manage GPU resources. OpenGl_PrimitiveArray now uses new OpenGl_VertexBuffer class (requires OpenGL 1.5+). Strange workarounds for feedback mode were removed. OpenGl_Context now provides access to shared GPU resources and manages resources queue for delayed release (replaces functionality of removed OpenGl_ResourceCleaner). Loaded GL_ARB_texture_buffer_object and GL_ARB_draw_instanced extensions. Global maps of views, workspaces and structures were moved to OpenGl_GraphicDriver members. UserDrawCallback() function moved to OpenGl_GraphicDriver methods. Aspect_GraphicCallbackStruct now holds handle of OpenGl_Context instead of system-dependent pointers to GL context definition. New classes NCollection_Vec2, NCollection_Vec3 and NCollection_Vec4 implements interface to low-level data (points, vertices, colors) in GLSL-style. Removed EnableVBO argument from vdrawparray Draw Harness command Corrected compilation errors Fixed wrong argument in Index VBO initialization Fixed several cases of incorrect memory management in TKV3d Visual3d_ViewManager::Remove() Destroy structures before last view removed for correct GPU resources management. Graphic3d_Structure::GraphicClear() Remove groups to avoid usage of dead OpenGl_Group pointers. V3d_View::Remove() Fixed mistake in #0000280 patch. Small correction Fixed OCC280 test command Replace removed view within created one in ViewerTest EventManager. ViewerTest, do not create unused 3D view In current design NIS_View always created and used for both - NIS objects and AIS objects.
This commit is contained in:
@@ -25,6 +25,11 @@
|
||||
#include <Aspect_Drawable.hxx>
|
||||
#include <Aspect_Display.hxx>
|
||||
#include <Aspect_RenderingContext.hxx>
|
||||
#include <Handle_OpenGl_Context.hxx>
|
||||
#include <NCollection_DataMap.hxx>
|
||||
#include <NCollection_Handle.hxx>
|
||||
#include <NCollection_Queue.hxx>
|
||||
#include <OpenGl_Resource.hxx>
|
||||
#include <Standard_Transient.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
#include <Handle_OpenGl_Context.hxx>
|
||||
@@ -36,6 +41,8 @@ struct OpenGl_GlCore14;
|
||||
struct OpenGl_GlCore15;
|
||||
struct OpenGl_GlCore20;
|
||||
struct OpenGl_ArbVBO;
|
||||
struct OpenGl_ArbTBO;
|
||||
struct OpenGl_ArbIns;
|
||||
struct OpenGl_ExtFBO;
|
||||
|
||||
//! This class generalize access to the GL context and available extensions.
|
||||
@@ -81,6 +88,10 @@ public:
|
||||
//! Destructor.
|
||||
Standard_EXPORT virtual ~OpenGl_Context();
|
||||
|
||||
//! Share GL context resources.
|
||||
//! theShareCtx - handle to context to retrieve handles to shared resources.
|
||||
Standard_EXPORT void Share (const Handle(OpenGl_Context)& theShareCtx);
|
||||
|
||||
//! Initialize available extensions.
|
||||
//! GL context should be active!
|
||||
Standard_EXPORT Standard_Boolean Init();
|
||||
@@ -130,6 +141,9 @@ public:
|
||||
//! Class should be initialized with appropriate info.
|
||||
Standard_EXPORT Standard_Boolean MakeCurrent();
|
||||
|
||||
//! Swap front/back buffers for this GL context (should be activated before!).
|
||||
Standard_EXPORT void SwapBuffers();
|
||||
|
||||
//! Return true if active mode is GL_FEEDBACK (cached state)
|
||||
Standard_EXPORT Standard_Boolean IsFeedback() const;
|
||||
|
||||
@@ -148,6 +162,53 @@ public:
|
||||
//! and contains more vendor-specific values than AvailableMemory().
|
||||
Standard_EXPORT TCollection_AsciiString MemoryInfo() const;
|
||||
|
||||
//! Access shared resource by its name.
|
||||
//! @param theKey - unique identifier;
|
||||
//! @return handle to shared resource or NULL.
|
||||
Standard_EXPORT const Handle(OpenGl_Resource)& GetResource (const TCollection_AsciiString& theKey) const;
|
||||
|
||||
//! Access shared resource by its name.
|
||||
//! @param theKey - unique identifier;
|
||||
//! @param theValue - handle to fill;
|
||||
//! @return true if resource was shared.
|
||||
template<typename TheHandleType>
|
||||
Standard_Boolean GetResource (const TCollection_AsciiString& theKey,
|
||||
TheHandleType& theValue) const
|
||||
{
|
||||
const Handle(OpenGl_Resource)& aResource = GetResource (theKey);
|
||||
if (aResource.IsNull())
|
||||
{
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
theValue = TheHandleType::DownCast (aResource);
|
||||
return !theValue.IsNull();
|
||||
}
|
||||
|
||||
//! Register shared resource.
|
||||
//! Notice that after registration caller shouldn't release it by himself -
|
||||
//! it will be automatically released on context destruction.
|
||||
//! @param theKey - unique identifier, shouldn't be empty;
|
||||
//! @param theResource - new resource to register, shouldn't be NULL.
|
||||
Standard_EXPORT Standard_Boolean ShareResource (const TCollection_AsciiString& theKey,
|
||||
const Handle(OpenGl_Resource)& theResource);
|
||||
|
||||
//! Release shared resource.
|
||||
//! If there are more than one reference to this resource
|
||||
//! (also used by some other existing object) then call will be ignored.
|
||||
//! This means that current object itself should nullify handle before this call.
|
||||
//! Notice that this is unrecommended operation at all and should be used
|
||||
//! only in case of fat resources to release memory for other needs.
|
||||
//! @param theKey - unique identifier.
|
||||
Standard_EXPORT void ReleaseResource (const TCollection_AsciiString& theKey);
|
||||
|
||||
//! 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);
|
||||
|
||||
//! Clean up the delayed release queue.
|
||||
Standard_EXPORT void ReleaseDelayed();
|
||||
|
||||
private:
|
||||
|
||||
//! Wrapper to system function to retrieve GL function pointer by name.
|
||||
@@ -170,11 +231,13 @@ public: // core profiles
|
||||
public: // extensions
|
||||
|
||||
OpenGl_ArbVBO* arbVBO; //!< GL_ARB_vertex_buffer_object
|
||||
OpenGl_ArbTBO* arbTBO; //!< GL_ARB_texture_buffer_object
|
||||
OpenGl_ArbIns* arbIns; //!< GL_ARB_draw_instanced
|
||||
OpenGl_ExtFBO* extFBO; //!< GL_EXT_framebuffer_object
|
||||
Standard_Boolean atiMem; //!< GL_ATI_meminfo
|
||||
Standard_Boolean nvxMem; //!< GL_NVX_gpu_memory_info
|
||||
|
||||
private:
|
||||
private: // system-dependent fields
|
||||
|
||||
#if (defined(_WIN32) || defined(__WIN32__))
|
||||
Aspect_Handle myWindow; //!< window handle (owner of GL context) : HWND
|
||||
@@ -186,6 +249,16 @@ private:
|
||||
Aspect_RenderingContext myGContext; //!< X-GLX rendering context : GLXContext
|
||||
#endif
|
||||
|
||||
private: // context info
|
||||
|
||||
typedef NCollection_DataMap<TCollection_AsciiString, Handle(OpenGl_Resource)> OpenGl_ResourcesMap;
|
||||
typedef NCollection_Handle<OpenGl_ResourcesMap> Handle(OpenGl_ResourcesMap);
|
||||
typedef NCollection_Queue<Handle(OpenGl_Resource)> OpenGl_ResourcesQueue;
|
||||
typedef NCollection_Handle<OpenGl_ResourcesQueue> Handle(OpenGl_ResourcesQueue);
|
||||
|
||||
Handle(OpenGl_ResourcesMap) mySharedResources; //!< shared resourced with unique identification key
|
||||
Handle(OpenGl_ResourcesQueue) myReleaseQueue; //!< queue of resources for delayed clean up
|
||||
|
||||
void* myGlLibHandle; //!< optional handle to GL library
|
||||
OpenGl_GlCore20* myGlCore20; //!< common structure for GL core functions upto 2.0
|
||||
Standard_Integer myGlVerMajor; //!< cached GL version major number
|
||||
@@ -193,10 +266,18 @@ private:
|
||||
Standard_Boolean myIsFeedback; //!< flag indicates GL_FEEDBACK mode
|
||||
Standard_Boolean myIsInitialized; //!< flag indicates initialization state
|
||||
|
||||
private:
|
||||
|
||||
//! Copying allowed only within Handles
|
||||
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__
|
||||
|
Reference in New Issue
Block a user