1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +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:
kgv
2012-07-13 15:51:16 +04:00
parent 400933675f
commit 5e27df788d
74 changed files with 3005 additions and 1593 deletions

View File

@@ -3251,10 +3251,10 @@ static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char*
}
else if (argc < 3)
{
di << "Use: " << argv[0] << " Name TypeOfArray [EnableVBO={0 | 1}]"
di << "Use: " << argv[0] << " Name TypeOfArray"
<< " [vertex] ... [bounds] ... [edges]\n"
<< " TypeOfArray={ points | segments | polylines | triangles |\n"
<< " trianglefan | trianglestrips | quads |\n"
<< " trianglefans | trianglestrips | quads |\n"
<< " quadstrips | polygons }\n"
<< " vertex={ 'v' x y z [normal={ 'n' nx ny nz }] [color={ 'c' r g b }]"
<< " [texel={ 't' tx ty }] } \n"
@@ -3264,20 +3264,16 @@ static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char*
}
// read the arguments
TCollection_AsciiString aName (argv[1]);
TCollection_AsciiString anArrayType (argv[2]);
// is argument list has an vbo flag
Standard_Boolean hasFlagVbo = Standard_False;
if (isdigit (argv[3][0]) && atoi (argv[3]) >= 0 && atoi (argv[3]) <= 1)
hasFlagVbo = Standard_True;
Standard_Integer aArgIndex = 1;
TCollection_AsciiString aName (argv[aArgIndex++]);
TCollection_AsciiString anArrayType (argv[aArgIndex++]);
const Standard_Integer anArgsFrom = aArgIndex;
// parse number of verticies, bounds, edges
Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
Standard_Boolean hasVColors, hasBColors, hasNormals, hasInfos, hasTexels;
hasVColors = hasNormals = hasBColors = hasInfos = hasTexels = Standard_False;
Standard_Integer aArgIndex = (hasFlagVbo) ? 4 : 3;
TCollection_AsciiString aCommand;
while (aArgIndex < argc)
{
@@ -3375,7 +3371,7 @@ static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char*
}
// parse an array of primitives
aArgIndex = (hasFlagVbo) ? 4 : 3;
aArgIndex = anArgsFrom;
while (aArgIndex < argc)
{
aCommand = argv[aArgIndex];
@@ -3438,17 +3434,6 @@ static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char*
aArgIndex++;
}
if (hasFlagVbo)
{
// enable / disable vbo
Handle(Graphic3d_GraphicDriver) aDriver =
Handle(Graphic3d_GraphicDriver)::DownCast (
aContextAIS->CurrentViewer()->Device()->GraphicDriver());
if (!aDriver.IsNull())
aDriver->EnableVBO ((Standard_Boolean) atoi (argv[3]));
}
// create primitives array object
Handle (MyPArrayObject) aPObject = new MyPArrayObject (anArray);
@@ -4379,7 +4364,7 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
__FILE__, VComputeHLR, group);
theCommands.Add("vdrawparray",
"vdrawparray : vdrawparray Name TypeOfArray [EnableVbo=1] [vertex = { 'v' x y z [vertex_normal = { 'n' x y z }] [vertex_color = { 'c' r g b }] ] ... [bound = { 'b' vertex_count [bound_color = { 'c' r g b }] ] ... [edge = { 'e' vertex_id [edge_hidden = { 'h' }] ]",
"vdrawparray : vdrawparray Name TypeOfArray [vertex = { 'v' x y z [vertex_normal = { 'n' x y z }] [vertex_color = { 'c' r g b }] ] ... [bound = { 'b' vertex_count [bound_color = { 'c' r g b }] ] ... [edge = { 'e' vertex_id [edge_hidden = { 'h' }] ]",
__FILE__,VDrawPArray,group);
theCommands.Add("vconnect",

View File

@@ -23,6 +23,8 @@
#include <ViewerTest.hxx>
#include <Aspect_GraphicDevice.hxx>
#include <AIS_InteractiveContext.hxx>
#include <AIS_InteractiveObject.hxx>
#include <Draw.hxx>
#include <Draw_Interpretor.hxx>
@@ -32,20 +34,18 @@
#include <OpenGl_AspectLine.hxx>
#include <OpenGl_AspectMarker.hxx>
#include <OpenGl_AspectText.hxx>
#include <OpenGl_Callback.hxx>
#include <OpenGl_Context.hxx>
#include <OpenGl_Element.hxx>
#include <OpenGl_ExtFBO.hxx>
#include <OpenGl_GlCore20.hxx>
#include <OpenGl_ResourceCleaner.hxx>
#include <OpenGl_ResourceTexture.hxx>
#include <OpenGl_ResourceVBO.hxx>
#include <OpenGl_GraphicDriver.hxx>
#include <OpenGl_Workspace.hxx>
#include <Prs3d_Presentation.hxx>
#include <Prs3d_Root.hxx>
#include <Select3D_SensitiveCurve.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_Selection.hxx>
#include <V3d_Viewer.hxx>
#include <TCollection_AsciiString.hxx>
#include <V3d_View.hxx>
@@ -100,6 +100,11 @@ public:
myIObj->Render(theWorkspace);
}
virtual void Release (const Handle(OpenGl_Context)& theGlCtx)
{
//
}
public:
DEFINE_STANDARD_ALLOC
};
@@ -175,21 +180,7 @@ void VUserDrawObj::Render(const Handle(OpenGl_Workspace)& theWorkspace) const
*(theWorkspace->HighlightColor) : aLA->Color();
// To test OpenGl_Window
Handle(OpenGl_Context) aCtx = theWorkspace->GetGlContext();
GLCONTEXT aGlContext = theWorkspace->GetGContext();
// To link against OpenGl_Context and extensions
GLuint aVboId = -1, aTexId = -1;
if (aCtx->arbVBO)
aCtx->arbVBO->glGenBuffersARB(1, &aVboId);
glGenTextures(1, &aTexId);
// To link against OpenGl_ResourceCleaner, OpenGl_ResourceVBO, OpenGl_ResourceTexture
OpenGl_ResourceCleaner* aResCleaner = OpenGl_ResourceCleaner::GetInstance();
if (aVboId != (GLuint)-1)
aResCleaner->AddResource(aGlContext, new OpenGl_ResourceVBO(aVboId));
if (aTexId != (GLuint)-1)
aResCleaner->AddResource(aGlContext, new OpenGl_ResourceTexture(aTexId));
//Handle(OpenGl_Context) aCtx = theWorkspace->GetGlContext();
// Finally draw something to make sure UserDraw really works
glPushAttrib(GL_ENABLE_BIT);
@@ -228,6 +219,13 @@ static Standard_Integer VUserDraw (Draw_Interpretor& di,
return 1;
}
Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aContext->CurrentViewer()->Device()->GraphicDriver());
if (aDriver.IsNull())
{
std::cerr << "Graphic driver not available.\n";
return 1;
}
if (argc > 2)
{
di << argv[0] << "Wrong number of arguments, only the object name expected\n";
@@ -238,7 +236,7 @@ static Standard_Integer VUserDraw (Draw_Interpretor& di,
VDisplayAISObject(aName, Handle(AIS_InteractiveObject)());
// register the custom element factory function
::UserDrawCallback() = VUserDrawCallback;
aDriver->UserDrawCallback() = VUserDrawCallback;
Handle(VUserDrawObj) anIObj = new VUserDrawObj();
VDisplayAISObject(aName, anIObj);

View File

@@ -234,16 +234,14 @@ void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_I
a3DCollector = new V3d_Viewer(GetG3dDevice(), NameOfWindow.ToExtString());
a3DViewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
a3DCollector->SetDefaultBackgroundColor(Quantity_NOC_STEELBLUE);
Handle(NIS_View) aView =
Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
if ( aView.IsNull() ) {
// Handle (V3d_View) V = a3DViewer->CreateView();
Handle(NIS_View) aView = Handle(NIS_View)::DownCast(ViewerTest::CurrentView());
if (aView.IsNull())
{
//Handle(V3d_View) a3DViewCol = a3DViewer->CreateView();
aView = new NIS_View (a3DViewer, VT_GetWindow());
ViewerTest::CurrentView(aView);
TheNISContext()->AttachView (aView);
}
Handle(V3d_View) a3DViewCol;
if ( a3DViewCol.IsNull() ) a3DViewCol = a3DViewer->CreateView();
// AIS setup
if ( ViewerTest::GetAISContext().IsNull() ) {