-/*
-File OpenGl_PrimitiveArray.c
-
-Created 16/06/2000 : ATS : G005 : Modified version of OpenGl_indexpolygons.c, which use glDrawArrays or glDrawElements for rendering of primitive
-21.06.03 : SAN : suppress display at all in animation mode if degenartion ratio == 1 (FULL_DEGENER)
-03.07.03 : SAN : draw_degenerates_as_lines() function - all client states disabled except GL_VERTEX_ARRAY
-in order to avoid exceptions in animation mode (OCC3192)
-*/
-
-#define xOGLBUG /* UNFORTUNATLY the edge flags are attached to vertexes
-and not to the edges. So the edge visibillity flags array
-is not usable.
-*/
-
-#define xPRINT
-
-#define TEST
-
-#define FULL_DEGENER
-#define OCC3192
-
-
-#ifndef OGL_Max
-#define OGL_Max(a,b) ((a) > (b) ? (a) : (b))
-#endif
-
-#ifndef OGL_Rand
-static unsigned long vRand = 1L;
-#define OGL_Rand() (vRand = vRand * 214013L + 2531011L)
-#endif
-
-
-#define OCC7833 /* ASL 26/01/05 transparency of polygon with colors assigned to vertices */
-
-/*----------------------------------------------------------------------*/
-/*
-* Includes
-*/
-
-#include <OpenGl_tgl_all.hxx>
-
-#include <stddef.h>
-#include <stdio.h>
-#include <string.h>
-#include <iostream>
-
-#include <OpenGl_cmn_varargs.hxx>
-#include <OpenGl_telem_attri.hxx>
-#include <OpenGl_tsm.hxx>
-#include <OpenGl_telem.hxx>
-#include <OpenGl_telem_util.hxx>
-#include <OpenGl_telem_highlight.hxx>
-#include <OpenGl_telem_inquire.hxx>
-#include <OpenGl_telem_view.hxx>
-#include <OpenGl_tgl_funcs.hxx>
-#include <OpenGl_LightBox.hxx>
-#include <OpenGl_TextureBox.hxx>
-#include <OpenGl_ResourceCleaner.hxx>
-#include <OpenGl_ResourceVBO.hxx>
-#include <InterfaceGraphic_PrimitiveArray.hxx>
-#include <OpenGl_Memory.hxx>
-#include <Standard.hxx>
-
-# include <float.h>
-# define DEF_DS_INTERNAL
-# include <OpenGl_degeneration.hxx>
-
-#include <OpenGl_Extension.hxx>
-
-extern GLboolean g_fBitmap;
-
-typedef CALL_DEF_PARRAY *call_def_parray;
-
-#define GL_ARRAY_BUFFER_ARB 0x8892
-#define GL_STATIC_DRAW_ARB 0x88E4
-#define GL_ELEMENTS_ARRAY_BUFFER_ARB 0x8893
-#define GL_EDGE_FLAG_ARRAY_EXT 0x8079
-
-#ifdef WNT
-typedef void (APIENTRY* PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer);
-typedef void (APIENTRY* PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers);
-typedef void (APIENTRY* PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers);
-typedef void (APIENTRY* PFNGLBUFFERDATAARBPROC) (GLenum target, int size, const GLvoid *data, GLenum usage);
-#else//WNT
-typedef void (*PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer);
-typedef void (*PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers);
-typedef void (*PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers);
-#if defined ( __sgi )
-typedef void (*PFNGLBUFFERDATAARBPROC) (GLenum target, int size, const GLvoid *data, GLenum usage);
-#else
-typedef void (*PFNGLBUFFERDATAARBPROC) (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage);
-#endif
-
-#endif//WNT
-
-PFNGLGENBUFFERSARBPROC glVBOGenBuffersARB = NULL; // VBO Name Generation Procedure
-PFNGLBINDBUFFERARBPROC glVBOBindBufferARB = NULL; // VBO Bind Procedure
-PFNGLBUFFERDATAARBPROC glVBOBufferDataARB = NULL; // VBO Data Loading Procedure
-PFNGLDELETEBUFFERSARBPROC glVBODeleteBuffersARB = NULL; // VBO Data Deleting Procedure
-
-int VBOExtension = 0;
-int VBOenabled = 1;
-
-#define VBO_NOT_INITIALIZED -1
-#define VBO_ERROR 0
-#define VBO_OK 1
-
-#ifndef WNT
-#define glGetProcAddress( x ) glXGetProcAddress( (const GLubyte*) x )
-#else
-#define glGetProcAddress( x ) wglGetProcAddress( x )
-#endif
-
-void clearRAMMemory( CALL_DEF_PARRAY* p )
+// Created on: 2011-07-13
+// Created by: Sergey ZERCHANINOV
+// Copyright (c) 2011-2013 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#include <OpenGl_Aspects.hxx>
+#include <OpenGl_Context.hxx>
+#include <OpenGl_GraphicDriver.hxx>
+#include <OpenGl_IndexBuffer.hxx>
+#include <OpenGl_PointSprite.hxx>
+#include <OpenGl_PrimitiveArray.hxx>
+#include <OpenGl_Sampler.hxx>
+#include <OpenGl_ShaderManager.hxx>
+#include <OpenGl_ShaderProgram.hxx>
+#include <OpenGl_Structure.hxx>
+#include <OpenGl_VertexBufferCompat.hxx>
+#include <OpenGl_View.hxx>
+#include <OpenGl_Workspace.hxx>
+#include <Graphic3d_TextureParams.hxx>
+#include <NCollection_AlignedAllocator.hxx>
+
+namespace
{
- if( p->bufferVBO[VBOEdges] ){
- Standard::Free((Standard_Address&)p->edges);
- p->edges = NULL;
- }
- if( p->bufferVBO[VBOVertices] ){
- Standard::Free((Standard_Address&)p->vertices);
- p->vertices = NULL;
- }
- if( p->bufferVBO[VBOVcolours] ){
- Standard::Free((Standard_Address&)p->vcolours);
- p->vcolours = NULL;
- }
- if( p->bufferVBO[VBOVnormals] ){
- Standard::Free((Standard_Address&)p->vnormals);
- p->vnormals = NULL;
- }
- if( p->bufferVBO[VBOVtexels] ){
- Standard::Free((Standard_Address&)p->vtexels);
- p->vtexels = NULL;
+ //! Convert data type to GL info
+ inline GLenum toGlDataType (const Graphic3d_TypeOfData theType,
+ GLint& theNbComp)
+ {
+ switch (theType)
+ {
+ case Graphic3d_TOD_USHORT:
+ theNbComp = 1;
+ return GL_UNSIGNED_SHORT;
+ case Graphic3d_TOD_UINT:
+ theNbComp = 1;
+ return GL_UNSIGNED_INT;
+ case Graphic3d_TOD_VEC2:
+ theNbComp = 2;
+ return GL_FLOAT;
+ case Graphic3d_TOD_VEC3:
+ theNbComp = 3;
+ return GL_FLOAT;
+ case Graphic3d_TOD_VEC4:
+ theNbComp = 4;
+ return GL_FLOAT;
+ case Graphic3d_TOD_VEC4UB:
+ theNbComp = 4;
+ return GL_UNSIGNED_BYTE;
+ case Graphic3d_TOD_FLOAT:
+ theNbComp = 1;
+ return GL_FLOAT;
}
- if( p->edge_vis ){
- Standard::Free((Standard_Address&)p->edge_vis);
- p->edge_vis = NULL;
- }
-}
-
-void clearGraphicRAMMemory( CALL_DEF_PARRAY* p )
-{
- if( p->bufferVBO[VBOEdges] ){
- glVBODeleteBuffersARB( 1 , &p->bufferVBO[VBOEdges]);
- }
- if( p->bufferVBO[VBOVertices] ){
- glVBODeleteBuffersARB( 1 , &p->bufferVBO[VBOVertices]);
- }
- if( p->bufferVBO[VBOVcolours] ){
- glVBODeleteBuffersARB( 1 , &p->bufferVBO[VBOVcolours]);
+ theNbComp = 0;
+ return GL_NONE;
}
- if( p->bufferVBO[VBOVnormals] ){
- glVBODeleteBuffersARB( 1 , &p->bufferVBO[VBOVnormals]);
- }
- if( p->bufferVBO[VBOVtexels] ){
- glVBODeleteBuffersARB( 1 , &p->bufferVBO[VBOVtexels]);
- }
- glVBOBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
- glVBOBindBufferARB(GL_ELEMENTS_ARRAY_BUFFER_ARB, 0);
-}
-int checkSizeForGraphicMemory( CALL_DEF_PARRAY* p )
-{
- if( GL_OUT_OF_MEMORY == glGetError() ){
- p->flagBufferVBO = VBO_ERROR;
- clearGraphicRAMMemory(p);
- }
- else
- p->flagBufferVBO = VBO_OK;
- return p->flagBufferVBO ;
}
-int initVBO()
+//! Auxiliary template for VBO with interleaved attributes.
+template<class TheBaseClass, int NbAttributes>
+class OpenGl_VertexBufferT : public TheBaseClass
{
- if(CheckExtension((char *)"GL_ARB_vertex_buffer_object",(const char *)glGetString( GL_EXTENSIONS ))){
- glVBOGenBuffersARB = (PFNGLGENBUFFERSARBPROC) glGetProcAddress("glGenBuffersARB");
- glVBOBindBufferARB = (PFNGLBINDBUFFERARBPROC) glGetProcAddress("glBindBufferARB");
- glVBOBufferDataARB = (PFNGLBUFFERDATAARBPROC) glGetProcAddress("glBufferDataARB");
- glVBODeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC) glGetProcAddress("glDeleteBuffersARB");
- VBOExtension = 1;
- return 1;
- }
- return 0;
-}
+public:
-static void BuildVBO( CALL_DEF_PARRAY* p )
-{
- int size_reqd = 0;
- if( p->edges ){
- size_reqd = ( p->num_edges * sizeof( Tint ) );
- glVBOGenBuffersARB( 1, &p->bufferVBO[VBOEdges] );
- glVBOBindBufferARB( GL_ELEMENTS_ARRAY_BUFFER_ARB, p->bufferVBO[VBOEdges] );
- glVBOBufferDataARB( GL_ELEMENTS_ARRAY_BUFFER_ARB, size_reqd , p->edges, GL_STATIC_DRAW_ARB );
- if( checkSizeForGraphicMemory( p ) == VBO_ERROR )
- return;
+ //! Create uninitialized VBO.
+ OpenGl_VertexBufferT (const Graphic3d_Buffer& theAttribs)
+ : Stride (theAttribs.IsInterleaved() ? theAttribs.Stride : 0)
+ {
+ memcpy (Attribs, theAttribs.AttributesArray(), sizeof(Graphic3d_Attribute) * NbAttributes);
}
- if( p->vertices ){
- size_reqd = ( p->num_vertexs * sizeof( TEL_POINT ) );
- glVBOGenBuffersARB( 1, &p->bufferVBO[VBOVertices]);
- glVBOBindBufferARB( GL_ARRAY_BUFFER_ARB, p->bufferVBO[VBOVertices] );
- glVBOBufferDataARB( GL_ARRAY_BUFFER_ARB, size_reqd , p->vertices, GL_STATIC_DRAW_ARB );
- if( checkSizeForGraphicMemory( p ) == VBO_ERROR )
- return;
+ virtual bool HasColorAttribute() const
+ {
+ for (Standard_Integer anAttribIter = 0; anAttribIter < NbAttributes; ++anAttribIter)
+ {
+ const Graphic3d_Attribute& anAttrib = Attribs[anAttribIter];
+ if (anAttrib.Id == Graphic3d_TOA_COLOR)
+ {
+ return true;
+ }
+ }
+ return false;
}
- if( p->vcolours ){
- size_reqd = ( p->num_vertexs * sizeof( Tint ) );
- glVBOGenBuffersARB( 1, &p->bufferVBO[VBOVcolours] );
- glVBOBindBufferARB( GL_ARRAY_BUFFER_ARB, p->bufferVBO[VBOVcolours]);
- glVBOBufferDataARB( GL_ARRAY_BUFFER_ARB, size_reqd , p->vcolours, GL_STATIC_DRAW_ARB );
- if( checkSizeForGraphicMemory( p ) == VBO_ERROR )
- return;
+ virtual bool HasNormalAttribute() const
+ {
+ for (Standard_Integer anAttribIter = 0; anAttribIter < NbAttributes; ++anAttribIter)
+ {
+ const Graphic3d_Attribute& anAttrib = Attribs[anAttribIter];
+ if (anAttrib.Id == Graphic3d_TOA_NORM)
+ {
+ return true;
+ }
+ }
+ return false;
}
- if( p->vnormals ){
- size_reqd = ( p->num_vertexs * sizeof( TEL_POINT ) );
- glVBOGenBuffersARB( 1, &p->bufferVBO[VBOVnormals] );
- glVBOBindBufferARB( GL_ARRAY_BUFFER_ARB, p->bufferVBO[VBOVnormals] );
- glVBOBufferDataARB( GL_ARRAY_BUFFER_ARB, size_reqd , p->vnormals, GL_STATIC_DRAW_ARB );
- if( checkSizeForGraphicMemory( p ) == VBO_ERROR)
+ virtual void BindPositionAttribute (const Handle(OpenGl_Context)& theGlCtx) const
+ {
+ if (!TheBaseClass::IsValid())
+ {
return;
+ }
+
+ TheBaseClass::Bind (theGlCtx);
+ GLint aNbComp;
+ const GLubyte* anOffset = TheBaseClass::myOffset;
+ const Standard_Size aMuliplier = Stride != 0 ? 1 : TheBaseClass::myElemsNb;
+ for (Standard_Integer anAttribIter = 0; anAttribIter < NbAttributes; ++anAttribIter)
+ {
+ const Graphic3d_Attribute& anAttrib = Attribs[anAttribIter];
+ const GLenum aDataType = toGlDataType (anAttrib.DataType, aNbComp);
+ if (anAttrib.Id == Graphic3d_TOA_POS
+ && aDataType != GL_NONE)
+ {
+ TheBaseClass::bindAttribute (theGlCtx, Graphic3d_TOA_POS, aNbComp, aDataType, Stride, anOffset);
+ break;
+ }
+
+ anOffset += aMuliplier * Graphic3d_Attribute::Stride (anAttrib.DataType);
+ }
}
- if( p->vtexels ){
- size_reqd = ( p->num_vertexs * sizeof( TEL_TEXTURE_COORD ) );
- glVBOGenBuffersARB( 1, &p->bufferVBO[VBOVtexels] );
- glVBOBindBufferARB( GL_ARRAY_BUFFER_ARB, p->bufferVBO[VBOVtexels] );
- glVBOBufferDataARB( GL_ARRAY_BUFFER_ARB, size_reqd , p->vtexels , GL_STATIC_DRAW_ARB );
- if( checkSizeForGraphicMemory( p ) == VBO_ERROR )
+ virtual void BindAllAttributes (const Handle(OpenGl_Context)& theGlCtx) const
+ {
+ if (!TheBaseClass::IsValid())
+ {
return;
- }
+ }
- if( p->flagBufferVBO == VBO_OK )
- clearRAMMemory(p);
+ TheBaseClass::Bind (theGlCtx);
+ GLint aNbComp;
+ const GLubyte* anOffset = TheBaseClass::myOffset;
+ const Standard_Size aMuliplier = Stride != 0 ? 1 : TheBaseClass::myElemsNb;
+ for (Standard_Integer anAttribIter = 0; anAttribIter < NbAttributes; ++anAttribIter)
+ {
+ const Graphic3d_Attribute& anAttrib = Attribs[anAttribIter];
+ const GLenum aDataType = toGlDataType (anAttrib.DataType, aNbComp);
+ if (aDataType != GL_NONE)
+ {
+ TheBaseClass::bindAttribute (theGlCtx, anAttrib.Id, aNbComp, aDataType, Stride, anOffset);
+ }
+ anOffset += aMuliplier * Graphic3d_Attribute::Stride (anAttrib.DataType);
+ }
+ }
- //specify context for VBO resource
- p->contextId = (Standard_Address)GET_GL_CONTEXT();
+ virtual void UnbindAllAttributes (const Handle(OpenGl_Context)& theGlCtx) const
+ {
+ if (!TheBaseClass::IsValid())
+ {
+ return;
+ }
+ TheBaseClass::Unbind (theGlCtx);
-}
+ for (Standard_Integer anAttribIter = 0; anAttribIter < NbAttributes; ++anAttribIter)
+ {
+ const Graphic3d_Attribute& anAttrib = Attribs[anAttribIter];
+ TheBaseClass::unbindAttribute (theGlCtx, anAttrib.Id);
+ }
+ }
-/*----------------------------------------------------------------------*/
-/*
-* Constantes
-*/
-
-/*----------------------------------------------------------------------*/
-/*
-* Prototypes
-*/
-
-static TStatus ParrayDisplay( TSM_ELEM_DATA, Tint, cmn_key* );
-static TStatus ParrayAdd( TSM_ELEM_DATA, Tint, cmn_key* );
-static TStatus ParrayDelete( TSM_ELEM_DATA, Tint, cmn_key* );
-static TStatus ParrayPrint( TSM_ELEM_DATA, Tint, cmn_key* );
-static TStatus ParrayInquire( TSM_ELEM_DATA, Tint, cmn_key* );
-
-/*static GLboolean lighting_mode;*/
-
-static void draw_array(
- call_def_parray,
- Tint, /* highlight_flag */
- Tint, /* front_lighting_model, */
- Tint, /* interior_style, */
- Tint, /* edge_flag, */
- tel_colour, /* interior_colour, */
- tel_colour, /* line_colour, */
- tel_colour /* edge_colour, */
-#ifdef OCC7833
- ,tel_surf_prop
-#endif
- );
+private:
-static void draw_edges ( call_def_parray, tel_colour );
-static void draw_degenerates_as_points ( call_def_parray, tel_colour );
-static void draw_degenerates_as_lines ( call_def_parray, tel_colour );
-static void draw_degenerates_as_bboxs ( call_def_parray, tel_colour );
+ Graphic3d_Attribute Attribs[NbAttributes];
+ Standard_Integer Stride;
-static TStatus (*MtdTbl[])( TSM_ELEM_DATA, Tint, cmn_key* ) =
-{
- NULL, /* PickTraverse */
- ParrayDisplay,
- ParrayAdd,
- ParrayDelete,
- 0,
- 0
};
-static GLenum draw_mode;
-
-/*----------------------------------------------------------------------*/
-/*
-* Variables externes
-*/
-
-extern Tint ForbidSetTextureMapping; /* currently defined in tsm/tsm.c */
-
-extern int g_nDegenerateModel;
-extern float g_fSkipRatio;
-
-/*----------------------------------------------------------------------*/
-MtblPtr
-TelParrayInitClass( TelType* el )
+// =======================================================================
+// function : clearMemoryGL
+// purpose :
+// =======================================================================
+void OpenGl_PrimitiveArray::clearMemoryGL (const Handle(OpenGl_Context)& theGlCtx) const
{
- *el = TelParray;
- return MtdTbl;
-}
-
-/*----------------------------------------------------------------------*/
-
-static TStatus
-ParrayAdd( TSM_ELEM_DATA d, Tint n, cmn_key *k )
-{
-
- if( k[0]->id != PARRAY_ID ) return TFailure;
-
- ((tsm_elem_data)(d.pdata))->pdata = k[0]->data.pdata;
-
- return TSuccess;
+ if (!myVboIndices.IsNull())
+ {
+ myVboIndices->Release (theGlCtx.operator->());
+ myVboIndices.Nullify();
+ }
+ if (!myVboAttribs.IsNull())
+ {
+ myVboAttribs->Release (theGlCtx.operator->());
+ myVboAttribs.Nullify();
+ }
}
-/*----------------------------------------------------------------------*/
-
-static TStatus
-ParrayDisplay( TSM_ELEM_DATA data, Tint n, cmn_key *k )
+// =======================================================================
+// function : initNormalVbo
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_PrimitiveArray::initNormalVbo (const Handle(OpenGl_Context)& theCtx) const
{
- CMN_KEY k11, k12, k17, k18, k111, k114, k115;
-
- Tint front_lighting_model;
- Tint interior_style;
- TEL_COLOUR interior_colour;
- TEL_COLOUR edge_colour;
- TEL_COLOUR line_colour;
- Tint edge_flag;
-
-#ifdef OCC7833
- CMN_KEY k117;
- TEL_SURF_PROP prop;
-#endif
-
- call_def_parray d = (call_def_parray)data.pdata;
-
- k12.id = TelInteriorReflectanceEquation;
- k17.id = TelInteriorStyle;
- k18.id = TelEdgeFlag;
- k111.id = TelInteriorColour;
- k111.data.pdata = &interior_colour;
- k114.id = TelEdgeColour;
- k114.data.pdata = &edge_colour;
- k115.id = TelPolylineColour;
- k115.data.pdata = &line_colour;
-
-#ifdef OCC7833
- k117.id = TelSurfaceAreaProperties;
- k117.data.pdata = ∝
-#endif
-
-#ifdef OCC7833
- TsmGetAttri( 7, &k12, &k17, &k18, &k111, &k114, &k115, &k117 );
-#else
- TsmGetAttri( 6, &k12, &k17, &k18, &k111, &k114, &k115 );
-#endif
-
- front_lighting_model = k12.data.ldata;
- interior_style = k17.data.ldata;
- edge_flag = k18.data.ldata;
-
-#ifdef PRINT
- printf("ParrayDisplay type %d\n",d->type);
-#endif
-
- /*
- * Use highlight colours
- */
-
- if( k[0]->id == TOn ) {
- TEL_HIGHLIGHT hrep;
-
- k11.id = TelHighlightIndex;
- TsmGetAttri( 1, &k11 );
- if( TelGetHighlightRep( TglActiveWs, k11.data.ldata, &hrep ) == TSuccess ) {
- if( hrep.type == TelHLForcedColour ) {
- edge_colour = interior_colour = line_colour = hrep.col;
- front_lighting_model = CALL_PHIGS_REFL_NONE;
- } else if( hrep.type == TelHLColour ) {
- edge_colour = hrep.col;
- k[0]->id = TOff;
- }
- } else {
- TelGetHighlightRep( TglActiveWs, 0, &hrep );
- if( hrep.type == TelHLForcedColour ) {
- edge_colour = interior_colour = line_colour = hrep.col;
- front_lighting_model = CALL_PHIGS_REFL_NONE;
- } else if( hrep.type == TelHLColour ) {
- edge_colour = hrep.col;
- k[0]->id = TOff;
- }
- }
+ switch (myAttribs->NbAttributes)
+ {
+ case 1: myVboAttribs = new OpenGl_VertexBufferT<OpenGl_VertexBuffer, 1> (*myAttribs); break;
+ case 2: myVboAttribs = new OpenGl_VertexBufferT<OpenGl_VertexBuffer, 2> (*myAttribs); break;
+ case 3: myVboAttribs = new OpenGl_VertexBufferT<OpenGl_VertexBuffer, 3> (*myAttribs); break;
+ case 4: myVboAttribs = new OpenGl_VertexBufferT<OpenGl_VertexBuffer, 4> (*myAttribs); break;
+ case 5: myVboAttribs = new OpenGl_VertexBufferT<OpenGl_VertexBuffer, 5> (*myAttribs); break;
+ case 6: myVboAttribs = new OpenGl_VertexBufferT<OpenGl_VertexBuffer, 6> (*myAttribs); break;
+ case 7: myVboAttribs = new OpenGl_VertexBufferT<OpenGl_VertexBuffer, 7> (*myAttribs); break;
+ case 8: myVboAttribs = new OpenGl_VertexBufferT<OpenGl_VertexBuffer, 8> (*myAttribs); break;
+ case 9: myVboAttribs = new OpenGl_VertexBufferT<OpenGl_VertexBuffer, 9> (*myAttribs); break;
+ case 10: myVboAttribs = new OpenGl_VertexBufferT<OpenGl_VertexBuffer, 10>(*myAttribs); break;
}
- draw_array( d, k[0]->id,
- front_lighting_model,
- interior_style,
- edge_flag,
- &interior_colour,
- &line_colour,
- &edge_colour
-#ifdef OCC7833
- ,&prop
-#endif
- );
-
- return TSuccess;
-
-}
-
-/*----------------------------------------------------------------------*/
-
-static void
-draw_primitive_array( call_def_parray p, GLenum mode, GLint first, GLsizei count )
-{
- int i;
- glBegin( mode );
- for( i=first; i<(first + count); i++ ){
- if( p->vnormals )
- glNormal3fv( p->vnormals[i].xyz );
- if( p->vtexels && !ForbidSetTextureMapping )
- glTexCoord3fv( p->vtexels[i].xy );
- if( p->vertices )
- glVertex3fv( p->vertices[i].xyz );
- if ( p->vcolours )
- glColor4ubv( (GLubyte*) p->vcolours[i] );
+ const Standard_Boolean isAttribMutable = myAttribs->IsMutable();
+ const Standard_Boolean isAttribInterleaved = myAttribs->IsInterleaved();
+ if (myAttribs->NbElements != myAttribs->NbMaxElements()
+ && myIndices.IsNull()
+ && (!isAttribInterleaved || isAttribMutable))
+ {
+ throw Standard_ProgramError ("OpenGl_PrimitiveArray::buildVBO() - vertex attribute data with reserved size is not supported");
}
- glEnd();
-}
-/*----------------------------------------------------------------------*/
-static void
-draw_primitive_elements( call_def_parray p, GLenum mode, GLsizei count, GLenum type, GLenum *indices )
-{
- int i;
- GLenum index;
- glBegin( mode );
- for( i=0; i<count; i++ ){
- index = indices[i];
- if( p->vnormals )
- glNormal3fv( p->vnormals[index].xyz );
- if( p->vtexels && !ForbidSetTextureMapping )
- glTexCoord3fv( p->vtexels[index].xy );
- if( p->vertices )
- glVertex3fv( p->vertices[index].xyz );
- if ( p->vcolours )
- glColor4ubv( (GLubyte*) p->vcolours[index] );
+ // specify data type as Byte and NbComponents as Stride, so that OpenGl_VertexBuffer::EstimatedDataSize() will return correct value
+ const Standard_Integer aNbVertexes = (isAttribMutable || !isAttribInterleaved) ? myAttribs->NbMaxElements() : myAttribs->NbElements;
+ if (!myVboAttribs->init (theCtx, myAttribs->Stride, aNbVertexes, myAttribs->Data(), GL_UNSIGNED_BYTE, myAttribs->Stride))
+ {
+ TCollection_ExtendedString aMsg = TCollection_ExtendedString("VBO creation for Primitive Array has failed for ") + aNbVertexes + " vertices. Out of memory?";
+ theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PERFORMANCE, 0, GL_DEBUG_SEVERITY_LOW, aMsg);
+
+ clearMemoryGL (theCtx);
+ return Standard_False;
}
- glEnd();
-}
-/*----------------------------------------------------------------------*/
-static void
-draw_array( call_def_parray p, Tint hflag,
- Tint lighting_model,
- Tint interior_style,
- Tint edge_flag,
- tel_colour interior_colour,
- tel_colour line_colour,
- tel_colour edge_colour
-#ifdef OCC7833
- ,tel_surf_prop prop
-#endif
- ){
- Tint i,n;
- Tint transp = 0;
- GLint renderMode;
- /* Following pointers have been provided for performance improvement */
- tel_colour pfc;
- Tint * pvc;
-
- pvc = p->vcolours;
- pfc = p->fcolours;
-
-#ifdef OCC7833
- if( pvc ){
- for( i=0; i<p->num_vertexs; i++ ){
- transp = (int)(prop->trans * 255.);
-#if defined (sparc) || defined (__sparc__) || defined (__sparc)
- pvc[i] = ( pvc[i] & 0xffffff00 );
- pvc[i] += transp ;
-
-#else
- pvc[i] = ( pvc[i] & 0x00ffffff );
- pvc[i] += transp << 24;
-#endif
+ else if (myIndices.IsNull())
+ {
+ if (isAttribMutable && isAttribInterleaved)
+ {
+ // for mutable interlaced array we can change dynamically number of vertexes (they will be just skipped at the end of buffer);
+ // this doesn't matter in case if we have indexed array
+ myVboAttribs->SetElemsNb (myAttribs->NbElements);
}
+ return Standard_True;
}
-#endif
- switch( p->type ) {
- case TelPointsArrayType:
- draw_mode = GL_POINTS;
- glColor3fv( line_colour->rgb );
- break;
- case TelPolylinesArrayType:
- draw_mode = GL_LINE_STRIP;
- glColor3fv( line_colour->rgb );
- break;
- case TelSegmentsArrayType:
- draw_mode = GL_LINES;
- glColor3fv( line_colour->rgb );
- break;
- case TelPolygonsArrayType:
- draw_mode = GL_POLYGON;
- glColor3fv( interior_colour->rgb );
- break;
- case TelTrianglesArrayType:
- draw_mode = GL_TRIANGLES;
- glColor3fv( interior_colour->rgb );
+ const Standard_Integer aNbIndexes = !myIndices->IsMutable() ? myIndices->NbElements : myIndices->NbMaxElements();
+ myVboIndices = new OpenGl_IndexBuffer();
+ bool isOk = false;
+ switch (myIndices->Stride)
+ {
+ case 2:
+ {
+ isOk = myVboIndices->Init (theCtx, 1, aNbIndexes, reinterpret_cast<const GLushort*> (myIndices->Data()));
+ myVboIndices->SetElemsNb (myIndices->NbElements);
+ myIndices->Validate();
break;
- case TelQuadranglesArrayType:
- draw_mode = GL_QUADS;
- glColor3fv( interior_colour->rgb );
- break;
- case TelTriangleStripsArrayType:
- draw_mode = GL_TRIANGLE_STRIP;
- glColor3fv( interior_colour->rgb );
- break;
- case TelQuadrangleStripsArrayType:
- draw_mode = GL_QUAD_STRIP;
- glColor3fv( interior_colour->rgb );
- break;
- case TelTriangleFansArrayType:
- draw_mode = GL_TRIANGLE_FAN;
- glColor3fv( interior_colour->rgb );
+ }
+ case 4:
+ {
+ isOk = myVboIndices->Init (theCtx, 1, aNbIndexes, reinterpret_cast<const GLuint*> (myIndices->Data()));
+ myVboIndices->SetElemsNb (myIndices->NbElements);
+ myIndices->Validate();
break;
+ }
default:
- return;
+ {
+ clearMemoryGL (theCtx);
+ return Standard_False;
+ }
}
-
- /* OCC11904 -- Temporarily disable environment mapping */
- if( draw_mode <= GL_LINE_STRIP ){
- glPushAttrib(GL_ENABLE_BIT);
- glDisable(GL_TEXTURE_1D);
- glDisable(GL_TEXTURE_2D);
+ if (!isOk)
+ {
+ TCollection_ExtendedString aMsg = TCollection_ExtendedString("VBO creation for Primitive Array has failed for ") + aNbIndexes + " indices. Out of memory?";
+ theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PERFORMANCE, 0, GL_DEBUG_SEVERITY_LOW, aMsg);
+ clearMemoryGL (theCtx);
+ return Standard_False;
}
+ return Standard_True;
+}
- if( p->VBOEnabled == -1 ){
- p->VBOEnabled = VBOenabled;
- if( VBOExtension == 0)
- initVBO();
- if( (VBOExtension == 1) && (p->VBOEnabled != 0))
- BuildVBO( p );
+// =======================================================================
+// function : buildVBO
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_PrimitiveArray::buildVBO (const Handle(OpenGl_Context)& theCtx,
+ const Standard_Boolean theToKeepData) const
+{
+ bool isNormalMode = theCtx->ToUseVbo();
+ clearMemoryGL (theCtx);
+ if (myAttribs.IsNull()
+ || myAttribs->IsEmpty()
+ || myAttribs->NbElements < 1
+ || myAttribs->NbAttributes < 1
+ || myAttribs->NbAttributes > 10)
+ {
+ // vertices should be always defined - others are optional
+ return Standard_False;
}
-
- #ifdef PRINT
- printf(" $$$ g_nDegenerateModel %d\n",g_nDegenerateModel);
- #endif
- if ( g_nDegenerateModel < 2 &&
- ( (draw_mode > GL_LINE_STRIP && interior_style != TSM_EMPTY) ||
- (draw_mode <= GL_LINE_STRIP /*&& !hflag*/)) ) {
-
- if( hflag == TOn ) {
- pfc = NULL;
- pvc = NULL;
+ if (isNormalMode
+ && initNormalVbo (theCtx))
+ {
+ if (!theCtx->caps->keepArrayData
+ && !theToKeepData
+ && !myAttribs->IsMutable())
+ {
+ myIndices.Nullify();
+ myAttribs.Nullify();
}
-
- if ( interior_style == TSM_HIDDENLINE) {
- edge_flag = 1;
- pfc = NULL;
- pvc = NULL;
+ else
+ {
+ myAttribs->Validate();
}
+ return Standard_True;
+ }
- /*OCC12297 - Sometimes the GL_LIGHTING mode is activated here
- without LightOn() call for an unknown reason, so it is necessary
- to call LightOn() to synchronize LightOn/Off mechanism*/
- LightOn();
-
- if( lighting_model == CALL_PHIGS_REFL_NONE || draw_mode <= GL_LINE_STRIP )
- LightOff();
-
- glGetIntegerv( GL_RENDER_MODE, &renderMode );
-
- if ( p->num_vertexs > 0 && p->flagBufferVBO != VBO_OK) {
- if( renderMode != GL_FEEDBACK ){
- if( p->vertices ) {
- glVertexPointer(3, GL_FLOAT, 0, p->vertices);/* array of vertices */
- glEnableClientState(GL_VERTEX_ARRAY);
- }
-
- if( p->vnormals ) {
- glNormalPointer(GL_FLOAT, 0, p->vnormals);/* array of normals */
- glEnableClientState(GL_NORMAL_ARRAY);
- }
-
- if ( p->vtexels) {
- glTexCoordPointer(2, GL_FLOAT, 0, p->vtexels);/* array of texture coordinates */
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- }
-
- if ( pvc ) {
-#ifdef OCC7833
- glColorPointer(4, GL_UNSIGNED_BYTE, 0, pvc); /* array of colors */
-#else
- glColorPointer(3, GL_UNSIGNED_BYTE, 0, pvc); /* array of colors */
-#endif
- glEnableClientState(GL_COLOR_ARRAY);
- glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
- glEnable(GL_COLOR_MATERIAL);
- }
- }
- }
-
- //Bindings concrete pointer in accordance with VBO buffer
- //Using VBO
- if ( p->num_vertexs > 0 && p->flagBufferVBO == VBO_OK ) {
- if( p->bufferVBO[VBOVertices] ){
- glVBOBindBufferARB( GL_ARRAY_BUFFER_ARB, p->bufferVBO[VBOVertices]);
- glVertexPointer(3, GL_FLOAT, 0, (char *) NULL);// array of vertices
- glEnableClientState(GL_VERTEX_ARRAY);
- }
-
- if( p->bufferVBO[VBOVnormals] ){
- glVBOBindBufferARB( GL_ARRAY_BUFFER_ARB, p->bufferVBO[VBOVnormals]);
- glNormalPointer(GL_FLOAT, 0, (char *) NULL);// array of normals
- glEnableClientState(GL_NORMAL_ARRAY);
- }
-
- if ( p->bufferVBO[VBOVtexels] && !ForbidSetTextureMapping ) {
- glVBOBindBufferARB( GL_ARRAY_BUFFER_ARB, p->bufferVBO[VBOVtexels]);
- glTexCoordPointer(2, GL_FLOAT, 0, (char *) NULL);/* array of texture coordinates */
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- }
-
- if ( p->bufferVBO[VBOVcolours] ) {
- glVBOBindBufferARB( GL_ARRAY_BUFFER_ARB, p->bufferVBO[VBOVcolours]);
- glColorPointer( 4, GL_UNSIGNED_BYTE, 0, (char *) NULL);// array of colors
- glEnableClientState(GL_COLOR_ARRAY);
- glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
- glEnable(GL_COLOR_MATERIAL);
+ Handle(OpenGl_VertexBufferCompat) aVboAttribs;
+ switch (myAttribs->NbAttributes)
+ {
+ case 1: aVboAttribs = new OpenGl_VertexBufferT<OpenGl_VertexBufferCompat, 1> (*myAttribs); break;
+ case 2: aVboAttribs = new OpenGl_VertexBufferT<OpenGl_VertexBufferCompat, 2> (*myAttribs); break;
+ case 3: aVboAttribs = new OpenGl_VertexBufferT<OpenGl_VertexBufferCompat, 3> (*myAttribs); break;
+ case 4: aVboAttribs = new OpenGl_VertexBufferT<OpenGl_VertexBufferCompat, 4> (*myAttribs); break;
+ case 5: aVboAttribs = new OpenGl_VertexBufferT<OpenGl_VertexBufferCompat, 5> (*myAttribs); break;
+ case 6: aVboAttribs = new OpenGl_VertexBufferT<OpenGl_VertexBufferCompat, 6> (*myAttribs); break;
+ case 7: aVboAttribs = new OpenGl_VertexBufferT<OpenGl_VertexBufferCompat, 7> (*myAttribs); break;
+ case 8: aVboAttribs = new OpenGl_VertexBufferT<OpenGl_VertexBufferCompat, 8> (*myAttribs); break;
+ case 9: aVboAttribs = new OpenGl_VertexBufferT<OpenGl_VertexBufferCompat, 9> (*myAttribs); break;
+ case 10: aVboAttribs = new OpenGl_VertexBufferT<OpenGl_VertexBufferCompat, 10>(*myAttribs); break;
+ }
+ aVboAttribs->initLink (myAttribs, 0, myAttribs->NbElements, GL_NONE);
+ if (!myIndices.IsNull())
+ {
+ Handle(OpenGl_VertexBufferCompat) aVboIndices = new OpenGl_VertexBufferCompat();
+ switch (myIndices->Stride)
+ {
+ case 2:
+ {
+ aVboIndices->initLink (myIndices, 1, myIndices->NbElements, GL_UNSIGNED_SHORT);
+ break;
}
- }
- // OCC22236 NOTE: draw for all situations:
- // 1) draw elements from p->bufferVBO[VBOEdges] indicies array
- // 2) draw elements from vertice array, when bounds defines count of primitive's verts.
- //end bindings
- if( p->flagBufferVBO == VBO_OK ){
- if ( p->num_edges > 0 && p->bufferVBO[VBOEdges] ) {
- glVBOBindBufferARB(GL_ELEMENTS_ARRAY_BUFFER_ARB, p->bufferVBO[VBOEdges]); // for edge indices
- glDrawElements( draw_mode, p->num_edges , GL_UNSIGNED_INT, 0);
+ case 4:
+ {
+ aVboIndices->initLink (myIndices, 1, myIndices->NbElements, GL_UNSIGNED_INT);
+ break;
}
- else {
- for( i = n = 0 ; i < p->num_bounds ; i ++ ){
- glDrawArrays( draw_mode, n, p->bounds[i]);
- n += p->bounds[i];
- }
+ default:
+ {
+ return Standard_False;
}
- //bind with 0
- glVBOBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
- glVBOBindBufferARB(GL_ELEMENTS_ARRAY_BUFFER_ARB, 0);
- }
- else {
- if( p->num_bounds > 0 ) {
- if( p->num_edges > 0 ) {
- for( i=n=0 ; i<p->num_bounds ; i++ ) {
- if( pfc ) glColor3fv ( pfc[i].rgb );
- if( renderMode == GL_FEEDBACK )
- draw_primitive_elements( p, draw_mode, p->bounds[i],
- GL_UNSIGNED_INT,(GLenum*) &p->edges[n]);
- else
- glDrawElements( draw_mode, p->bounds[i],
- GL_UNSIGNED_INT, &p->edges[n]);
- n += p->bounds[i];
- }
- } else {
- for( i=n=0 ; i<p->num_bounds ; i++ ) {
- if( pfc )
- glColor3fv ( pfc[i].rgb );
- if( renderMode == GL_FEEDBACK )
- draw_primitive_array( p, draw_mode, n, p->bounds[i]);
- else
- {
- glDrawArrays( draw_mode, n, p->bounds[i]);
- }
- n += p->bounds[i];
- }
- }
- } else if( p->num_edges > 0 ) {
- if( renderMode == GL_FEEDBACK )
- draw_primitive_elements( p, draw_mode, p->num_edges,
- GL_UNSIGNED_INT,(GLenum*) &p->edges[0]);
- else
- glDrawElements( draw_mode, p->num_edges, GL_UNSIGNED_INT, p->edges);
- } else {
- if( renderMode == GL_FEEDBACK )
- draw_primitive_array( p, draw_mode, 0, p->num_vertexs);
- else
- glDrawArrays( draw_mode, 0, p->num_vertexs);
- }
- }
-
-#ifdef TEST
- if( p->bufferVBO[VBOVcolours] || pvc ) {
- glDisable(GL_COLOR_MATERIAL);
- TelResetMaterial();
- }
-#endif
-
- if( p->bufferVBO[VBOVertices] || p->vertices )
- glDisableClientState(GL_VERTEX_ARRAY);
- if( p->bufferVBO[VBOVcolours] || p->vcolours )
- glDisableClientState(GL_COLOR_ARRAY);
- if( p->bufferVBO[VBOVnormals] || p->vnormals )
- glDisableClientState(GL_NORMAL_ARRAY);
- if ( (p->bufferVBO[VBOVtexels] && !ForbidSetTextureMapping ) || p->vtexels )
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-
- if ( g_nDegenerateModel ){
- if(draw_mode <= GL_LINE_STRIP)
- glPopAttrib();
- return;
}
+ myVboIndices = aVboIndices;
+ }
+ myVboAttribs = aVboAttribs;
+ if (!theCtx->caps->keepArrayData
+ && !theToKeepData)
+ {
+ // does not make sense for compatibility mode
+ //myIndices.Nullify();
+ //myAttribs.Nullify();
}
- if( edge_flag || g_nDegenerateModel )
- switch ( g_nDegenerateModel ) {
- default: /* XXX_TDM_NODE or TINY */
- /*
- On some NVIDIA graphic cards, using glEdgeFlagPointer() in
- combination with VBO ( edge flag data put into a VBO buffer)
- leads to a crash in a driver. Therefore, edge flags are simply
- igonored when VBOs are enabled, so all the edges are drawn if
- edge visibility is turned on. In order to draw edges selectively,
- either disable VBO or turn off edge visibilty in the current
- primitive array and create a separate primitive array (segments)
- and put edges to be drawn into it.
- */
- draw_edges ( p, edge_flag ? edge_colour : interior_colour );
- break;
- // DegenerateModel(as Lines, Points, BBoxs) are used only without VBO
- case 2: /* XXX_TDM_WIREFRAME */
- if( p->VBOEnabled == 0 )
- draw_degenerates_as_lines ( p, edge_flag ? edge_colour : interior_colour );
- break;
- case 3: /* XXX_TDM_MARKER */
- if( p->VBOEnabled == 0 )
- draw_degenerates_as_points ( p, edge_flag ? edge_colour : interior_colour );
- break;
- case 4: /* XXX_TDM_BBOX */
- if( p->VBOEnabled == 0 )
- draw_degenerates_as_bboxs ( p, edge_flag ? edge_colour : interior_colour );
- break;
- }
-
- if(draw_mode <= GL_LINE_STRIP)
- glPopAttrib();
+ return Standard_True;
}
-/*----------------------------------------------------------------------*/
-
-static TStatus
-ParrayDelete( TSM_ELEM_DATA data, Tint n, cmn_key *k )
+// =======================================================================
+// function : updateVBO
+// purpose :
+// =======================================================================
+void OpenGl_PrimitiveArray::updateVBO (const Handle(OpenGl_Context)& theCtx) const
{
- call_def_parray p = (call_def_parray)data.pdata;
- if( p->VBOEnabled == VBO_OK ) {
- OpenGl_ResourceCleaner* resCleaner = OpenGl_ResourceCleaner::GetInstance();
- if( p->bufferVBO[VBOEdges] )
- resCleaner->AddResource( (GLCONTEXT)p->contextId, new OpenGl_ResourceVBO(p->bufferVBO[VBOEdges]) );
- if( p->bufferVBO[VBOVertices] )
- resCleaner->AddResource( (GLCONTEXT)p->contextId, new OpenGl_ResourceVBO(p->bufferVBO[VBOVertices]) );
- if( p->bufferVBO[VBOVcolours] )
- resCleaner->AddResource( (GLCONTEXT)p->contextId, new OpenGl_ResourceVBO(p->bufferVBO[VBOVcolours]) );
- if( p->bufferVBO[VBOVnormals] )
- resCleaner->AddResource( (GLCONTEXT)p->contextId, new OpenGl_ResourceVBO(p->bufferVBO[VBOVnormals]) );
- if( p->bufferVBO[VBOVtexels] )
- resCleaner->AddResource( (GLCONTEXT)p->contextId, new OpenGl_ResourceVBO(p->bufferVBO[VBOVtexels]) );
+ if (!myAttribs.IsNull())
+ {
+ Graphic3d_BufferRange aRange = myAttribs->InvalidatedRange();
+ if (!aRange.IsEmpty()
+ && myVboAttribs->IsValid()
+ && !myVboAttribs->IsVirtual())
+ {
+ myVboAttribs->Bind (theCtx);
+ theCtx->core15fwd->glBufferSubData (myVboAttribs->GetTarget(),
+ aRange.Start,
+ aRange.Length,
+ myAttribs->Data() + aRange.Start);
+ myVboAttribs->Unbind (theCtx);
+ if (myAttribs->IsInterleaved())
+ {
+ myVboAttribs->SetElemsNb (myAttribs->NbElements);
+ }
+ }
+ myAttribs->Validate();
+ }
+ if (!myIndices.IsNull())
+ {
+ Graphic3d_BufferRange aRange = myIndices->InvalidatedRange();
+ if (!aRange.IsEmpty()
+ && myVboIndices->IsValid()
+ && !myVboIndices->IsVirtual())
+ {
+ myVboIndices->Bind (theCtx);
+ theCtx->core15fwd->glBufferSubData (myVboIndices->GetTarget(),
+ aRange.Start,
+ aRange.Length,
+ myIndices->Data() + aRange.Start);
+ myVboIndices->Unbind (theCtx);
+ myVboIndices->SetElemsNb (myIndices->NbElements);
+ }
+ myIndices->Validate();
}
-
- return TSuccess;
}
-/*----------------------------------------------------------------------*/
-
-static void
-draw_edges ( call_def_parray p, tel_colour edge_colour )
+// =======================================================================
+// function : drawArray
+// purpose :
+// =======================================================================
+void OpenGl_PrimitiveArray::drawArray (const Handle(OpenGl_Workspace)& theWorkspace,
+ const Graphic3d_Vec4* theFaceColors,
+ const Standard_Boolean theHasVertColor) const
{
- Tint i, j, n;
- Tint edge_type=0, line_type_preserve=0;
- Tfloat edge_width=0, line_width_preserve=0;
- /* GLboolean texture_on;*/
-
- GLint renderMode;
-
- LightOff();
-
- if( draw_mode > GL_LINE_STRIP ) {
- CMN_KEY k, k1, k2, k3, k4;
-
- k1.id = TelPolylineWidth;
- k2.id = TelPolylineType;
- k3.id = TelEdgeType;
- k4.id = TelEdgeWidth;
-
- TsmGetAttri( 4, &k1, &k2, &k3, &k4 );
-
- line_width_preserve = k1.data.fdata;
- line_type_preserve = k2.data.ldata;
- edge_type = k3.data.ldata;
- edge_width = k4.data.fdata;
-
- if( line_width_preserve != edge_width ) {
- k.id = TelPolylineWidth;
- k.data.fdata = edge_width;
- TsmSetAttri( 1, &k );
- }
- if( line_type_preserve != edge_type ) {
- k.id = TelPolylineType;
- k.data.ldata = edge_type;
- TsmSetAttri( 1, &k );
+ if (myVboAttribs.IsNull())
+ {
+ #if !defined(GL_ES_VERSION_2_0)
+ if (myDrawMode == GL_POINTS)
+ {
+ // extreme compatibility mode - without sprites but with markers
+ drawMarkers (theWorkspace);
}
-
- glPushAttrib( GL_POLYGON_BIT );
- glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
+ #endif
+ return;
}
- // OCC22236 NOTE: draw edges for all situations:
- // 1) draw elements with GL_LINE style as edges from p->bufferVBO[VBOEdges] indicies array
- // 2) draw elements with GL_LINE style as edges from vertice array,
- // when bounds defines count of primitive's verts.
- if(p->flagBufferVBO == VBO_OK)
- {
- glVBOBindBufferARB( GL_ARRAY_BUFFER_ARB, p->bufferVBO[VBOVertices] );
- glEnableClientState( GL_VERTEX_ARRAY );
- glColor3fv( edge_colour->rgb );
- if ( p->num_edges > 0 && p->bufferVBO[VBOEdges] ) {
- glVBOBindBufferARB(GL_ELEMENTS_ARRAY_BUFFER_ARB, p->bufferVBO[VBOEdges]);
- glDrawElements( draw_mode, p->num_edges, GL_UNSIGNED_INT, 0);
- }
- else {
- for( i = n = 0 ; i < p->num_bounds ; i ++ ) {
- glDrawArrays( draw_mode , n , p->bounds[i]);
- n += p->bounds[i];
+ const Handle(OpenGl_Context)& aGlContext = theWorkspace->GetGlContext();
+ const bool toHilight = theWorkspace->ToHighlight();
+ const GLenum aDrawMode = !aGlContext->ActiveProgram().IsNull()
+ && aGlContext->ActiveProgram()->HasTessellationStage()
+ ? GL_PATCHES
+ : myDrawMode;
+ myVboAttribs->BindAllAttributes (aGlContext);
+ if (theHasVertColor && toHilight)
+ {
+ // disable per-vertex color
+ OpenGl_VertexBuffer::unbindAttribute (aGlContext, Graphic3d_TOA_COLOR);
+ }
+ if (!myVboIndices.IsNull())
+ {
+ myVboIndices->Bind (aGlContext);
+ GLubyte* anOffset = myVboIndices->GetDataOffset();
+ if (!myBounds.IsNull())
+ {
+ // draw primitives by vertex count with the indices
+ const size_t aStride = myVboIndices->GetDataType() == GL_UNSIGNED_SHORT ? sizeof(unsigned short) : sizeof(unsigned int);
+ for (Standard_Integer aGroupIter = 0; aGroupIter < myBounds->NbBounds; ++aGroupIter)
+ {
+ const GLint aNbElemsInGroup = myBounds->Bounds[aGroupIter];
+ if (theFaceColors != NULL) aGlContext->SetColor4fv (theFaceColors[aGroupIter]);
+ glDrawElements (aDrawMode, aNbElemsInGroup, myVboIndices->GetDataType(), anOffset);
+ anOffset += aStride * aNbElemsInGroup;
}
}
- glDisableClientState(GL_VERTEX_ARRAY);
- glVBOBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
- glVBOBindBufferARB(GL_ELEMENTS_ARRAY_BUFFER_ARB, 0);
+ else
+ {
+ // draw one (or sequential) primitive by the indices
+ glDrawElements (aDrawMode, myVboIndices->GetElemsNb(), myVboIndices->GetDataType(), anOffset);
+ }
+ myVboIndices->Unbind (aGlContext);
}
- else {
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(3, GL_FLOAT, 0, p->vertices); /* array of vertices */
-#ifdef OGLBUG
- if( p->edge_vis ) {
- glEnableClientState(GL_EDGE_FLAG_ARRAY);
- glEdgeFlagPointer( sizeof(Tchar), p->edge_vis);
- } else
- glDisableClientState(GL_EDGE_FLAG_ARRAY);
-#endif
-
- glGetIntegerv( GL_RENDER_MODE, &renderMode );
-
- glColor3fv( edge_colour->rgb );
- if( p->num_bounds > 0 ) {
- if( p->num_edges > 0 ) {
- for( i=n=0 ; i<p->num_bounds ; i++ ) {
-#ifndef OGLBUG
- if( p->edge_vis ) {
- glBegin( draw_mode );
- for( j=0 ; j<p->bounds[i] ; j++ ) {
- glEdgeFlag( p->edge_vis[n+j] );
- glVertex3fv( &p->vertices[p->edges[n+j]].xyz[0] );
- }
- glEnd();
- } else
-#endif
- if( renderMode == GL_FEEDBACK )
- draw_primitive_elements( p, draw_mode, p->bounds[i],
- GL_UNSIGNED_INT, (GLenum*)&p->edges[n]);
- else
- glDrawElements( draw_mode, p->bounds[i],
- GL_UNSIGNED_INT, &p->edges[n]);
- n += p->bounds[i];
- }
- } else {
- for( i=n=0 ; i<p->num_bounds ; i++ ) {
- if( renderMode == GL_FEEDBACK )
- draw_primitive_array( p, draw_mode, n, p->bounds[i]);
- else
- glDrawArrays( draw_mode, n, p->bounds[i]);
- n += p->bounds[i];
- }
- }
- }
- else if( p->num_edges > 0 ) {
-#ifndef OGLBUG
- if( p->edge_vis ) {
- glBegin( draw_mode );
- for( i=0 ; i<p->num_edges ; i++ ) {
- glEdgeFlag( p->edge_vis[i] );
- glVertex3fv( &p->vertices[p->edges[i]].xyz[0] );
- }
- glEnd();
- } else
-#endif
- if( renderMode == GL_FEEDBACK )
- draw_primitive_elements( p, draw_mode, p->num_edges,
- GL_UNSIGNED_INT,(GLenum*) p->edges);
- else
- glDrawElements( draw_mode, p->num_edges,
- GL_UNSIGNED_INT, p->edges);
- } else {
- if( renderMode == GL_FEEDBACK )
- draw_primitive_array( p, draw_mode, 0, p->num_vertexs);
- else
- glDrawArrays( draw_mode, 0, p->num_vertexs);
- }
+ else if (!myBounds.IsNull())
+ {
+ GLint aFirstElem = 0;
+ for (Standard_Integer aGroupIter = 0; aGroupIter < myBounds->NbBounds; ++aGroupIter)
+ {
+ const GLint aNbElemsInGroup = myBounds->Bounds[aGroupIter];
+ if (theFaceColors != NULL) aGlContext->SetColor4fv (theFaceColors[aGroupIter]);
+ glDrawArrays (aDrawMode, aFirstElem, aNbElemsInGroup);
+ aFirstElem += aNbElemsInGroup;
}
-
- if( draw_mode > GL_LINE_STRIP ) {
- CMN_KEY k;
- if( line_width_preserve != edge_width ) {
- k.id = TelPolylineWidth;
- k.data.fdata = line_width_preserve;
- TsmSetAttri( 1, &k );
+ }
+ else
+ {
+ if (myDrawMode == GL_POINTS)
+ {
+ drawMarkers (theWorkspace);
}
- if( line_type_preserve != edge_type ) {
- k.id = TelPolylineType;
- k.data.ldata = line_type_preserve;
- TsmSetAttri( 1, &k );
+ else
+ {
+ glDrawArrays (aDrawMode, 0, myVboAttribs->GetElemsNb());
}
- glPopAttrib();
}
-}
-
-/*----------------------------------------------------------------------*/
-static void draw_degenerates_points_as_points ( call_def_parray p ) {
- Tint j;
- tel_point pv = p -> vertices;
+ // bind with 0
+ myVboAttribs->UnbindAllAttributes (aGlContext);
+}
-#ifdef FULL_DEGENER
- if ( g_fSkipRatio == 1. )
+// =======================================================================
+// function : drawEdges
+// purpose :
+// =======================================================================
+void OpenGl_PrimitiveArray::drawEdges (const Handle(OpenGl_Workspace)& theWorkspace) const
+{
+ const Handle(OpenGl_Context)& aGlContext = theWorkspace->GetGlContext();
+ if (myVboAttribs.IsNull())
+ {
return;
-#endif
-
- for ( j=0 ; j<p->num_vertexs ; j++ ) {
- glVertex3fv ( &pv[j].xyz[0] );
}
-}
-
-/*----------------------------------------------------------------------*/
-static void draw_degenerates_lines_as_points ( call_def_parray p ) {
-
- Tint j;
- GLfloat pt[ 3 ];
- tel_point pv = p -> vertices;
-#ifdef FULL_DEGENER
- if ( g_fSkipRatio == 1. )
- return;
+ const OpenGl_Aspects* anAspect = theWorkspace->Aspects();
+#if !defined(GL_ES_VERSION_2_0)
+ const Standard_Integer aPolyModeOld = aGlContext->SetPolygonMode (GL_LINE);
#endif
- for ( j=0 ; j<p->num_vertexs ; j+=2 ) {
- pt[0] = pt[1] = pt[2] = 0.;
- pt[ 0 ] += pv[j].xyz[ 0 ];
- pt[ 1 ] += pv[j].xyz[ 1 ];
- pt[ 2 ] += pv[j].xyz[ 2 ];
- pt[ 0 ] += pv[j+1].xyz[ 0 ];
- pt[ 1 ] += pv[j+1].xyz[ 1 ];
- pt[ 2 ] += pv[j+1].xyz[ 2 ];
- pt[ 0 ] /= 2;
- pt[ 1 ] /= 2;
- pt[ 2 ] /= 2;
- glVertex3fv ( pt );
+ if (aGlContext->core20fwd != NULL)
+ {
+ aGlContext->ShaderManager()->BindLineProgram (Handle(OpenGl_TextureSet)(), anAspect->Aspect()->EdgeLineType(),
+ Graphic3d_TOSM_UNLIT, Graphic3d_AlphaMode_Opaque, Standard_False,
+ anAspect->ShaderProgramRes (aGlContext));
+ }
+ aGlContext->SetSampleAlphaToCoverage (aGlContext->ShaderManager()->MaterialState().HasAlphaCutoff());
+ const GLenum aDrawMode = !aGlContext->ActiveProgram().IsNull()
+ && aGlContext->ActiveProgram()->HasTessellationStage()
+ ? GL_PATCHES
+ : myDrawMode;
+#if !defined(GL_ES_VERSION_2_0)
+ if (aGlContext->ActiveProgram().IsNull()
+ && aGlContext->core11 != NULL)
+ {
+ glDisable (GL_LIGHTING);
}
-}
-
-/*----------------------------------------------------------------------*/
-static void draw_degenerates_triangles_as_points ( call_def_parray p ) {
-
- Tint i, j, iv;
- GLfloat pt[ 3 ];
- tel_point pv = p -> vertices;
-
-#ifdef FULL_DEGENER
- if ( g_fSkipRatio == 1. )
- return;
#endif
- if( p->num_edges > 0 ) {
- for ( j=0 ; j<p->num_edges ; j+=3 ) {
- pt[0] = pt[1] = pt[2] = 0.;
- for ( i=0 ; i<3 ; i++ ) {
- iv = p->edges[j+i];
- pt[ 0 ] += pv[iv].xyz[ 0 ];
- pt[ 1 ] += pv[iv].xyz[ 1 ];
- pt[ 2 ] += pv[iv].xyz[ 2 ];
+ /// OCC22236 NOTE: draw edges for all situations:
+ /// 1) draw elements with GL_LINE style as edges from myPArray->bufferVBO[VBOEdges] indices array
+ /// 2) draw elements from vertex array, when bounds defines count of primitive's vertices.
+ /// 3) draw primitive's edges by vertexes if no edges and bounds array is specified
+ myVboAttribs->BindPositionAttribute (aGlContext);
+
+ aGlContext->SetColor4fv (theWorkspace->EdgeColor().a() >= 0.1f
+ ? theWorkspace->EdgeColor()
+ : theWorkspace->View()->BackgroundColor());
+ aGlContext->SetTypeOfLine (anAspect->Aspect()->EdgeLineType());
+ aGlContext->SetLineWidth (anAspect->Aspect()->EdgeWidth());
+
+ if (!myVboIndices.IsNull())
+ {
+ myVboIndices->Bind (aGlContext);
+ GLubyte* anOffset = myVboIndices->GetDataOffset();
+
+ // draw primitives by vertex count with the indices
+ if (!myBounds.IsNull())
+ {
+ const size_t aStride = myVboIndices->GetDataType() == GL_UNSIGNED_SHORT ? sizeof(unsigned short) : sizeof(unsigned int);
+ for (Standard_Integer aGroupIter = 0; aGroupIter < myBounds->NbBounds; ++aGroupIter)
+ {
+ const GLint aNbElemsInGroup = myBounds->Bounds[aGroupIter];
+ glDrawElements (aDrawMode, aNbElemsInGroup, myVboIndices->GetDataType(), anOffset);
+ anOffset += aStride * aNbElemsInGroup;
}
- pt[ 0 ] /= 3;
- pt[ 1 ] /= 3;
- pt[ 2 ] /= 3;
- glVertex3fv ( pt );
}
- } else {
- for ( j=0 ; j<p->num_vertexs ; j+=3 ) {
- pt[0] = pt[1] = pt[2] = 0.;
- for ( i=0 ; i<3 ; i++ ) {
- pt[ 0 ] += pv[j+i].xyz[ 0 ];
- pt[ 1 ] += pv[j+i].xyz[ 1 ];
- pt[ 2 ] += pv[j+i].xyz[ 2 ];
- }
- pt[ 0 ] /= 3;
- pt[ 1 ] /= 3;
- pt[ 2 ] /= 3;
- glVertex3fv ( pt );
+ // draw one (or sequential) primitive by the indices
+ else
+ {
+ glDrawElements (aDrawMode, myVboIndices->GetElemsNb(), myVboIndices->GetDataType(), anOffset);
}
+ myVboIndices->Unbind (aGlContext);
+ }
+ else if (!myBounds.IsNull())
+ {
+ GLint aFirstElem = 0;
+ for (Standard_Integer aGroupIter = 0; aGroupIter < myBounds->NbBounds; ++aGroupIter)
+ {
+ const GLint aNbElemsInGroup = myBounds->Bounds[aGroupIter];
+ glDrawArrays (aDrawMode, aFirstElem, aNbElemsInGroup);
+ aFirstElem += aNbElemsInGroup;
+ }
+ }
+ else
+ {
+ glDrawArrays (aDrawMode, 0, !myVboAttribs.IsNull() ? myVboAttribs->GetElemsNb() : myAttribs->NbElements);
}
-}
-
-/*----------------------------------------------------------------------*/
-static void draw_degenerates_trianglestrips_as_points ( call_def_parray p ) {
- Tint i, j, k, n;
- GLfloat pt[ 3 ];
- tel_point pv = p -> vertices;
+ // unbind buffers
+ myVboAttribs->UnbindAttribute (aGlContext, Graphic3d_TOA_POS);
-#ifdef FULL_DEGENER
- if ( g_fSkipRatio == 1. )
- return;
+ // restore line context
+#if !defined(GL_ES_VERSION_2_0)
+ aGlContext->SetPolygonMode (aPolyModeOld);
#endif
+}
- if( p->num_bounds > 0 ) {
- for ( k=n=0 ; k<p->num_bounds ; k++ ) {
- for ( j=0 ; j<p->bounds[k]-2 ; j++ ) {
- pt[0] = pt[1] = pt[2] = 0.;
- for ( i=0 ; i<3 ; i++ ) {
- pt[ 0 ] += pv[n+j+i].xyz[ 0 ];
- pt[ 1 ] += pv[n+j+i].xyz[ 1 ];
- pt[ 2 ] += pv[n+j+i].xyz[ 2 ];
- }
- pt[ 0 ] /= 3;
- pt[ 1 ] /= 3;
- pt[ 2 ] /= 3;
- glVertex3fv ( pt );
- }
- n += p->bounds[k];
- }
- } else {
- for ( j=0 ; j<p->num_vertexs-2 ; j++ ) {
- pt[0] = pt[1] = pt[2] = 0.;
- for ( i=0 ; i<3 ; i++ ) {
- pt[ 0 ] += pv[j+i].xyz[ 0 ];
- pt[ 1 ] += pv[j+i].xyz[ 1 ];
- pt[ 2 ] += pv[j+i].xyz[ 2 ];
- }
- pt[ 0 ] /= 3;
- pt[ 1 ] /= 3;
- pt[ 2 ] /= 3;
- glVertex3fv ( pt );
+// =======================================================================
+// function : drawMarkers
+// purpose :
+// =======================================================================
+void OpenGl_PrimitiveArray::drawMarkers (const Handle(OpenGl_Workspace)& theWorkspace) const
+{
+ const OpenGl_Aspects* anAspectMarker = theWorkspace->Aspects();
+ const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
+ const GLenum aDrawMode = !aCtx->ActiveProgram().IsNull()
+ && aCtx->ActiveProgram()->HasTessellationStage()
+ ? GL_PATCHES
+ : myDrawMode;
+ if (anAspectMarker->HasPointSprite (aCtx))
+ {
+ // Textured markers will be drawn with the point sprites
+ aCtx->SetPointSize (anAspectMarker->MarkerSize());
+ aCtx->SetPointSpriteOrigin();
+ #if !defined(GL_ES_VERSION_2_0)
+ if (aCtx->core11 != NULL)
+ {
+ aCtx->core11fwd->glEnable (GL_ALPHA_TEST);
+ aCtx->core11fwd->glAlphaFunc (GL_GEQUAL, 0.1f);
}
- }
-}
-
-/*----------------------------------------------------------------------*/
-static void draw_degenerates_polygons_as_points ( call_def_parray p ) {
+ #endif
- Tint j, k, n, iv;
- GLfloat pt[ 3 ];
- tel_point pv = p -> vertices;
+ aCtx->core11fwd->glEnable (GL_BLEND);
+ aCtx->core11fwd->glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-#ifdef FULL_DEGENER
- if ( g_fSkipRatio == 1. )
- return;
-#endif
+ aCtx->core11fwd->glDrawArrays (aDrawMode, 0, !myVboAttribs.IsNull() ? myVboAttribs->GetElemsNb() : myAttribs->NbElements);
- if( p->num_bounds > 0 ) {
- if( p->num_edges > 0 ) {
- for ( k=n=0 ; k<p->num_bounds ; k++ ) {
- pt[0] = pt[1] = pt[2] = 0.;
- for ( j=0 ; j<p->bounds[k] ; j++ ) {
- iv = p->edges[n+j];
- pt[ 0 ] += pv[iv].xyz[ 0 ];
- pt[ 1 ] += pv[iv].xyz[ 1 ];
- pt[ 2 ] += pv[iv].xyz[ 2 ];
- }
- pt[ 0 ] /= p->bounds[k];
- pt[ 1 ] /= p->bounds[k];
- pt[ 2 ] /= p->bounds[k];
- glVertex3fv ( pt );
- n += p->bounds[k];
+ aCtx->core11fwd->glDisable (GL_BLEND);
+ #if !defined(GL_ES_VERSION_2_0)
+ if (aCtx->core11 != NULL)
+ {
+ if (aCtx->ShaderManager()->MaterialState().AlphaCutoff() >= ShortRealLast())
+ {
+ aCtx->core11fwd->glDisable (GL_ALPHA_TEST);
}
- } else {
- for ( k=n=0 ; k<p->num_bounds ; k++ ) {
- pt[0] = pt[1] = pt[2] = 0.;
- for ( j=0 ; j<p->bounds[k] ; j++ ) {
- pt[ 0 ] += pv[n+j].xyz[ 0 ];
- pt[ 1 ] += pv[n+j].xyz[ 1 ];
- pt[ 2 ] += pv[n+j].xyz[ 2 ];
- }
- pt[ 0 ] /= p->bounds[k];
- pt[ 1 ] /= p->bounds[k];
- pt[ 2 ] /= p->bounds[k];
- glVertex3fv ( pt );
- n += p->bounds[k];
+ else
+ {
+ aCtx->core11fwd->glAlphaFunc (GL_GEQUAL, aCtx->ShaderManager()->MaterialState().AlphaCutoff());
}
}
- } else if( p->num_edges > 0 ) {
- pt[0] = pt[1] = pt[2] = 0.;
- for ( j=0 ; j<p->num_edges ; j++ ) {
- iv = p->edges[j];
- pt[ 0 ] += pv[iv].xyz[ 0 ];
- pt[ 1 ] += pv[iv].xyz[ 1 ];
- pt[ 2 ] += pv[iv].xyz[ 2 ];
- }
- pt[ 0 ] /= p->num_edges;
- pt[ 1 ] /= p->num_edges;
- pt[ 2 ] /= p->num_edges;
- glVertex3fv ( pt );
- } else {
- pt[0] = pt[1] = pt[2] = 0.;
- for ( j=0 ; j<p->num_vertexs ; j++ ) {
- pt[ 0 ] += pv[j].xyz[ 0 ];
- pt[ 1 ] += pv[j].xyz[ 1 ];
- pt[ 2 ] += pv[j].xyz[ 2 ];
- }
- pt[ 0 ] /= p->num_vertexs;
- pt[ 1 ] /= p->num_vertexs;
- pt[ 2 ] /= p->num_vertexs;
- glVertex3fv ( pt );
- }
-}
-
-/*----------------------------------------------------------------------*/
-static void draw_degenerates_quadrangles_as_points ( call_def_parray p ) {
-
- Tint i, j, iv;
- GLfloat pt[ 3 ];
- tel_point pv = p -> vertices;
-
-#ifdef FULL_DEGENER
- if ( g_fSkipRatio == 1. )
+ #endif
+ aCtx->SetPointSize (1.0f);
return;
-#endif
+ }
+ else if (anAspectMarker->Aspect()->MarkerType() == Aspect_TOM_POINT)
+ {
+ aCtx->SetPointSize (anAspectMarker->MarkerSize());
+ aCtx->core11fwd->glDrawArrays (aDrawMode, 0, !myVboAttribs.IsNull() ? myVboAttribs->GetElemsNb() : myAttribs->NbElements);
+ aCtx->SetPointSize (1.0f);
+ }
+#if !defined(GL_ES_VERSION_2_0)
+ // Textured markers will be drawn with the glBitmap
+ else if (anAspectMarker->Aspect()->MarkerType() != Aspect_TOM_POINT)
+ {
+ const Handle(OpenGl_PointSprite)& aSpriteNorm = anAspectMarker->SpriteRes (aCtx, false);
+ if (aSpriteNorm.IsNull())
+ {
+ return;
+ }
- if( p->num_edges > 0 ) {
- for ( j=0 ; j<p->num_edges ; j+=4 ) {
- pt[0] = pt[1] = pt[2] = 0.;
- for ( i=0 ; i<4 ; i++ ) {
- iv = p->edges[j+i];
- pt[ 0 ] += pv[iv].xyz[ 0 ];
- pt[ 1 ] += pv[iv].xyz[ 1 ];
- pt[ 2 ] += pv[iv].xyz[ 2 ];
+ /**if (!isHilight && (myPArray->vcolours != NULL))
+ {
+ for (Standard_Integer anIter = 0; anIter < myAttribs->NbElements; anIter++)
+ {
+ glColor4ubv (myPArray->vcolours[anIter].GetData());
+ glRasterPos3fv (myAttribs->Value<Graphic3d_Vec3> (anIter).GetData());
+ aSpriteNorm->DrawBitmap (theWorkspace->GetGlContext());
}
- pt[ 0 ] /= 4;
- pt[ 1 ] /= 4;
- pt[ 2 ] /= 4;
- glVertex3fv ( pt );
}
- } else {
- for ( j=0 ; j<p->num_vertexs ; j+=4 ) {
- pt[0] = pt[1] = pt[2] = 0.;
- for ( i=0 ; i<4 ; i++ ) {
- pt[ 0 ] += pv[j+i].xyz[ 0 ];
- pt[ 1 ] += pv[j+i].xyz[ 1 ];
- pt[ 2 ] += pv[j+i].xyz[ 2 ];
+ else*/
+ {
+ for (Standard_Integer anIter = 0; anIter < myAttribs->NbElements; anIter++)
+ {
+ aCtx->core11->glRasterPos3fv (myAttribs->Value<Graphic3d_Vec3> (anIter).GetData());
+ aSpriteNorm->DrawBitmap (theWorkspace->GetGlContext());
}
- pt[ 0 ] /= 4;
- pt[ 1 ] /= 4;
- pt[ 2 ] /= 4;
- glVertex3fv ( pt );
}
}
-}
-
-/*----------------------------------------------------------------------*/
-static void draw_degenerates_quadranglestrips_as_points ( call_def_parray p ) {
-
- Tint i, j, k, n;
- GLfloat pt[ 3 ];
- tel_point pv = p -> vertices;
-
-#ifdef FULL_DEGENER
- if ( g_fSkipRatio == 1. )
- return;
#endif
+}
- if( p->num_bounds > 0 ) {
- for ( k=n=0 ; k<p->num_bounds ; k++ ) {
- for ( j=0 ; j<p->bounds[k]-2 ; j+=2 ) {
- pt[0] = pt[1] = pt[2] = 0.;
- for ( i=0 ; i<4 ; i++ ) {
- pt[ 0 ] += pv[n+j+i].xyz[ 0 ];
- pt[ 1 ] += pv[n+j+i].xyz[ 1 ];
- pt[ 2 ] += pv[n+j+i].xyz[ 2 ];
- }
- pt[ 0 ] /= 4;
- pt[ 1 ] /= 4;
- pt[ 2 ] /= 4;
- glVertex3fv ( pt );
- }
- n += p->bounds[k];
- }
- } else {
- for ( j=0 ; j<p->num_vertexs-2 ; j+=2 ) {
- pt[0] = pt[1] = pt[2] = 0.;
- for ( i=0 ; i<4 ; i++ ) {
- pt[ 0 ] += pv[j+i].xyz[ 0 ];
- pt[ 1 ] += pv[j+i].xyz[ 1 ];
- pt[ 2 ] += pv[j+i].xyz[ 2 ];
- }
- pt[ 0 ] /= 4;
- pt[ 1 ] /= 4;
- pt[ 2 ] /= 4;
- glVertex3fv ( pt );
- }
+// =======================================================================
+// function : OpenGl_PrimitiveArray
+// purpose :
+// =======================================================================
+OpenGl_PrimitiveArray::OpenGl_PrimitiveArray (const OpenGl_GraphicDriver* theDriver)
+
+: myDrawMode (DRAW_MODE_NONE),
+ myIsFillType(Standard_False),
+ myIsVboInit (Standard_False)
+{
+ if (theDriver != NULL)
+ {
+ myUID = theDriver->GetNextPrimitiveArrayUID();
}
-}
+}
-/*----------------------------------------------------------------------*/
-static void draw_degenerates_as_points ( call_def_parray p,
- tel_colour edge_colour )
+// =======================================================================
+// function : OpenGl_PrimitiveArray
+// purpose :
+// =======================================================================
+OpenGl_PrimitiveArray::OpenGl_PrimitiveArray (const OpenGl_GraphicDriver* theDriver,
+ const Graphic3d_TypeOfPrimitiveArray theType,
+ const Handle(Graphic3d_IndexBuffer)& theIndices,
+ const Handle(Graphic3d_Buffer)& theAttribs,
+ const Handle(Graphic3d_BoundBuffer)& theBounds)
+
+: myIndices (theIndices),
+ myAttribs (theAttribs),
+ myBounds (theBounds),
+ myDrawMode (DRAW_MODE_NONE),
+ myIsFillType(Standard_False),
+ myIsVboInit (Standard_False)
{
+ if (!myIndices.IsNull()
+ && myIndices->NbElements < 1)
+ {
+ // dummy index buffer?
+ myIndices.Nullify();
+ }
- GLboolean zbuff_state = glIsEnabled(GL_DEPTH_TEST);
- LightOff ();
- if( zbuff_state ) glDisable(GL_DEPTH_TEST);
- glColor3fv( edge_colour->rgb );
- glBegin ( GL_POINTS );
- switch( draw_mode ) {
- case GL_POINTS:
- draw_degenerates_points_as_points( p );
- break;
- case GL_LINES:
- draw_degenerates_lines_as_points( p );
- break;
- case GL_LINE_STRIP:
- case GL_POLYGON:
- draw_degenerates_polygons_as_points( p );
- break;
- case GL_TRIANGLES:
- draw_degenerates_triangles_as_points( p );
- break;
- case GL_QUADS:
- draw_degenerates_quadrangles_as_points( p );
- break;
- case GL_TRIANGLE_FAN:
- case GL_TRIANGLE_STRIP:
- draw_degenerates_trianglestrips_as_points( p );
- break;
- case GL_QUAD_STRIP:
- draw_degenerates_quadranglestrips_as_points( p );
- break;
- default:
- break;
+ if (theDriver != NULL)
+ {
+ myUID = theDriver->GetNextPrimitiveArrayUID();
+ #if defined (GL_ES_VERSION_2_0)
+ const Handle(OpenGl_Context)& aCtx = theDriver->GetSharedContext();
+ if (!aCtx.IsNull())
+ {
+ processIndices (aCtx);
+ }
+ #endif
}
- glEnd ();
+ setDrawMode (theType);
+}
- if( zbuff_state ) glEnable(GL_DEPTH_TEST);
+// =======================================================================
+// function : ~OpenGl_PrimitiveArray
+// purpose :
+// =======================================================================
+OpenGl_PrimitiveArray::~OpenGl_PrimitiveArray()
+{
+ //
}
-/*----------------------------------------------------------------------*/
-static void draw_degenerates_lines_as_lines ( call_def_parray p ) {
-
- Tint i,j,n,iv;
- tel_point pv = p -> vertices;
-
- n = p->num_vertexs;
- j = (int)((1.-g_fSkipRatio)*n);
- while ( j-- ) {
- i = OGL_Rand() % n;
- p->keys[i] = -p->keys[i];
- };
-
- if( p->num_bounds > 0 ) {
- if( p->num_edges > 0 ) {
- for ( i=n=0 ; i<p->num_bounds ; i++ ) {
- glBegin ( GL_LINES );
- for ( j=0 ; j<p->bounds[i] ; j++ ) {
- iv = p->edges[n+j];
- if( p->keys[iv] < 0 ) {
- p->keys[iv] = -p->keys[iv];
- glVertex3fv ( pv[iv].xyz );
- }
- }
- glEnd();
- n += p->bounds[i];
- }
- } else {
- for ( i=n=0 ; i<p->num_bounds ; i++ ) {
- glBegin ( GL_LINES );
- for ( j=0 ; j<p->bounds[i] ; j++ ) {
- if( p->keys[n+j] < 0 ) {
- p->keys[n+j] = -p->keys[n+j];
- glVertex3fv ( pv[n+j].xyz );
- }
- }
- glEnd();
- n += p->bounds[i];
- }
- }
- } else if( p->num_edges > 0 ) {
- glBegin ( GL_LINES );
- for ( j=0 ; j<p->num_edges ; j++ ) {
- iv = p->edges[j];
- if( p->keys[iv] < 0 ) {
- p->keys[iv] = -p->keys[iv];
- glVertex3fv ( pv[iv].xyz );
- }
- }
- glEnd();
- } else {
- glBegin ( GL_LINES );
- for ( j=0 ; j<p->num_vertexs ; j++ ) {
- if( p->keys[j] < 0 ) {
- p->keys[j] = -p->keys[j];
- glVertex3fv ( pv[j].xyz );
- }
+// =======================================================================
+// function : Release
+// purpose :
+// =======================================================================
+void OpenGl_PrimitiveArray::Release (OpenGl_Context* theContext)
+{
+ myIsVboInit = Standard_False;
+ if (!myVboIndices.IsNull())
+ {
+ if (theContext)
+ {
+ theContext->DelayedRelease (myVboIndices);
}
- glEnd();
+ myVboIndices.Nullify();
}
-}
-
-/*----------------------------------------------------------------------*/
-static void draw_degenerates_triangles_as_lines ( call_def_parray p )
-{
-
- Tint i,j,n,iv;
- tel_point pv = p -> vertices;
-
- n = p->num_vertexs/3;
- j = (int)((1.-g_fSkipRatio)*n);
- while ( j-- ) {
- i = OGL_Rand() % n; i *= 3;
- p->keys[i] = -p->keys[i];
- };
-
- if( p->num_edges > 0 ) {
- for ( j=0 ; j<p->num_edges ; j+=3 ) {
- iv = p->edges[j];
- if( p->keys[iv] < 0 ) {
- p->keys[iv] = -p->keys[iv];
- glBegin ( GL_LINE_LOOP );
- for ( i=0 ; i<3 ; i++ ) {
- iv = p->edges[j+i];
- glVertex3fv ( pv[iv].xyz );
- }
- glEnd();
- }
- }
- } else {
- for ( j=0 ; j<p->num_vertexs ; j+=3 ) {
- if( p->keys[j] < 0 ) {
- p->keys[j] = -p->keys[j];
- glBegin ( GL_LINE_LOOP );
- for ( i=0 ; i<3 ; i++ ) {
- glVertex3fv ( pv[j+i].xyz );
- }
- glEnd();
- }
+ if (!myVboAttribs.IsNull())
+ {
+ if (theContext)
+ {
+ theContext->DelayedRelease (myVboAttribs);
}
+ myVboAttribs.Nullify();
}
-}
-
-/*----------------------------------------------------------------------*/
-static void draw_degenerates_trianglestrips_as_lines ( call_def_parray p )
-{
-
- Tint i,j,k,n,ni;
- tel_point pv = p -> vertices;
-
- if( p->num_bounds > 0 ) {
- for ( i=n=0 ; i<p->num_bounds ; i++ ) {
- ni = p->bounds[i]-2;
- k = (int)((1.-g_fSkipRatio)*ni);
- while ( k-- ) {
- j = OGL_Rand() % ni; j += 2;
- p->keys[n+j] = -p->keys[n+j];
- };
- for ( j=2 ; j<p->bounds[i] ; j++ ) {
- if( p->keys[n+j] < 0 ) {
- p->keys[n+j] = -p->keys[n+j];
- glBegin ( GL_LINE_LOOP );
- glVertex3fv ( pv[n+j-2].xyz );
- glVertex3fv ( pv[n+j-1].xyz );
- glVertex3fv ( pv[n+j].xyz );
- glEnd();
- }
- }
- n += p->bounds[i];
- }
- } else {
- ni = p->num_vertexs-2;
- k = (int)((1.-g_fSkipRatio)*ni);
- while ( k-- ) {
- j = OGL_Rand() % ni; j += 2;
- p->keys[j] = -p->keys[j];
- };
- for ( j=2 ; j<p->num_vertexs ; j++ ) {
- if( p->keys[j] < 0 ) {
- p->keys[j] = -p->keys[j];
- glBegin ( GL_LINE_LOOP );
- glVertex3fv ( pv[j-2].xyz );
- glVertex3fv ( pv[j-1].xyz );
- glVertex3fv ( pv[j].xyz );
- glEnd();
- }
- }
+}
+
+// =======================================================================
+// function : Render
+// purpose :
+// =======================================================================
+void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
+{
+ if (myDrawMode == DRAW_MODE_NONE)
+ {
+ return;
}
-}
-
-/*----------------------------------------------------------------------*/
-static void draw_degenerates_polygons_as_lines ( call_def_parray p )
-{
- Tint i,j,n,iv;
- tel_point pv = p -> vertices;
-
- n = p->num_vertexs;
- j = (int)((1.-g_fSkipRatio)*n);
- while ( j-- ) {
- i = OGL_Rand() % n;
- p->keys[i] = -p->keys[i];
- };
-
- if( p->num_bounds > 0 ) {
- if( p->num_edges > 0 ) {
- for ( i=n=0 ; i<p->num_bounds ; i++ ) {
- glBegin ( GL_LINE_LOOP );
- for ( j=0 ; j<p->bounds[i] ; j++ ) {
- iv = p->edges[n+j];
- if( p->keys[iv] < 0 ) {
- p->keys[iv] = -p->keys[iv];
- glVertex3fv ( pv[iv].xyz );
+
+ const OpenGl_Aspects* anAspectFace = theWorkspace->ApplyAspects();
+ const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
+
+ const bool toEnableEnvMap = !aCtx->ActiveTextures().IsNull()
+ && aCtx->ActiveTextures() == theWorkspace->EnvironmentTexture();
+ bool toDrawArray = true;
+ int toDrawInteriorEdges = 0; // 0 - no edges, 1 - glsl edges, 2 - polygonMode
+ if (myIsFillType)
+ {
+ toDrawArray = anAspectFace->Aspect()->InteriorStyle() != Aspect_IS_EMPTY;
+ if (anAspectFace->Aspect()->ToDrawEdges())
+ {
+ toDrawInteriorEdges = 1;
+ toDrawArray = true;
+ #if !defined(GL_ES_VERSION_2_0)
+ if (anAspectFace->Aspect()->EdgeLineType() != Aspect_TOL_SOLID
+ || aCtx->hasGeometryStage == OpenGl_FeatureNotAvailable
+ || aCtx->caps->usePolygonMode)
+ {
+ toDrawInteriorEdges = 2;
+ if (anAspectFace->Aspect()->InteriorStyle() == Aspect_IS_EMPTY)
+ {
+ if (anAspectFace->Aspect()->EdgeLineType() != Aspect_TOL_SOLID)
+ {
+ toDrawArray = false;
}
- }
- glEnd();
- n += p->bounds[i];
- }
- } else {
- for ( i=n=0 ; i<p->num_bounds ; i++ ) {
- glBegin ( GL_LINE_LOOP );
- for ( j=0 ; j<p->bounds[i] ; j++ ) {
- if( p->keys[n+j] < 0 ) {
- p->keys[n+j] = -p->keys[n+j];
- glVertex3fv ( pv[n+j].xyz );
+ else
+ {
+ aCtx->SetPolygonMode (GL_LINE);
}
}
- glEnd();
- n += p->bounds[i];
}
+ #endif
}
- } else if( p->num_edges > 0 ) {
- glBegin ( GL_LINE_LOOP );
- for ( j=0 ; j<p->num_edges ; j++ ) {
- iv = p->edges[j];
- if( p->keys[iv] < 0 ) {
- p->keys[iv] = -p->keys[iv];
- glVertex3fv ( pv[iv].xyz );
+ }
+ else
+ {
+ if (myDrawMode == GL_POINTS)
+ {
+ if (anAspectFace->Aspect()->MarkerType() == Aspect_TOM_EMPTY)
+ {
+ return;
}
}
- glEnd();
- } else {
- glBegin ( GL_LINE_LOOP );
- for ( j=0 ; j<p->num_vertexs ; j++ ) {
- if( p->keys[j] < 0 ) {
- p->keys[j] = -p->keys[j];
- glVertex3fv ( pv[j].xyz );
+ else
+ {
+ if (anAspectFace->Aspect()->LineType() == Aspect_TOL_EMPTY)
+ {
+ return;
}
}
- glEnd();
}
-}
-
-/*----------------------------------------------------------------------*/
-static void draw_degenerates_quadrangles_as_lines ( call_def_parray p )
-{
-
- Tint i,j,n,iv;
- tel_point pv = p -> vertices;
-
- n = p->num_vertexs/4;
- j = (int)((1.-g_fSkipRatio)*n);
- while ( j-- ) {
- i = OGL_Rand() % n; i *= 4;
- p->keys[i] = -p->keys[i];
- };
-
- if( p->num_edges > 0 ) {
- for ( j=0 ; j<p->num_edges ; j+=4 ) {
- iv = p->edges[j];
- if( p->keys[iv] < 0 ) {
- p->keys[iv] = -p->keys[iv];
- glBegin ( GL_LINE_LOOP );
- for ( i=0 ; i<4 ; i++ ) {
- iv = p->edges[j+i];
- glVertex3fv ( pv[iv].xyz );
- }
- glEnd();
+ // create VBOs on first render call
+ if (!myIsVboInit)
+ {
+ // compatibility - keep data to draw markers using display lists
+ Standard_Boolean toKeepData = myDrawMode == GL_POINTS
+ && anAspectFace->IsDisplayListSprite (aCtx);
+ #if defined (GL_ES_VERSION_2_0)
+ processIndices (aCtx);
+ #endif
+ buildVBO (aCtx, toKeepData);
+ myIsVboInit = Standard_True;
+ }
+ else if ((!myAttribs.IsNull()
+ && myAttribs->IsMutable())
+ || (!myIndices.IsNull()
+ && myIndices->IsMutable()))
+ {
+ updateVBO (aCtx);
+ }
+
+ Graphic3d_TypeOfShadingModel aShadingModel = Graphic3d_TOSM_UNLIT;
+ if (toDrawArray)
+ {
+ const bool hasColorAttrib = !myVboAttribs.IsNull()
+ && myVboAttribs->HasColorAttribute();
+ const bool toHilight = theWorkspace->ToHighlight();
+ const bool hasVertColor = hasColorAttrib && !toHilight;
+ const bool hasVertNorm = !myVboAttribs.IsNull() && myVboAttribs->HasNormalAttribute();
+ switch (myDrawMode)
+ {
+ case GL_POINTS:
+ {
+ aShadingModel = aCtx->ShaderManager()->ChooseMarkerShadingModel (anAspectFace->ShadingModel(), hasVertNorm);
+ aCtx->ShaderManager()->BindMarkerProgram (aCtx->ActiveTextures(),
+ aShadingModel, Graphic3d_AlphaMode_Opaque,
+ hasVertColor, anAspectFace->ShaderProgramRes (aCtx));
+ break;
}
- }
- } else {
- for ( j=0 ; j<p->num_vertexs ; j+=4 ) {
- if( p->keys[j] < 0 ) {
- p->keys[j] = -p->keys[j];
- glBegin ( GL_LINE_LOOP );
- for ( i=0 ; i<4 ; i++ ) {
- glVertex3fv ( pv[j+i].xyz );
- }
- glEnd();
+ case GL_LINES:
+ case GL_LINE_STRIP:
+ {
+ aShadingModel = aCtx->ShaderManager()->ChooseLineShadingModel (anAspectFace->ShadingModel(), hasVertNorm);
+ aCtx->ShaderManager()->BindLineProgram (Handle(OpenGl_TextureSet)(),
+ anAspectFace->Aspect()->LineType(),
+ aShadingModel,
+ Graphic3d_AlphaMode_Opaque,
+ hasVertColor,
+ anAspectFace->ShaderProgramRes (aCtx));
+ break;
}
- }
- }
-}
-
-/*----------------------------------------------------------------------*/
-static void draw_degenerates_quadranglestrips_as_lines ( call_def_parray p )
-{
-
- Tint i,j,k,n,ni;
- tel_point pv = p -> vertices;
-
- if( p->num_bounds > 0 ) {
- for ( i=n=0 ; i<p->num_bounds ; i++ ) {
- ni = p->bounds[i]/2-2;
- k = (int)((1.-g_fSkipRatio)*ni);
- while ( k-- ) {
- j = OGL_Rand() % ni; j = j*2+2;
- p->keys[n+j] = -p->keys[n+j];
- };
- for ( j=3 ; j<p->bounds[i] ; j+=2 ) {
- if( p->keys[n+j] < 0 ) {
- p->keys[n+j] = -p->keys[n+j];
- glBegin ( GL_LINE_LOOP );
- glVertex3fv ( pv[n+j-3].xyz );
- glVertex3fv ( pv[n+j-2].xyz );
- glVertex3fv ( pv[n+j-1].xyz );
- glVertex3fv ( pv[n+j].xyz );
- glEnd();
+ default:
+ {
+ aShadingModel = aCtx->ShaderManager()->ChooseFaceShadingModel (anAspectFace->ShadingModel(), hasVertNorm);
+ aCtx->ShaderManager()->BindFaceProgram (aCtx->ActiveTextures(),
+ aShadingModel,
+ aCtx->ShaderManager()->MaterialState().HasAlphaCutoff() ? Graphic3d_AlphaMode_Mask : Graphic3d_AlphaMode_Opaque,
+ toDrawInteriorEdges == 1 ? anAspectFace->Aspect()->InteriorStyle() : Aspect_IS_SOLID,
+ hasVertColor,
+ toEnableEnvMap,
+ toDrawInteriorEdges == 1,
+ anAspectFace->ShaderProgramRes (aCtx));
+ if (toDrawInteriorEdges == 1)
+ {
+ aCtx->ShaderManager()->PushInteriorState (aCtx->ActiveProgram(), anAspectFace->Aspect());
}
+ break;
}
- n += p->bounds[i];
}
- } else {
- ni = p->num_vertexs/2-2;
- k = (int)((1.-g_fSkipRatio)*ni);
- while ( k-- ) {
- j = OGL_Rand() % ni; j = j*2+2;
- p->keys[j] = -p->keys[j];
- };
- for ( j=3 ; j<p->num_vertexs ; j+=2 ) {
- if( p->keys[j] < 0 ) {
- p->keys[j] = -p->keys[j];
- glBegin ( GL_LINE_LOOP );
- glVertex3fv ( pv[j-3].xyz );
- glVertex3fv ( pv[j-2].xyz );
- glVertex3fv ( pv[j-1].xyz );
- glVertex3fv ( pv[j].xyz );
- glEnd();
+
+ #if !defined(GL_ES_VERSION_2_0)
+ // manage FFP lighting
+ if (aCtx->ActiveProgram().IsNull()
+ && aCtx->core11 != NULL)
+ {
+ if (aShadingModel == Graphic3d_TOSM_UNLIT)
+ {
+ glDisable (GL_LIGHTING);
+ }
+ else
+ {
+ glEnable (GL_LIGHTING);
}
}
- }
-}
+ #endif
-/*----------------------------------------------------------------------*/
-static void draw_degenerates_as_lines ( call_def_parray p,
- tel_colour edge_colour )
-{
+ if (!aCtx->ActiveTextures().IsNull()
+ && !aCtx->ActiveTextures()->IsEmpty()
+ && !aCtx->ActiveTextures()->First().IsNull()
+ && myDrawMode != GL_POINTS) // transformation is not supported within point sprites
+ {
+ aCtx->SetTextureMatrix (aCtx->ActiveTextures()->First()->Sampler()->Parameters());
+ }
+ aCtx->SetSampleAlphaToCoverage (aCtx->ShaderManager()->MaterialState().HasAlphaCutoff());
+
+ const Graphic3d_Vec4* aFaceColors = !myBounds.IsNull() && !toHilight && anAspectFace->Aspect()->InteriorStyle() != Aspect_IS_HIDDENLINE
+ ? myBounds->Colors
+ : NULL;
+ const OpenGl_Vec4& anInteriorColor = theWorkspace->InteriorColor();
+ aCtx->SetColor4fv (anInteriorColor);
+ if (!myIsFillType)
+ {
+ if (myDrawMode == GL_LINES
+ || myDrawMode == GL_LINE_STRIP)
+ {
+ aCtx->SetTypeOfLine (anAspectFace->Aspect()->LineType());
+ aCtx->SetLineWidth (anAspectFace->Aspect()->LineWidth());
+ }
- GLint renderMode;
+ drawArray (theWorkspace, aFaceColors, hasColorAttrib);
+ return;
+ }
- GLboolean zbuff_state = glIsEnabled(GL_DEPTH_TEST);
+ drawArray (theWorkspace, aFaceColors, hasColorAttrib);
- LightOff ();
+ // draw outline - only closed triangulation with defined vertex normals can be drawn in this way
+ if (anAspectFace->Aspect()->ToDrawSilhouette()
+ && aCtx->ToCullBackFaces()
+ && aCtx->ShaderManager()->BindOutlineProgram())
+ {
+ const Graphic3d_Vec2i aViewSize (aCtx->Viewport()[2], aCtx->Viewport()[3]);
+ const Standard_Integer aMin = aViewSize.minComp();
+ const GLfloat anEdgeWidth = (GLfloat )anAspectFace->Aspect()->EdgeWidth() * aCtx->LineWidthScale() / (GLfloat )aMin;
+ const GLfloat anOrthoScale = theWorkspace->View()->Camera()->IsOrthographic() ? (GLfloat )theWorkspace->View()->Camera()->Scale() : -1.0f;
- if( zbuff_state ) glDisable(GL_DEPTH_TEST);
+ const Handle(OpenGl_ShaderProgram)& anOutlineProgram = aCtx->ActiveProgram();
+ anOutlineProgram->SetUniform (aCtx, anOutlineProgram->GetStateLocation (OpenGl_OCCT_SILHOUETTE_THICKNESS), anEdgeWidth);
+ anOutlineProgram->SetUniform (aCtx, anOutlineProgram->GetStateLocation (OpenGl_OCCT_ORTHO_SCALE), anOrthoScale);
+ aCtx->SetColor4fv (anAspectFace->Aspect()->EdgeColorRGBA());
- glColor3fv( edge_colour->rgb );
+ aCtx->core11fwd->glCullFace (GL_FRONT);
+ drawArray (theWorkspace, NULL, false);
- if( g_fSkipRatio != 0 ) switch( draw_mode ) {
- case GL_POINTS:
- draw_degenerates_points_as_points( p );
- break;
- case GL_LINES:
- draw_degenerates_lines_as_lines( p );
- break;
- case GL_LINE_STRIP:
- case GL_POLYGON:
- draw_degenerates_polygons_as_lines( p );
- break;
- case GL_TRIANGLES:
- draw_degenerates_triangles_as_lines( p );
- break;
- case GL_QUADS:
- draw_degenerates_quadrangles_as_lines( p );
- break;
- case GL_TRIANGLE_FAN:
- case GL_TRIANGLE_STRIP:
- draw_degenerates_trianglestrips_as_lines( p );
- break;
- case GL_QUAD_STRIP:
- draw_degenerates_quadranglestrips_as_lines( p );
- break;
- default:
- break;
+ aCtx->core11fwd->glCullFace (GL_BACK);
+ }
+ }
+
+#if !defined(GL_ES_VERSION_2_0)
+ // draw triangulation edges using Polygon Mode
+ if (toDrawInteriorEdges == 2)
+ {
+ if (anAspectFace->Aspect()->InteriorStyle() == Aspect_IS_HOLLOW
+ && anAspectFace->Aspect()->EdgeLineType() == Aspect_TOL_SOLID)
+ {
+ aCtx->SetPolygonMode (GL_FILL);
+ }
+ else
+ {
+ drawEdges (theWorkspace);
+ }
}
- else {
- int i,n;
-
-#ifdef OCC3192
- GLboolean color_array_mode,
- edge_flag_array_mode,
- index_array_mode,
- normal_array_mode,
- texture_coord_array_mode,
- vertex_array_mode;
-#endif
- glPushAttrib( GL_POLYGON_BIT );
- glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
-
-#ifdef OCC3192
- color_array_mode = glIsEnabled( GL_COLOR_ARRAY );
- edge_flag_array_mode = glIsEnabled( GL_EDGE_FLAG_ARRAY );
- index_array_mode = glIsEnabled( GL_INDEX_ARRAY );
- normal_array_mode = glIsEnabled( GL_NORMAL_ARRAY );
- texture_coord_array_mode = glIsEnabled( GL_TEXTURE_COORD_ARRAY );
- vertex_array_mode = glIsEnabled( GL_VERTEX_ARRAY );
-
- glDisableClientState( GL_COLOR_ARRAY );
- glDisableClientState( GL_EDGE_FLAG_ARRAY );
- glDisableClientState( GL_INDEX_ARRAY );
- glDisableClientState( GL_NORMAL_ARRAY );
- glDisableClientState( GL_TEXTURE_COORD_ARRAY );
-
- if( !vertex_array_mode ) glEnableClientState( GL_VERTEX_ARRAY );
-#else
- glEnableClientState( GL_VERTEX_ARRAY );
#endif
- glVertexPointer(3, GL_FLOAT, 0, p->vertices); /* array of vertices */
+}
- glGetIntegerv( GL_RENDER_MODE, &renderMode );
+// =======================================================================
+// function : setDrawMode
+// purpose :
+// =======================================================================
+void OpenGl_PrimitiveArray::setDrawMode (const Graphic3d_TypeOfPrimitiveArray theType)
+{
+ if (myAttribs.IsNull())
+ {
+ myDrawMode = DRAW_MODE_NONE;
+ myIsFillType = false;
+ return;
+ }
- if( p->num_bounds > 0 ) {
- if( p->num_edges > 0 ) {
- for( i=n=0 ; i<p->num_bounds ; i++ ) {
- if( renderMode == GL_FEEDBACK )
- draw_primitive_elements( p, draw_mode, p->bounds[i],
- GL_UNSIGNED_INT, (GLenum*) &p->edges[n]);
- else
- glDrawElements( draw_mode, p->bounds[i],
- GL_UNSIGNED_INT, &p->edges[n]);
- n += p->bounds[i];
- }
- } else {
- for( i=n=0 ; i<p->num_bounds ; i++ ) {
- if( renderMode == GL_FEEDBACK )
- draw_primitive_array( p, draw_mode, n, p->bounds[i]);
- else
- glDrawArrays( draw_mode, n, p->bounds[i]);
- n += p->bounds[i];
- }
- }
- } else if( p->num_edges > 0 ) {
- if( renderMode == GL_FEEDBACK )
- draw_primitive_elements( p, draw_mode, p->num_edges,
- GL_UNSIGNED_INT, (GLenum*) p->edges);
- else
- glDrawElements( draw_mode, p->num_edges,
- GL_UNSIGNED_INT, p->edges);
- } else {
- if( renderMode == GL_FEEDBACK )
- draw_primitive_array( p, draw_mode, 0, p->num_vertexs);
- else
- glDrawArrays( draw_mode, 0, p->num_vertexs);
+ switch (theType)
+ {
+ case Graphic3d_TOPA_POINTS:
+ myDrawMode = GL_POINTS;
+ myIsFillType = false;
+ break;
+ case Graphic3d_TOPA_SEGMENTS:
+ myDrawMode = GL_LINES;
+ myIsFillType = false;
+ break;
+ case Graphic3d_TOPA_POLYLINES:
+ myDrawMode = GL_LINE_STRIP;
+ myIsFillType = false;
+ break;
+ case Graphic3d_TOPA_TRIANGLES:
+ myDrawMode = GL_TRIANGLES;
+ myIsFillType = true;
+ break;
+ case Graphic3d_TOPA_TRIANGLESTRIPS:
+ myDrawMode = GL_TRIANGLE_STRIP;
+ myIsFillType = true;
+ break;
+ case Graphic3d_TOPA_TRIANGLEFANS:
+ myDrawMode = GL_TRIANGLE_FAN;
+ myIsFillType = true;
+ break;
+ //
+ case Graphic3d_TOPA_LINES_ADJACENCY:
+ myDrawMode = GL_LINES_ADJACENCY;
+ myIsFillType = false;
+ break;
+ case Graphic3d_TOPA_LINE_STRIP_ADJACENCY:
+ myDrawMode = GL_LINE_STRIP_ADJACENCY;
+ myIsFillType = false;
+ break;
+ case Graphic3d_TOPA_TRIANGLES_ADJACENCY:
+ myDrawMode = GL_TRIANGLES_ADJACENCY;
+ myIsFillType = true;
+ break;
+ case Graphic3d_TOPA_TRIANGLE_STRIP_ADJACENCY:
+ myDrawMode = GL_TRIANGLE_STRIP_ADJACENCY;
+ myIsFillType = true;
+ break;
+ //
+ #if !defined(GL_ES_VERSION_2_0)
+ case Graphic3d_TOPA_QUADRANGLES:
+ myDrawMode = GL_QUADS;
+ myIsFillType = true;
+ break;
+ case Graphic3d_TOPA_QUADRANGLESTRIPS:
+ myDrawMode = GL_QUAD_STRIP;
+ myIsFillType = true;
+ break;
+ case Graphic3d_TOPA_POLYGONS:
+ myDrawMode = GL_POLYGON;
+ myIsFillType = true;
+ break;
+ #else
+ case Graphic3d_TOPA_QUADRANGLES:
+ case Graphic3d_TOPA_QUADRANGLESTRIPS:
+ case Graphic3d_TOPA_POLYGONS:
+ #endif
+ case Graphic3d_TOPA_UNDEFINED:
+ myDrawMode = DRAW_MODE_NONE;
+ myIsFillType = false;
+ break;
+ }
+}
+
+// =======================================================================
+// function : processIndices
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_PrimitiveArray::processIndices (const Handle(OpenGl_Context)& theContext) const
+{
+ if (myIndices.IsNull()
+ || myAttribs.IsNull()
+ || theContext->hasUintIndex)
+ {
+ return Standard_True;
+ }
+
+ if (myAttribs->NbElements > std::numeric_limits<GLushort>::max())
+ {
+ Handle(Graphic3d_Buffer) anAttribs = new Graphic3d_Buffer (new NCollection_AlignedAllocator (16));
+ if (!anAttribs->Init (myIndices->NbElements, myAttribs->AttributesArray(), myAttribs->NbAttributes))
+ {
+ return Standard_False; // failed to initialize attribute array
}
-#ifdef OCC3192
- if( !vertex_array_mode ) glDisableClientState( GL_VERTEX_ARRAY );
+ for (Standard_Integer anIdxIdx = 0; anIdxIdx < myIndices->NbElements; ++anIdxIdx)
+ {
+ const Standard_Integer anIndex = myIndices->Index (anIdxIdx);
+ memcpy (anAttribs->ChangeData() + myAttribs->Stride * anIdxIdx,
+ myAttribs->Data() + myAttribs->Stride * anIndex,
+ myAttribs->Stride);
+ }
- if( color_array_mode ) glEnableClientState( GL_COLOR_ARRAY );
- if( edge_flag_array_mode ) glEnableClientState( GL_EDGE_FLAG_ARRAY );
- if( index_array_mode ) glEnableClientState( GL_INDEX_ARRAY );
- if( normal_array_mode ) glEnableClientState( GL_NORMAL_ARRAY );
- if( texture_coord_array_mode ) glEnableClientState( GL_TEXTURE_COORD_ARRAY );
-#endif
- glPopAttrib();
+ myIndices.Nullify();
+ myAttribs = anAttribs;
}
- if( zbuff_state ) glEnable(GL_DEPTH_TEST);
-
-}
+ return Standard_True;
+}
-static void draw_degenerates_as_bboxs ( call_def_parray p,
- tel_colour edge_colour )
+// =======================================================================
+// function : InitBuffers
+// purpose :
+// =======================================================================
+void OpenGl_PrimitiveArray::InitBuffers (const Handle(OpenGl_Context)& theContext,
+ const Graphic3d_TypeOfPrimitiveArray theType,
+ const Handle(Graphic3d_IndexBuffer)& theIndices,
+ const Handle(Graphic3d_Buffer)& theAttribs,
+ const Handle(Graphic3d_BoundBuffer)& theBounds)
{
+ // Release old graphic resources
+ Release (theContext.get());
+
+ myIndices = theIndices;
+ myAttribs = theAttribs;
+ myBounds = theBounds;
+#if defined(GL_ES_VERSION_2_0)
+ processIndices (theContext);
+#endif
- Tint i;
- GLfloat minp[ 3 ] = { FLT_MAX, FLT_MAX, FLT_MAX };
- GLfloat maxp[ 3 ] = { FLT_MIN, FLT_MIN, FLT_MIN };
- tel_point pv = p -> vertices;
-
- LightOff ();
-
- glColor3fv( edge_colour->rgb );
-
- for ( i=0 ; i<p->num_vertexs ; ++i ) {
- if ( pv[ i ].xyz[ 0 ] < minp[ 0 ] )
- minp[ 0 ] = pv[ i ].xyz[ 0 ] ;
- if ( pv[ i ].xyz[ 1 ] < minp[ 1 ] )
- minp[ 1 ] = pv[ i ].xyz[ 1 ] ;
- if ( pv[ i ].xyz[ 2 ] < minp[ 2 ] )
- minp[ 2 ] = pv[ i ].xyz[ 2 ] ;
-
- if ( pv[ i ].xyz[ 0 ] > maxp[ 0 ] )
- maxp[ 0 ] = pv[ i ].xyz[ 0 ] ;
- if ( pv[ i ].xyz[ 1 ] > maxp[ 1 ] )
- maxp[ 1 ] = pv[ i ].xyz[ 1 ] ;
- if ( pv[ i ].xyz[ 2 ] > maxp[ 2 ] )
- maxp[ 2 ] = pv[ i ].xyz[ 2 ] ;
- } /* end for ( i ) */
-
- glBegin ( GL_LINE_STRIP );
-
- glVertex3fv ( minp );
- glVertex3f ( minp[ 0 ], maxp[ 1 ], minp[ 2 ] );
- glVertex3f ( minp[ 0 ], maxp[ 1 ], maxp[ 2 ] );
- glVertex3f ( minp[ 0 ], minp[ 1 ], maxp[ 2 ] );
- glVertex3f ( minp[ 0 ], minp[ 1 ], minp[ 2 ] );
-
- glVertex3f ( maxp[ 0 ], minp[ 1 ], minp[ 2 ] );
- glVertex3f ( maxp[ 0 ], maxp[ 1 ], minp[ 2 ] );
- glVertex3f ( maxp[ 0 ], maxp[ 1 ], maxp[ 2 ] );
- glVertex3f ( maxp[ 0 ], minp[ 1 ], maxp[ 2 ] );
- glVertex3f ( maxp[ 0 ], minp[ 1 ], minp[ 2 ] );
-
- glVertex3f ( maxp[ 0 ], minp[ 1 ], maxp[ 2 ] );
- glVertex3f ( minp[ 0 ], minp[ 1 ], maxp[ 2 ] );
- glVertex3f ( minp[ 0 ], maxp[ 1 ], maxp[ 2 ] );
- glVertex3fv ( maxp );
- glVertex3f ( maxp[ 0 ], maxp[ 1 ], minp[ 2 ] );
- glVertex3f ( minp[ 0 ], maxp[ 1 ], minp[ 2 ] );
-
- glEnd();
-
-} /* end draw_degenerates_as_bboxs */
+ setDrawMode (theType);
+}