OpenGl_LineAttributes - drop display lists for stipple lines.
OpenGl_Context - add methods OpenGl_Context::SetTypeOfLine() and OpenGl_Context::SetLineWidth() to setup line aspects.
OpenGl_ShaderManager::prepareStdProgramFlat() - support new bit OpenGl_PO_StippleLine.
vaspects command - add -setlinetype option.
#include <GL/glx.h> // glXGetProcAddress()
#endif
+#ifdef HAVE_GL2PS
+ #include <gl2ps.h>
+ #ifdef _MSC_VER
+ #pragma comment (lib, "gl2ps.lib")
+ #endif
+#endif
+
IMPLEMENT_STANDARD_HANDLE (OpenGl_Context, Standard_Transient)
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Context, Standard_Transient)
#endif
}
+// =======================================================================
+// function : SetTypeOfLine
+// purpose :
+// =======================================================================
+void OpenGl_Context::SetTypeOfLine (const Aspect_TypeOfLine theType,
+ const Standard_ShortReal theFactor)
+{
+ Standard_Integer aPattern = 0xFFFF;
+ switch (theType)
+ {
+ case Aspect_TOL_DASH:
+ {
+ aPattern = 0xFFC0;
+ break;
+ }
+ case Aspect_TOL_DOT:
+ {
+ aPattern = 0xCCCC;
+ break;
+ }
+ case Aspect_TOL_DOTDASH:
+ {
+ aPattern = 0xFF18;
+ break;
+ }
+ case Aspect_TOL_SOLID:
+ {
+ aPattern = 0xFFFF;
+ break;
+ }
+ case Aspect_TOL_USERDEFINED:
+ {
+ aPattern = 0xFF24;
+ break;
+ }
+ }
+
+ if (myActiveProgram != NULL)
+ {
+ myActiveProgram->SetUniform (this, "uPattern", aPattern);
+ myActiveProgram->SetUniform (this, "uFactor", theFactor);
+ return;
+ }
+
+#if !defined(GL_ES_VERSION_2_0)
+ if (theType != Aspect_TOL_SOLID)
+ {
+ #ifdef HAVE_GL2PS
+ if (IsFeedback())
+ {
+ gl2psEnable (GL2PS_LINE_STIPPLE);
+ }
+ #endif
+
+ if (core11 != NULL)
+ {
+ core11fwd->glEnable (GL_LINE_STIPPLE);
+
+ core11->glLineStipple (static_cast<GLint> (theFactor),
+ static_cast<GLushort> (aPattern));
+ }
+ }
+ else
+ {
+ if (core11 != NULL)
+ {
+ core11fwd->glDisable (GL_LINE_STIPPLE);
+ }
+
+ #ifdef HAVE_GL2PS
+ if (IsFeedback())
+ {
+ gl2psDisable (GL2PS_LINE_STIPPLE);
+ }
+ #endif
+ }
+#endif
+}
+
+// =======================================================================
+// function : SetLineWidth
+// purpose :
+// =======================================================================
+void OpenGl_Context::SetLineWidth (const Standard_ShortReal theWidth)
+{
+ if (core11 != NULL)
+ {
+ // glLineWidth() is still defined within Core Profile, but has no effect with values != 1.0f
+ core11fwd->glLineWidth (theWidth);
+ }
+#ifdef HAVE_GL2PS
+ if (IsFeedback())
+ {
+ gl2psLineWidth (theWidth);
+ }
+#endif
+}
+
// =======================================================================
// function : SetPointSize
// purpose :
#include <Aspect_Drawable.hxx>
#include <Aspect_Display.hxx>
#include <Aspect_RenderingContext.hxx>
+#include <Aspect_TypeOfLine.hxx>
#include <Handle_OpenGl_Context.hxx>
#include <Handle_OpenGl_FrameBuffer.hxx>
#include <Handle_OpenGl_Sampler.hxx>
//! Setup current color.
Standard_EXPORT void SetColor4fv (const OpenGl_Vec4& theColor);
+ //! Setup type of line.
+ Standard_EXPORT void SetTypeOfLine (const Aspect_TypeOfLine theType,
+ const Standard_ShortReal theFactor = 1.0f);
+
+ //! Setup width of line.
+ Standard_EXPORT void SetLineWidth (const Standard_ShortReal theWidth);
+
//! Setup point size.
Standard_EXPORT void SetPointSize (const Standard_ShortReal theSize);
if (TheLayerProp.LineType != theType)
{
- Handle(OpenGl_LineAttributes) aLineAttribs;
- if (aCtx->GetResource ("OpenGl_LineAttributes", aLineAttribs))
- {
- TheLayerProp.LineType = theType;
- aLineAttribs->SetTypeOfLine ((Aspect_TypeOfLine )theType);
- }
+ TheLayerProp.LineType = theType;
+ aCtx->SetTypeOfLine ((Aspect_TypeOfLine) theType);
}
if (TheLayerProp.LineWidth != theWidth)
{
TheLayerProp.LineWidth = theWidth;
- glLineWidth ((GLfloat )theWidth);
+ aCtx->SetLineWidth (theWidth);
}
}
#include <OpenGl_LineAttributes.hxx>
#include <OpenGl_Context.hxx>
-#ifdef HAVE_GL2PS
- #include <gl2ps.h>
-#endif
-
-#define DOT_LS 0xCCCC
-#define DASH_DOT_LS 0xFF18
-#define DASH_LS 0xFFC0
-#define DASH_DDOT_LS 0xFF24
-
static const unsigned int myInteriors[TEL_HS_USER_DEF_START][32] =
{
//TEL_HS_SOLID
// purpose :
// =======================================================================
OpenGl_LineAttributes::OpenGl_LineAttributes()
-: myLinestyleBase(0),
- myPatternBase(0)
+: myPatternBase(0)
{
//
}
// =======================================================================
void OpenGl_LineAttributes::Release (OpenGl_Context* theGlCtx)
{
- // Delete line styles
- if (myLinestyleBase != 0)
- {
- if (theGlCtx->IsValid())
- {
- #if !defined(GL_ES_VERSION_2_0)
- glDeleteLists ((GLuint )myLinestyleBase, 5);
- #endif
- }
- myLinestyleBase = 0;
- }
// Delete surface patterns
if (myPatternBase != 0)
{
void OpenGl_LineAttributes::Init (const Handle(OpenGl_Context)& theGlCtx)
{
// Return if already initialized
- if (myLinestyleBase != 0)
+ if (myPatternBase != 0)
{
return;
}
return;
}
- myLinestyleBase = theGlCtx->core11->glGenLists (5);
-
- // Line
- glNewList ((GLuint )myLinestyleBase + (GLuint )Aspect_TOL_DASH, GL_COMPILE);
- glLineStipple (1, DASH_LS);
- glEndList();
-
- glNewList ((GLuint )myLinestyleBase + (GLuint )Aspect_TOL_DOT, GL_COMPILE);
- glLineStipple (1, DOT_LS);
- glEndList();
-
- glNewList ((GLuint )myLinestyleBase + (GLuint )Aspect_TOL_DOTDASH, GL_COMPILE);
- glLineStipple (1, DASH_DOT_LS);
- glEndList();
-
- glNewList ((GLuint )myLinestyleBase + (GLuint )Aspect_TOL_USERDEFINED, GL_COMPILE);
- glLineStipple (1, DASH_DDOT_LS);
- glEndList();
-
// GL_POLYGON_STIPPLE need 32x32 stipple patterns
const int nbi = sizeof(myInteriors) / (32 * sizeof(unsigned int));
myPatternBase = glGenLists(TEL_HS_USER_DEF_START);
#endif
}
-// =======================================================================
-// function : SetTypeOfLine
-// purpose :
-// =======================================================================
-void OpenGl_LineAttributes::SetTypeOfLine (const Aspect_TypeOfLine theType) const
-{
-#if !defined(GL_ES_VERSION_2_0)
- if (theType != Aspect_TOL_SOLID)
- {
- if (myLinestyleBase != 0)
- {
- glCallList ((GLuint )myLinestyleBase + (GLuint )theType);
- glEnable (GL_LINE_STIPPLE);
- }
- #ifdef HAVE_GL2PS
- gl2psEnable (GL2PS_LINE_STIPPLE);
- #endif
- }
- else
- {
- if (myLinestyleBase != 0)
- {
- glDisable (GL_LINE_STIPPLE);
- }
- #ifdef HAVE_GL2PS
- gl2psDisable (GL2PS_LINE_STIPPLE);
- #endif
- }
-#endif
-}
-
// =======================================================================
// function : SetTypeOfHatch
// purpose :
void Init (const Handle(OpenGl_Context)& theGlCtx);
virtual void Release (OpenGl_Context* theGlCtx);
- void SetTypeOfLine (const Aspect_TypeOfLine theType) const;
-
void SetTypeOfHatch (const int theType) const;
protected:
- unsigned int myLinestyleBase;
unsigned int myPatternBase;
public:
/// 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 (*(const OpenGl_Vec4* )theEdgeColour->rgb);
+
+ aGlContext->SetColor4fv (*(const OpenGl_Vec4* )theEdgeColour->rgb);
+ aGlContext->SetTypeOfLine (anAspect->Type());
+ aGlContext->SetLineWidth (anAspect->Width());
+
if (!myVboIndices.IsNull())
{
myVboIndices->Bind (aGlContext);
}
aCtx->SetColor4fv (*(const OpenGl_Vec4* )(myDrawMode <= GL_LINE_STRIP ? aLineColor->rgb : anInteriorColor->rgb));
+ if (myDrawMode == GL_LINES
+ || myDrawMode == GL_LINE_STRIP)
+ {
+ aCtx->SetTypeOfLine (anAspectLine->Type());
+ aCtx->SetLineWidth (anAspectLine->Width());
+ }
drawArray (theWorkspace, aFaceColors, hasColorAttrib);
}
//! Standard GLSL program combination bits.
enum OpenGl_ProgramOptions
{
- OpenGl_PO_ClipPlanes = 0x01, //!< handle clipping planes
- OpenGl_PO_Point = 0x02, //!< point marker
- OpenGl_PO_VertColor = 0x04, //!< per-vertex color
- OpenGl_PO_TextureRGB = 0x08, //!< handle RGB texturing
- OpenGl_PO_TextureA = 0x10, //!< handle Alpha texturing
- OpenGl_PO_TextureEnv = 0x20, //!< handle environment map
- OpenGl_PO_NB = 0x40 //!< overall number of combinations
+ OpenGl_PO_ClipPlanes = 0x01, //!< handle clipping planes
+ OpenGl_PO_Point = 0x02, //!< point marker
+ OpenGl_PO_VertColor = 0x04, //!< per-vertex color
+ OpenGl_PO_TextureRGB = 0x08, //!< handle RGB texturing
+ OpenGl_PO_TextureA = 0x10, //!< handle Alpha texturing
+ OpenGl_PO_TextureEnv = 0x20, //!< handle environment map
+ OpenGl_PO_StippleLine = 0x40, //!< stipple line
+ OpenGl_PO_NB = 0x80 //!< overall number of combinations
};
//! Alias to programs array of predefined length
#include <OpenGl_ShaderProgram.hxx>
#include <OpenGl_Workspace.hxx>
+#include <TCollection_ExtendedString.hxx>
+
IMPLEMENT_STANDARD_HANDLE (OpenGl_SetOfShaderPrograms, Standard_Transient)
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_SetOfShaderPrograms, Standard_Transient)
aSrcFragExtraMain += THE_FRAG_CLIP_PLANES;
}
+ TCollection_AsciiString aSrcVertEndMain;
+ if ((theBits & OpenGl_PO_StippleLine) != 0)
+ {
+ bool hasCaps = false;
+ #if defined(GL_ES_VERSION_2_0)
+ if (myContext->IsGlGreaterEqual (3, 0))
+ {
+ aProgramSrc->SetHeader ("#version 300 es");
+ hasCaps = true;
+ }
+ #else
+ if (myContext->core32 != NULL)
+ {
+ aProgramSrc->SetHeader ("#version 150");
+ hasCaps = true;
+ }
+ #endif
+
+ if (hasCaps)
+ {
+ aSrcVertExtraOut +=
+ EOL"THE_SHADER_OUT vec2 ScreenSpaceCoord;";
+ aSrcFragExtraOut +=
+ EOL"THE_SHADER_IN vec2 ScreenSpaceCoord;"
+ EOL"uniform int uPattern;"
+ EOL"uniform float uFactor;";
+ aSrcVertEndMain =
+ EOL" ScreenSpaceCoord = gl_Position.xy / gl_Position.w;";
+ aSrcFragMainGetColor =
+ EOL" float anAngle = atan (dFdx (ScreenSpaceCoord.x), dFdy (ScreenSpaceCoord.y));"
+ EOL" float aRotatePoint = gl_FragCoord.x * sin (anAngle) + gl_FragCoord.y * cos (anAngle);"
+ EOL" uint aBit = uint (floor (aRotatePoint / uFactor + 0.5)) & 15U;"
+ EOL" if ((uint (uPattern) & (1U << aBit)) == 0U) discard;"
+ EOL" vec4 aColor = getColor();"
+ EOL" if (aColor.a <= 0.1) discard;"
+ EOL" occFragColor = aColor;";
+ }
+ else
+ {
+ const TCollection_ExtendedString aWarnMessage =
+ "Warning: stipple lines in GLSL will be ignored.";
+ myContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB,
+ GL_DEBUG_TYPE_PORTABILITY_ARB, 0, GL_DEBUG_SEVERITY_HIGH_ARB, aWarnMessage);
+ }
+ }
+
aSrcVert =
aSrcVertExtraFunc
+ aSrcVertExtraOut
EOL"{"
+ aSrcVertExtraMain
+ EOL" gl_Position = occProjectionMatrix * occWorldViewMatrix * occModelWorldMatrix * occVertex;"
- EOL"}";
+ + aSrcVertEndMain
+ + EOL"}";
aSrcFrag =
aSrcFragExtraOut
return bindProgramWithState (theCustomProgram, theAspect);
}
- const Standard_Integer aBits = getProgramBits (theTexture, theHasVertColor);
+ Standard_Integer aBits = getProgramBits (theTexture, theHasVertColor);
+ if (theAspect->Type() != Aspect_TOL_SOLID)
+ {
+ aBits |= OpenGl_PO_StippleLine;
+ }
+
Handle(OpenGl_ShaderProgram)& aProgram = getStdProgram (theToLightOn, aBits);
return bindProgramWithState (aProgram, theAspect);
}
AspectFace(Standard_True);
AspectMarker(Standard_True);
AspectText(Standard_True);
+
+ myGlContext->SetTypeOfLine (myDefaultAspectLine.Type());
+ myGlContext->SetLineWidth (myDefaultAspectLine.Width());
}
// =======================================================================
/*----------------------------------------------------------------------*/
-const OpenGl_AspectLine * OpenGl_Workspace::AspectLine(const Standard_Boolean WithApply)
+const OpenGl_AspectLine * OpenGl_Workspace::AspectLine(const Standard_Boolean theWithApply)
{
- if ( WithApply && (AspectLine_set != AspectLine_applied) )
+ if (theWithApply)
{
- myGlContext->SetColor4fv (*(const OpenGl_Vec4* )AspectLine_set->Color().rgb);
- if ( !AspectLine_applied || (AspectLine_set->Type() != AspectLine_applied->Type() ) )
- {
- myLineAttribs->SetTypeOfLine (AspectLine_set->Type());
- }
-
- if ( !AspectLine_applied || ( AspectLine_set->Width() != AspectLine_applied->Width() ) )
- {
- glLineWidth( (GLfloat)AspectLine_set->Width() );
-#ifdef HAVE_GL2PS
- gl2psLineWidth( (GLfloat)AspectLine_set->Width() );
-#endif
- }
-
AspectLine_applied = AspectLine_set;
}
+
return AspectLine_set;
}
Standard_Integer ToSetLineWidth;
Standard_Real LineWidth;
+ Standard_Integer ToSetTypeOfLine;
+ Aspect_TypeOfLine TypeOfLine;
+
Standard_Integer ToSetTransparency;
Standard_Real Transparency;
Color (DEFAULT_COLOR),
ToSetLineWidth (0),
LineWidth (1.0),
+ ToSetTypeOfLine (0),
+ TypeOfLine (Aspect_TOL_SOLID),
ToSetTransparency (0),
Transparency (0.0),
ToSetMaterial (0),
aChangeSet->ToSetColor = 1;
anArgIter += aNbComps;
}
+ else if (anArg == "-setlinetype")
+ {
+ if (++anArgIter >= theArgNb)
+ {
+ std::cout << "Error: wrong syntax at " << anArg << "\n";
+ return 1;
+ }
+
+ TCollection_AsciiString aValue (theArgVec[anArgIter]);
+ aValue.LowerCase();
+
+ if (aValue.IsEqual ("solid"))
+ {
+ aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
+ }
+ else if (aValue.IsEqual ("dot"))
+ {
+ aChangeSet->TypeOfLine = Aspect_TOL_DOT;
+ }
+ else if (aValue.IsEqual ("dash"))
+ {
+ aChangeSet->TypeOfLine = Aspect_TOL_DASH;
+ }
+ else if (aValue.IsEqual ("dotdash"))
+ {
+ aChangeSet->TypeOfLine = Aspect_TOL_DOTDASH;
+ }
+ else
+ {
+ std::cout << "Error: wrong syntax at " << anArg << "\n";
+ return 1;
+ }
+
+ aChangeSet->ToSetTypeOfLine = 1;
+ }
+ else if (anArg == "-unsetlinetype")
+ {
+ aChangeSet->ToSetTypeOfLine = -1;
+ }
else if (anArg == "-unsetcolor")
{
aChangeSet->ToSetColor = -1;
aChangeSet->Visibility = 1;
aChangeSet->ToSetLineWidth = -1;
aChangeSet->LineWidth = 1.0;
+ aChangeSet->ToSetTypeOfLine = -1;
+ aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
aChangeSet->ToSetTransparency = -1;
aChangeSet->Transparency = 0.0;
aChangeSet->ToSetColor = -1;
aDrawer->WireAspect()->SetColor (aChangeSet->Color);
aDrawer->PointAspect()->SetColor (aChangeSet->Color);
}
+ if (aChangeSet->ToSetTypeOfLine != 0)
+ {
+ aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
+ aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
+ aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
+ aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
+ aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
+ }
if (aChangeSet->ToSetTransparency != 0)
{
aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
toRedisplay = Standard_True;
}
+ if (aChangeSet->ToSetTypeOfLine != 0)
+ {
+ aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
+ aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
+ aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
+ aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
+ aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
+ toRedisplay = Standard_True;
+ }
}
for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
theCommands.Add("vaspects",
"vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
- "\n\t\t: [-setvisibility 0|1]"
- "\n\t\t: [-setcolor ColorName] [-setcolor R G B] [-unsetcolor]"
- "\n\t\t: [-setmaterial MatName] [-unsetmaterial]"
- "\n\t\t: [-settransparency Transp] [-unsettransparency]"
- "\n\t\t: [-setwidth LineWidth] [-unsetwidth]"
+ "\n\t\t: [-setVisibility 0|1]"
+ "\n\t\t: [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
+ "\n\t\t: [-setMaterial MatName] [-unsetMaterial]"
+ "\n\t\t: [-setTransparency Transp] [-unsetTransparency]"
+ "\n\t\t: [-setWidth LineWidth] [-unsetWidth]"
+ "\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
"\n\t\t: [-freeBoundary {off/on | 0/1}]"
"\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
"\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
--- /dev/null
+restore [locate_data_file occ/fuse.brep] f
+
+vcaps -ffp 1
+vinit View1
+vclear
+vsetdispmode 0
+vaxo
+vdisplay f
+vaspects f -setLineType dotDash
+vfit
+vdump $::imagedir/${::casename}_ffp.png
+
+vcaps -ffp 0
+vdump $::imagedir/${::casename}_glsl.png