// and conditions governing the rights and limitations under the License.
-#include <OpenGl_ArbVBO.hxx>
+#include <OpenGl_IndexBuffer.hxx>
#include <OpenGl_Context.hxx>
#include <OpenGl_PrimitiveArray.hxx>
#include <OpenGl_AspectFace.hxx>
#include <OpenGl_GraphicDriver.hxx>
-#include <OpenGl_ResourceCleaner.hxx>
-#include <OpenGl_ResourceVBO.hxx>
#include <OpenGl_Structure.hxx>
#include <OpenGl_TextureBox.hxx>
#include <InterfaceGraphic_PrimitiveArray.hxx>
-enum
-{
- VBO_NOT_INITIALIZED = -1,
- VBO_ERROR = 0,
- VBO_OK = 1
-};
-
namespace
{
static unsigned long vRand = 1L;
// =======================================================================
void OpenGl_PrimitiveArray::clearMemoryOwn() const
{
- if (myPArray->bufferVBO[VBOEdges] != 0)
- {
- Standard::Free ((Standard_Address& )myPArray->edges);
- myPArray->edges = NULL;
- }
- if (myPArray->bufferVBO[VBOVertices] != 0)
- {
- Standard::Free ((Standard_Address& )myPArray->vertices);
- myPArray->vertices = NULL;
- }
- if (myPArray->bufferVBO[VBOVcolours] != 0)
- {
- Standard::Free ((Standard_Address& )myPArray->vcolours);
- myPArray->vcolours = NULL;
- }
- if (myPArray->bufferVBO[VBOVnormals] != 0)
- {
- Standard::Free ((Standard_Address& )myPArray->vnormals);
- myPArray->vnormals = NULL;
- }
- if (myPArray->bufferVBO[VBOVtexels] != 0)
- {
- Standard::Free ((Standard_Address& )myPArray->vtexels);
- myPArray->vtexels = NULL;
- }
- if (myPArray->edge_vis != NULL) /// ????
- {
- Standard::Free ((Standard_Address& )myPArray->edge_vis);
- myPArray->edge_vis = NULL;
- }
+ Standard::Free ((Standard_Address& )myPArray->edges);
+ Standard::Free ((Standard_Address& )myPArray->vertices);
+ Standard::Free ((Standard_Address& )myPArray->vcolours);
+ Standard::Free ((Standard_Address& )myPArray->vnormals);
+ Standard::Free ((Standard_Address& )myPArray->vtexels);
+ Standard::Free ((Standard_Address& )myPArray->edge_vis); /// ???
+
+ myPArray->edges = NULL;
+ myPArray->vertices = NULL;
+ myPArray->vcolours = NULL;
+ myPArray->vnormals = NULL;
+ myPArray->vtexels = NULL;
+ myPArray->edge_vis = NULL;
}
// =======================================================================
// function : clearMemoryGL
// purpose :
// =======================================================================
-void OpenGl_PrimitiveArray::clearMemoryGL (const Handle(OpenGl_Context)& theGlContext) const
+void OpenGl_PrimitiveArray::clearMemoryGL (const Handle(OpenGl_Context)& theGlCtx) const
{
- if (myPArray->bufferVBO[VBOEdges] != 0)
+ for (Standard_Integer anIter = 0; anIter < VBOMaxType; ++anIter)
{
- theGlContext->arbVBO->glDeleteBuffersARB (1, &myPArray->bufferVBO[VBOEdges]);
- }
- if (myPArray->bufferVBO[VBOVertices] != 0)
- {
- theGlContext->arbVBO->glDeleteBuffersARB (1, &myPArray->bufferVBO[VBOVertices]);
- }
- if (myPArray->bufferVBO[VBOVcolours] != 0)
- {
- theGlContext->arbVBO->glDeleteBuffersARB (1, &myPArray->bufferVBO[VBOVcolours]);
- }
- if (myPArray->bufferVBO[VBOVnormals] != 0)
- {
- theGlContext->arbVBO->glDeleteBuffersARB (1, &myPArray->bufferVBO[VBOVnormals]);
- }
- if (myPArray->bufferVBO[VBOVtexels] != 0)
- {
- theGlContext->arbVBO->glDeleteBuffersARB (1, &myPArray->bufferVBO[VBOVtexels]);
+ if (!myVbos[anIter].IsNull())
+ {
+ myVbos[anIter]->Release (theGlCtx.operator->());
+ myVbos[anIter].Nullify();
+ }
}
- theGlContext->arbVBO->glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0);
- theGlContext->arbVBO->glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
}
// =======================================================================
-// function : checkSizeForGraphicMemory
+// function : BuildVBO
// purpose :
// =======================================================================
-Standard_Boolean OpenGl_PrimitiveArray::checkSizeForGraphicMemory (const Handle(OpenGl_Context)& theGlContext) const
+Standard_Boolean OpenGl_PrimitiveArray::BuildVBO (const Handle(OpenGl_Workspace)& theWorkspace) const
{
- if (glGetError() == GL_OUT_OF_MEMORY)
+ const Handle(OpenGl_Context)& aGlCtx = theWorkspace->GetGlContext();
+ if (myPArray->vertices == NULL)
{
- myPArray->flagBufferVBO = VBO_ERROR;
- clearMemoryGL (theGlContext);
+ // vertices should be always defined - others are optional
+ return Standard_False;
}
- else
+ myVbos[VBOVertices] = new OpenGl_VertexBuffer();
+ if (!myVbos[VBOVertices]->Init (aGlCtx, 3, myPArray->num_vertexs, &myPArray->vertices[0].xyz[0]))
{
- myPArray->flagBufferVBO = VBO_OK;
+ clearMemoryGL (aGlCtx);
+ return Standard_False;
}
- return myPArray->flagBufferVBO == VBO_OK;
-}
-// =======================================================================
-// function : BuildVBO
-// purpose :
-// =======================================================================
-Standard_Boolean OpenGl_PrimitiveArray::BuildVBO (const Handle(OpenGl_Workspace)& theWorkspace) const
-{
- int size_reqd = 0;
- const Handle(OpenGl_Context)& aGlContext = theWorkspace->GetGlContext();
if (myPArray->edges != NULL)
{
- size_reqd = myPArray->num_edges * sizeof(Tint);
- aGlContext->arbVBO->glGenBuffersARB (1, &myPArray->bufferVBO[VBOEdges]);
- aGlContext->arbVBO->glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, myPArray->bufferVBO[VBOEdges]);
- aGlContext->arbVBO->glBufferDataARB (GL_ELEMENT_ARRAY_BUFFER_ARB, size_reqd, myPArray->edges, GL_STATIC_DRAW_ARB);
- if (!checkSizeForGraphicMemory (aGlContext))
- return Standard_False;
- }
-
- if (myPArray->vertices != NULL)
- {
- size_reqd = myPArray->num_vertexs * sizeof(TEL_POINT);
- aGlContext->arbVBO->glGenBuffersARB (1, &myPArray->bufferVBO[VBOVertices]);
- aGlContext->arbVBO->glBindBufferARB (GL_ARRAY_BUFFER_ARB, myPArray->bufferVBO[VBOVertices]);
- aGlContext->arbVBO->glBufferDataARB (GL_ARRAY_BUFFER_ARB, size_reqd, myPArray->vertices, GL_STATIC_DRAW_ARB);
- if (!checkSizeForGraphicMemory (aGlContext))
+ myVbos[VBOEdges] = new OpenGl_IndexBuffer();
+ if (!myVbos[VBOEdges]->Init (aGlCtx, 1, myPArray->num_edges, (GLuint* )myPArray->edges))
+ {
+ clearMemoryGL (aGlCtx);
return Standard_False;
+ }
}
-
if (myPArray->vcolours != NULL)
{
- size_reqd = myPArray->num_vertexs * sizeof(Tint);
- aGlContext->arbVBO->glGenBuffersARB (1, &myPArray->bufferVBO[VBOVcolours]);
- aGlContext->arbVBO->glBindBufferARB (GL_ARRAY_BUFFER_ARB, myPArray->bufferVBO[VBOVcolours]);
- aGlContext->arbVBO->glBufferDataARB (GL_ARRAY_BUFFER_ARB, size_reqd, myPArray->vcolours, GL_STATIC_DRAW_ARB);
- if (!checkSizeForGraphicMemory (aGlContext))
+ myVbos[VBOVcolours] = new OpenGl_VertexBuffer();
+ if (!myVbos[VBOVcolours]->Init (aGlCtx, 4, myPArray->num_vertexs, (GLubyte* )myPArray->vcolours))
+ {
+ clearMemoryGL (aGlCtx);
return Standard_False;
+ }
}
-
if (myPArray->vnormals != NULL)
{
- size_reqd = myPArray->num_vertexs * sizeof(TEL_POINT);
- aGlContext->arbVBO->glGenBuffersARB (1, &myPArray->bufferVBO[VBOVnormals]);
- aGlContext->arbVBO->glBindBufferARB (GL_ARRAY_BUFFER_ARB, myPArray->bufferVBO[VBOVnormals]);
- aGlContext->arbVBO->glBufferDataARB (GL_ARRAY_BUFFER_ARB, size_reqd, myPArray->vnormals, GL_STATIC_DRAW_ARB);
- if (!checkSizeForGraphicMemory (aGlContext))
+ myVbos[VBOVnormals] = new OpenGl_VertexBuffer();
+ if (!myVbos[VBOVnormals]->Init (aGlCtx, 3, myPArray->num_vertexs, &myPArray->vnormals[0].xyz[0]))
+ {
+ clearMemoryGL (aGlCtx);
return Standard_False;
+ }
}
-
if (myPArray->vtexels)
{
- size_reqd = myPArray->num_vertexs * sizeof(TEL_TEXTURE_COORD);
- aGlContext->arbVBO->glGenBuffersARB (1, &myPArray->bufferVBO[VBOVtexels]);
- aGlContext->arbVBO->glBindBufferARB (GL_ARRAY_BUFFER_ARB, myPArray->bufferVBO[VBOVtexels]);
- aGlContext->arbVBO->glBufferDataARB (GL_ARRAY_BUFFER_ARB, size_reqd, myPArray->vtexels, GL_STATIC_DRAW_ARB);
- if (!checkSizeForGraphicMemory (aGlContext))
+ myVbos[VBOVtexels] = new OpenGl_VertexBuffer();
+ if (!myVbos[VBOVtexels]->Init (aGlCtx, 2, myPArray->num_vertexs, &myPArray->vtexels[0].xy[0]))
+ {
+ clearMemoryGL (aGlCtx);
return Standard_False;
+ }
}
- if (myPArray->flagBufferVBO == VBO_OK)
- clearMemoryOwn();
-
- // specify context for VBO resource
- myPArray->contextId = (Standard_Address )theWorkspace->GetGContext();
+ clearMemoryOwn();
return Standard_True;
}
-// =======================================================================
-// function : DrawArrays
-// purpose : Auxiliary method to split Feedback/Normal rendering modes
-// =======================================================================
-inline void DrawArrays (const Handle(OpenGl_Workspace)& theWorkspace,
- const CALL_DEF_PARRAY* thePArray,
- const Standard_Boolean theIsFeedback,
- GLenum theMode,
- GLint theFirst,
- GLsizei theCount)
-{
- if (!theIsFeedback)
- {
- glDrawArrays (theMode, theFirst, theCount);
- return;
- }
-
- glBegin (theMode);
- for (int anIter = theFirst; anIter < (theFirst + theCount); ++anIter)
- {
- if (thePArray->vnormals != NULL)
- glNormal3fv (thePArray->vnormals[anIter].xyz);
- if (thePArray->vtexels != NULL && (theWorkspace->NamedStatus & OPENGL_NS_FORBIDSETTEX) == 0)
- glTexCoord3fv (thePArray->vtexels[anIter].xy);
- if (thePArray->vertices != NULL)
- glVertex3fv (thePArray->vertices[anIter].xyz);
- if (thePArray->vcolours != NULL)
- glColor4ubv((GLubyte* )thePArray->vcolours[anIter]);
- }
- glEnd();
-}
-
-// =======================================================================
-// function : DrawElements
-// purpose : Auxiliary method to split Feedback/Normal rendering modes
-// =======================================================================
-inline void DrawElements (const Handle(OpenGl_Workspace)& theWorkspace,
- const CALL_DEF_PARRAY* thePArray,
- const Standard_Boolean theIsFeedback,
- GLenum theMode,
- GLsizei theCount,
- GLenum* theIndices)
-{
- if (!theIsFeedback)
- {
- glDrawElements (theMode, theCount, GL_UNSIGNED_INT, theIndices);
- return;
- }
-
- GLenum anIndex;
- glBegin (theMode);
- for (GLsizei anIter = 0; anIter < theCount; ++anIter)
- {
- anIndex = theIndices[anIter];
- if (thePArray->vnormals != NULL)
- glNormal3fv (thePArray->vnormals[anIndex].xyz);
- if (thePArray->vtexels != NULL && (theWorkspace->NamedStatus & OPENGL_NS_FORBIDSETTEX) == 0)
- glTexCoord3fv (thePArray->vtexels[anIndex].xy);
- if (thePArray->vertices != NULL)
- glVertex3fv (thePArray->vertices[anIndex].xyz);
- if (thePArray->vcolours != NULL)
- glColor4ubv ((GLubyte* )thePArray->vcolours[anIndex]);
- }
- glEnd();
-}
-
// =======================================================================
// function : DrawArray
// purpose :
else
glEnable (GL_LIGHTING);
- if (myPArray->num_vertexs > 0
- && myPArray->flagBufferVBO != VBO_OK
- && !aGlContext->IsFeedback())
+ if (!toDrawVbo())
{
if (myPArray->vertices != NULL)
{
glEnable (GL_COLOR_MATERIAL);
}
}
- else if (myPArray->num_vertexs > 0
- && myPArray->flagBufferVBO == VBO_OK)
+ else
{
// Bindings concrete pointer in accordance with VBO buffer
- if (myPArray->bufferVBO[VBOVertices] != 0)
- {
- aGlContext->arbVBO->glBindBufferARB (GL_ARRAY_BUFFER_ARB, myPArray->bufferVBO[VBOVertices]);
- glVertexPointer (3, GL_FLOAT, 0, NULL); // array of vertices
- glEnableClientState (GL_VERTEX_ARRAY);
- }
- if (myPArray->bufferVBO[VBOVnormals] != 0)
+ myVbos[VBOVertices]->BindFixed (aGlContext, GL_VERTEX_ARRAY);
+ if (!myVbos[VBOVnormals].IsNull())
{
- aGlContext->arbVBO->glBindBufferARB (GL_ARRAY_BUFFER_ARB, myPArray->bufferVBO[VBOVnormals]);
- glNormalPointer (GL_FLOAT, 0, NULL); // array of normals
- glEnableClientState (GL_NORMAL_ARRAY);
+ myVbos[VBOVnormals]->BindFixed (aGlContext, GL_NORMAL_ARRAY);
}
- if (myPArray->bufferVBO[VBOVtexels] != 0 && (theWorkspace->NamedStatus & OPENGL_NS_FORBIDSETTEX) == 0)
+ if (!myVbos[VBOVtexels].IsNull() && (theWorkspace->NamedStatus & OPENGL_NS_FORBIDSETTEX) == 0)
{
- aGlContext->arbVBO->glBindBufferARB (GL_ARRAY_BUFFER_ARB, myPArray->bufferVBO[VBOVtexels]);
- glTexCoordPointer (2, GL_FLOAT, 0, NULL); // array of texture coordinates
- glEnableClientState (GL_TEXTURE_COORD_ARRAY);
+ myVbos[VBOVtexels]->BindFixed (aGlContext, GL_TEXTURE_COORD_ARRAY);
}
- if (myPArray->bufferVBO[VBOVcolours] != 0)
+ if (!myVbos[VBOVcolours].IsNull())
{
- aGlContext->arbVBO->glBindBufferARB (GL_ARRAY_BUFFER_ARB, myPArray->bufferVBO[VBOVcolours]);
- glColorPointer (4, GL_UNSIGNED_BYTE, 0, NULL); // array of colors
- glEnableClientState (GL_COLOR_ARRAY);
- glColorMaterial (GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
+ myVbos[VBOVcolours]->BindFixed (aGlContext, GL_COLOR_ARRAY);
+ glColorMaterial (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glEnable (GL_COLOR_MATERIAL);
}
}
- // OCC22236 NOTE: draw for all situations:
- // 1) draw elements from myPArray->bufferVBO[VBOEdges] indicies array
- // 2) draw elements from vertice array, when bounds defines count of primitive's verts.
- // 3) draw primitive by vertexes if no edges and bounds array is specified
- if (myPArray->flagBufferVBO == VBO_OK)
+ /// OCC22236 NOTE: draw for all situations:
+ /// 1) draw elements from myPArray->bufferVBO[VBOEdges] indicies array
+ /// 2) draw elements from vertice array, when bounds defines count of primitive's verts.
+ /// 3) draw primitive by vertexes if no edges and bounds array is specified
+ if (toDrawVbo())
{
- if (myPArray->num_edges > 0 && myPArray->bufferVBO[VBOEdges] != 0)
+ if (!myVbos[VBOEdges].IsNull())
{
- aGlContext->arbVBO->glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, myPArray->bufferVBO[VBOEdges]); // for edge indices
+ myVbos[VBOEdges]->Bind (aGlContext);
if (myPArray->num_bounds > 0)
{
// draw primitives by vertex count with the indicies
Tint* anOffset = NULL;
for (i = 0; i < myPArray->num_bounds; ++i)
{
- glDrawElements (myDrawMode, myPArray->bounds[i], GL_UNSIGNED_INT, anOffset);
+ glDrawElements (myDrawMode, myPArray->bounds[i], myVbos[VBOEdges]->GetDataType(), anOffset);
anOffset += myPArray->bounds[i];
}
}
else
{
// draw one (or sequential) primitive by the indicies
- glDrawElements (myDrawMode, myPArray->num_edges, GL_UNSIGNED_INT, NULL);
+ glDrawElements (myDrawMode, myPArray->num_edges, myVbos[VBOEdges]->GetDataType(), NULL);
}
+ myVbos[VBOEdges]->Unbind (aGlContext);
}
else if (myPArray->num_bounds > 0)
{
}
else
{
- glDrawArrays (myDrawMode, 0, myPArray->num_vertexs);
+ glDrawArrays (myDrawMode, 0, myVbos[VBOVertices]->GetElemsNb());
}
// bind with 0
- aGlContext->arbVBO->glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0);
- aGlContext->arbVBO->glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
+ myVbos[VBOVertices]->UnbindFixed (aGlContext, GL_VERTEX_ARRAY);
+ if (!myVbos[VBOVnormals].IsNull())
+ {
+ myVbos[VBOVnormals]->UnbindFixed (aGlContext, GL_NORMAL_ARRAY);
+ }
+ if (!myVbos[VBOVtexels].IsNull() && (theWorkspace->NamedStatus & OPENGL_NS_FORBIDSETTEX) == 0)
+ {
+ myVbos[VBOVtexels]->UnbindFixed (aGlContext, GL_TEXTURE_COORD_ARRAY);
+ }
+ if (!myVbos[VBOVcolours].IsNull())
+ {
+ myVbos[VBOVcolours]->UnbindFixed (aGlContext, GL_COLOR_ARRAY);
+ glDisable (GL_COLOR_MATERIAL);
+ theWorkspace->NamedStatus |= OPENGL_NS_RESMAT; // Reset material
+ }
}
else
{
for (i = n = 0; i < myPArray->num_bounds; ++i)
{
if (pfc != NULL) glColor3fv (pfc[i].rgb);
- DrawElements (theWorkspace, myPArray, aGlContext->IsFeedback(), myDrawMode,
- myPArray->bounds[i], (GLenum* )&myPArray->edges[n]);
+ glDrawElements (myDrawMode, myPArray->bounds[i], GL_UNSIGNED_INT, (GLenum* )&myPArray->edges[n]);
n += myPArray->bounds[i];
}
}
{
glColor3fv (pfc[i].rgb);
}
- DrawArrays (theWorkspace, myPArray, aGlContext->IsFeedback(), myDrawMode,
- n, myPArray->bounds[i]);
+ glDrawArrays (myDrawMode, n, myPArray->bounds[i]);
n += myPArray->bounds[i];
}
}
}
else if (myPArray->num_edges > 0)
{
- DrawElements (theWorkspace, myPArray, aGlContext->IsFeedback(), myDrawMode,
- myPArray->num_edges, (GLenum* )myPArray->edges);
+ glDrawElements (myDrawMode, myPArray->num_edges, GL_UNSIGNED_INT, (GLenum* )myPArray->edges);
}
else
{
- DrawArrays (theWorkspace, myPArray, aGlContext->IsFeedback(), myDrawMode,
- 0, myPArray->num_vertexs);
+ glDrawArrays (myDrawMode, 0, myPArray->num_vertexs);
}
- }
- if (myPArray->bufferVBO[VBOVcolours] != 0 || pvc != NULL)
- {
- glDisable (GL_COLOR_MATERIAL);
- theWorkspace->NamedStatus |= OPENGL_NS_RESMAT; // Reset material
- }
+ if (pvc != NULL)
+ {
+ glDisable (GL_COLOR_MATERIAL);
+ theWorkspace->NamedStatus |= OPENGL_NS_RESMAT; // Reset material
+ }
- if (myPArray->bufferVBO[VBOVertices] != 0 || myPArray->vertices != NULL)
glDisableClientState (GL_VERTEX_ARRAY);
- if (myPArray->bufferVBO[VBOVcolours] != 0 || myPArray->vcolours != NULL)
- glDisableClientState (GL_COLOR_ARRAY);
- if (myPArray->bufferVBO[VBOVnormals] != 0 || myPArray->vnormals != NULL)
- glDisableClientState (GL_NORMAL_ARRAY);
- if ((myPArray->bufferVBO[VBOVtexels] != 0 && (theWorkspace->NamedStatus & OPENGL_NS_FORBIDSETTEX) == 0) || myPArray->vtexels != NULL)
- glDisableClientState (GL_TEXTURE_COORD_ARRAY);
+ if (myPArray->vcolours != NULL)
+ glDisableClientState (GL_COLOR_ARRAY);
+ if (myPArray->vnormals != NULL)
+ glDisableClientState (GL_NORMAL_ARRAY);
+ if (myPArray->vtexels != NULL)
+ glDisableClientState (GL_TEXTURE_COORD_ARRAY);
+ }
if (theWorkspace->DegenerateModel)
{
break;
// DegenerateModel(as Lines, Points, BBoxs) are used only without VBO
case 2: // XXX_TDM_WIREFRAME
- if (myPArray->VBOEnabled == 0)
+ if (!toDrawVbo())
DrawDegeneratesAsLines ((theEdgeFlag ? theEdgeColour : theInteriorColour), theWorkspace);
break;
case 3: // XXX_TDM_MARKER
- if (myPArray->VBOEnabled == 0)
+ if (!toDrawVbo())
DrawDegeneratesAsPoints ((theEdgeFlag ? theEdgeColour : theInteriorColour), theWorkspace->SkipRatio);
break;
case 4: // XXX_TDM_BBOX
- if (myPArray->VBOEnabled == 0)
+ if (!toDrawVbo())
DrawDegeneratesAsBBoxs (theEdgeFlag ? theEdgeColour : theInteriorColour);
break;
}
Tint i, j, n;
- // OCC22236 NOTE: draw edges for all situations:
- // 1) draw elements with GL_LINE style as edges from myPArray->bufferVBO[VBOEdges] indicies array
- // 2) draw elements from vertice array, when bounds defines count of primitive's verts.
- // 3) draw primitive's edges by vertexes if no edges and bounds array is specified
- if (myPArray->flagBufferVBO == VBO_OK)
+ /// OCC22236 NOTE: draw edges for all situations:
+ /// 1) draw elements with GL_LINE style as edges from myPArray->bufferVBO[VBOEdges] indicies array
+ /// 2) draw elements from vertice array, when bounds defines count of primitive's verts.
+ /// 3) draw primitive's edges by vertexes if no edges and bounds array is specified
+ if (toDrawVbo())
{
- aGlContext->arbVBO->glBindBufferARB (GL_ARRAY_BUFFER_ARB, myPArray->bufferVBO[VBOVertices]);
- glEnableClientState (GL_VERTEX_ARRAY);
+ myVbos[VBOVertices]->BindFixed (aGlContext, GL_VERTEX_ARRAY);
glColor3fv (theEdgeColour->rgb);
- if (myPArray->num_edges > 0 && myPArray->bufferVBO[VBOEdges])
+ if (!myVbos[VBOEdges].IsNull())
{
- aGlContext->arbVBO->glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, myPArray->bufferVBO[VBOEdges]);
+ myVbos[VBOEdges]->Bind (aGlContext);
// draw primitives by vertex count with the indicies
if (myPArray->num_bounds > 0)
Tint* offset = 0;
for (i = 0, offset = 0; i < myPArray->num_bounds; ++i)
{
- glDrawElements (myDrawMode, myPArray->bounds[i], GL_UNSIGNED_INT, offset);
+ glDrawElements (myDrawMode, myPArray->bounds[i], myVbos[VBOEdges]->GetDataType(), offset);
offset += myPArray->bounds[i];
}
}
// draw one (or sequential) primitive by the indicies
else
{
- glDrawElements (myDrawMode, myPArray->num_edges, GL_UNSIGNED_INT, NULL);
+ glDrawElements (myDrawMode, myVbos[VBOEdges]->GetElemsNb(), myVbos[VBOEdges]->GetDataType(), NULL);
}
+ myVbos[VBOEdges]->Unbind (aGlContext);
}
else if (myPArray->num_bounds > 0)
{
}
// unbind buffers
- glDisableClientState (GL_VERTEX_ARRAY);
- aGlContext->arbVBO->glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0);
- aGlContext->arbVBO->glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
+ myVbos[VBOVertices]->UnbindFixed (aGlContext, GL_VERTEX_ARRAY);
}
else
{
}
else
{
- DrawElements (theWorkspace, myPArray, aGlContext->IsFeedback(), myDrawMode,
- myPArray->bounds[i], (GLenum* )&myPArray->edges[n]);
+ glDrawElements (myDrawMode, myPArray->bounds[i], GL_UNSIGNED_INT, (GLenum* )&myPArray->edges[n]);
}
n += myPArray->bounds[i];
}
{
for (i = n = 0 ; i < myPArray->num_bounds; ++i)
{
- DrawArrays (theWorkspace, myPArray, aGlContext->IsFeedback(), myDrawMode,
- n, myPArray->bounds[i]);
+ glDrawArrays (myDrawMode, n, myPArray->bounds[i]);
n += myPArray->bounds[i];
}
}
}
else
{
- DrawElements (theWorkspace, myPArray, aGlContext->IsFeedback(), myDrawMode,
- myPArray->num_edges, (GLenum* )myPArray->edges);
+ glDrawElements (myDrawMode, myPArray->num_edges, GL_UNSIGNED_INT, (GLenum* )myPArray->edges);
}
}
else
{
- DrawArrays (theWorkspace, myPArray, aGlContext->IsFeedback(), myDrawMode,
- 0, myPArray->num_vertexs);
+ glDrawArrays (myDrawMode, 0, myPArray->num_vertexs);
}
}
else
{
int i,n;
- Standard_Boolean isFeedback = theWorkspace->GetGlContext()->IsFeedback();
glPushAttrib (GL_POLYGON_BIT);
glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
{
for (i = n = 0; i < myPArray->num_bounds; ++i)
{
- DrawElements (theWorkspace, myPArray, isFeedback, myDrawMode,
- myPArray->bounds[i], (GLenum* )&myPArray->edges[n]);
+ glDrawElements (myDrawMode, myPArray->bounds[i], GL_UNSIGNED_INT, (GLenum* )&myPArray->edges[n]);
n += myPArray->bounds[i];
}
}
{
for (i = n = 0; i < myPArray->num_bounds; ++i)
{
- DrawArrays (theWorkspace, myPArray, isFeedback, myDrawMode,
- n, myPArray->bounds[i]);
+ glDrawArrays (myDrawMode, n, myPArray->bounds[i]);
n += myPArray->bounds[i];
}
}
}
else if (myPArray->num_edges > 0)
{
- DrawElements (theWorkspace, myPArray, isFeedback, myDrawMode,
- myPArray->num_edges, (GLenum* )myPArray->edges);
+ glDrawElements (myDrawMode, myPArray->num_edges, GL_UNSIGNED_INT, (GLenum* )myPArray->edges);
}
else
{
- DrawArrays (theWorkspace, myPArray, isFeedback, myDrawMode,
- 0, myPArray->num_vertexs);
+ glDrawArrays (myDrawMode, 0, myPArray->num_vertexs);
}
if (!vertex_array_mode) glDisableClientState (GL_VERTEX_ARRAY);
// =======================================================================
OpenGl_PrimitiveArray::OpenGl_PrimitiveArray (CALL_DEF_PARRAY* thePArray)
: myPArray (thePArray),
- myDrawMode (DRAW_MODE_NONE)
+ myDrawMode (DRAW_MODE_NONE),
+ myIsVboInit (Standard_False)
{
switch (myPArray->type)
{
// function : ~OpenGl_PrimitiveArray
// purpose :
// =======================================================================
-OpenGl_PrimitiveArray::~OpenGl_PrimitiveArray ()
+OpenGl_PrimitiveArray::~OpenGl_PrimitiveArray()
{
- if (myPArray == NULL)
- return;
+ //
+}
- if (myPArray->VBOEnabled == VBO_OK)
+// =======================================================================
+// function : Release
+// purpose :
+// =======================================================================
+void OpenGl_PrimitiveArray::Release (const Handle(OpenGl_Context)& theContext)
+{
+ for (Standard_Integer anIter = 0; anIter < VBOMaxType; ++anIter)
{
- OpenGl_ResourceCleaner* aResCleaner = OpenGl_ResourceCleaner::GetInstance();
- if (myPArray->bufferVBO[VBOEdges] != 0)
- aResCleaner->AddResource ((GLCONTEXT )myPArray->contextId,
- new OpenGl_ResourceVBO (myPArray->bufferVBO[VBOEdges]));
- if (myPArray->bufferVBO[VBOVertices] != 0)
- aResCleaner->AddResource ((GLCONTEXT )myPArray->contextId,
- new OpenGl_ResourceVBO (myPArray->bufferVBO[VBOVertices]));
- if (myPArray->bufferVBO[VBOVcolours] != 0)
- aResCleaner->AddResource ((GLCONTEXT )myPArray->contextId,
- new OpenGl_ResourceVBO (myPArray->bufferVBO[VBOVcolours]));
- if (myPArray->bufferVBO[VBOVnormals] != 0)
- aResCleaner->AddResource ((GLCONTEXT )myPArray->contextId,
- new OpenGl_ResourceVBO (myPArray->bufferVBO[VBOVnormals]));
- if (myPArray->bufferVBO[VBOVtexels] != 0)
- aResCleaner->AddResource ((GLCONTEXT )myPArray->contextId,
- new OpenGl_ResourceVBO (myPArray->bufferVBO[VBOVtexels]));
+ if (!myVbos[anIter].IsNull())
+ {
+ theContext->DelayedRelease (myVbos[anIter]);
+ myVbos[anIter].Nullify();
+ }
}
}
// =======================================================================
void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
{
- if (myPArray == NULL || myDrawMode == DRAW_MODE_NONE)
+ if (myPArray == NULL || myDrawMode == DRAW_MODE_NONE || myPArray->num_vertexs <= 0)
return;
// create VBOs on first render call
- if (myPArray->VBOEnabled == -1) // special value for uninitialized state
+ if (!myIsVboInit && OpenGl_GraphicDriver::ToUseVBO() && theWorkspace->GetGlContext()->core15 != NULL)
{
- myPArray->VBOEnabled = OpenGl_GraphicDriver::ToUseVBO() && (theWorkspace->GetGlContext()->arbVBO != NULL);
- if (myPArray->VBOEnabled != 0)
- BuildVBO (theWorkspace);
+ BuildVBO (theWorkspace);
+ myIsVboInit = Standard_True;
}
switch (myPArray->type)
break;
}
- const OpenGl_AspectFace* anAspectFace = theWorkspace->AspectFace (Standard_True);
- const OpenGl_AspectLine* anAspectLine = theWorkspace->AspectLine (Standard_True);
+ const OpenGl_AspectFace* anAspectFace = theWorkspace->AspectFace (Standard_True);
+ const OpenGl_AspectLine* anAspectLine = theWorkspace->AspectLine (Standard_True);
+ const OpenGl_AspectMarker* anAspectMarker = theWorkspace->AspectMarker (myPArray->type == TelPointsArrayType);
Tint aFrontLightingModel = anAspectFace->Context().IntFront.color_mask;
const TEL_COLOUR* anInteriorColor = &anAspectFace->Context().IntFront.matcol;
const TEL_COLOUR* anEdgeColor = &anAspectFace->AspectEdge()->Color();
- const TEL_COLOUR* aLineColor = &anAspectLine->Color();
+ const TEL_COLOUR* aLineColor = (myPArray->type == TelPointsArrayType) ? &anAspectMarker->Color() : &anAspectLine->Color();
// Use highlight colors
if (theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT)