1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-02 17:46:22 +03:00

Add additional TypeOfAttribute for back vertex color

This commit is contained in:
mzernova 2024-08-19 12:27:38 +01:00
parent 4c1ce53d99
commit 2192e732c8
11 changed files with 37 additions and 6 deletions

View File

@ -98,6 +98,7 @@ void Graphic3d_ArrayOfPrimitives::init (Graphic3d_TypeOfPrimitiveArray theType,
myNormData = NULL;
myTexData = NULL;
myColData = NULL;
myColDataBack = NULL;
myAttribs.Nullify();
myIndices.Nullify();
myBounds.Nullify();
@ -171,6 +172,10 @@ void Graphic3d_ArrayOfPrimitives::init (Graphic3d_TypeOfPrimitiveArray theType,
anAttribs[aNbAttribs].Id = Graphic3d_TOA_COLOR;
anAttribs[aNbAttribs].DataType = Graphic3d_TOD_VEC4UB;
++aNbAttribs;
anAttribs[aNbAttribs].Id = Graphic3d_TOA_COLOR_BACK;
anAttribs[aNbAttribs].DataType = Graphic3d_TOD_VEC4UB;
++aNbAttribs;
}
if (!myAttribs->Init (theMaxVertexs, anAttribs, aNbAttribs))
@ -185,6 +190,7 @@ void Graphic3d_ArrayOfPrimitives::init (Graphic3d_TypeOfPrimitiveArray theType,
myNormData = myAttribs->ChangeAttributeData (Graphic3d_TOA_NORM, anAttribDummy, myNormStride);
myTexData = myAttribs->ChangeAttributeData (Graphic3d_TOA_UV, anAttribDummy, myTexStride);
myColData = myAttribs->ChangeAttributeData (Graphic3d_TOA_COLOR, anAttribDummy, myColStride);
myColDataBack = myAttribs->ChangeAttributeData (Graphic3d_TOA_COLOR_BACK, anAttribDummy, myColStrideBack);
memset (myAttribs->ChangeData(), 0, size_t(myAttribs->Stride) * size_t(myAttribs->NbMaxElements()));
if ((theArrayOptions & Graphic3d_ArrayFlags_AttribsMutable) == 0

View File

@ -806,7 +806,7 @@ protected: //! @name protected constructors
Standard_Integer theMaxBounds,
Standard_Integer theMaxEdges,
Graphic3d_ArrayFlags theArrayFlags)
: myNormData (NULL), myTexData (NULL), myColData (NULL), myPosStride (0), myNormStride (0), myTexStride (0), myColStride (0),
: myNormData (NULL), myTexData (NULL), myColData (NULL), myColDataBack (NULL), myPosStride (0), myNormStride (0), myTexStride (0), myColStride (0),
myType (Graphic3d_TOPA_UNDEFINED)
{
init (theType, theMaxVertexs, theMaxBounds, theMaxEdges, theArrayFlags);
@ -827,10 +827,12 @@ private: //! @name private fields
Standard_Byte* myNormData;
Standard_Byte* myTexData;
Standard_Byte* myColData;
Standard_Byte* myColDataBack;
Standard_Size myPosStride;
Standard_Size myNormStride;
Standard_Size myTexStride;
Standard_Size myColStride;
Standard_Size myColStrideBack;
Graphic3d_TypeOfPrimitiveArray myType;
};

View File

@ -27,6 +27,7 @@ enum Graphic3d_TypeOfAttribute
Graphic3d_TOA_NORM, //!< normal
Graphic3d_TOA_UV, //!< texture coordinates
Graphic3d_TOA_COLOR, //!< per-vertex color
Graphic3d_TOA_COLOR_BACK, //!< per-vertex color back
Graphic3d_TOA_CUSTOM, //!< custom attributes
};

View File

@ -1019,8 +1019,10 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getStdProgramUnlit (Sta
if ((theBits & Graphic3d_ShaderFlags_VertColor) != 0)
{
aStageInOuts.Append (Graphic3d_ShaderObject::ShaderVariable ("vec4 VertColor", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT));
aStageInOuts.Append (Graphic3d_ShaderObject::ShaderVariable ("vec4 VertColorBack", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT));
aSrcVertExtraMain += EOL" VertColor = occVertColor;";
aSrcFragGetColor = EOL"vec4 getColor(void) { return VertColor; }";
aSrcVertExtraMain += EOL" VertColorBack = occVertColorBack;";
aSrcFragGetColor = EOL"vec4 getColor(void) { return gl_FrontFacing ? VertColor : VertColorBack; }";
}
int aNbClipPlanes = 0;
@ -1430,7 +1432,7 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getStdProgramGouraud (c
if ((theBits & Graphic3d_ShaderFlags_VertColor) != 0)
{
aSrcVertColor = EOL"vec4 getVertColor(void) { return occVertColor; }";
aSrcVertColor = EOL"vec4 getVertColor(void) { return gl_FrontFacing ? VertColor : VertColorBack; }";
}
int aNbClipPlanes = 0;
@ -1617,8 +1619,10 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getStdProgramPhong (con
if ((theBits & Graphic3d_ShaderFlags_VertColor) != 0)
{
aStageInOuts.Append (Graphic3d_ShaderObject::ShaderVariable ("vec4 VertColor", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT));
aStageInOuts.Append (Graphic3d_ShaderObject::ShaderVariable ("vec4 VertColorBack", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT));
aSrcVertExtraMain += EOL" VertColor = occVertColor;";
aSrcFragGetVertColor = EOL"vec4 getVertColor(void) { return VertColor; }";
aSrcVertExtraMain += EOL" VertColorBack = occVertColorBack;";
aSrcFragGetVertColor = EOL"vec4 getVertColor(void) { return gl_FrontFacing ? VertColor : VertColorBack; }";
}
int aNbClipPlanes = 0;

View File

@ -201,7 +201,8 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG
Graphic3d_Attribute aGragientAttribInfo[] =
{
{ Graphic3d_TOA_POS, Graphic3d_TOD_VEC2 },
{ Graphic3d_TOA_COLOR, Graphic3d_TOD_VEC3 }
{ Graphic3d_TOA_COLOR, Graphic3d_TOD_VEC3 },
{ Graphic3d_TOA_COLOR_BACK, Graphic3d_TOD_VEC3 }
};
if (!myAttribs->Init (4, aGragientAttribInfo, 2))

View File

@ -427,11 +427,13 @@ void OpenGl_FrameStatsPrs::Render (const Handle(OpenGl_Workspace)& theWorkspace)
myChartVertices->Bind (aCtx);
myChartVertices->bindAttribute (aCtx, Graphic3d_TOA_POS, 3, GL_FLOAT, myChartVertices->GetComponentsNb(), NULL);
myChartVertices->bindAttribute (aCtx, Graphic3d_TOA_COLOR, 4, GL_UNSIGNED_BYTE, myChartVertices->GetComponentsNb(), (void* )sizeof(Graphic3d_Vec3));
myChartVertices->bindAttribute (aCtx, Graphic3d_TOA_COLOR_BACK, 5, GL_UNSIGNED_BYTE, myChartVertices->GetComponentsNb(), (void*)sizeof(Graphic3d_Vec3));
myChartIndices->Bind (aCtx);
aCtx->core15fwd->glDrawElements (GL_TRIANGLES, myChartIndices->GetElemsNb(), myChartIndices->GetDataType(), NULL);
myChartIndices->Unbind (aCtx);
myChartVertices->Unbind (aCtx);
myChartVertices->unbindAttribute (aCtx, Graphic3d_TOA_COLOR_BACK);
myChartVertices->unbindAttribute (aCtx, Graphic3d_TOA_COLOR);
myChartVertices->unbindAttribute (aCtx, Graphic3d_TOA_POS);
aCtx->core15fwd->glDisable (GL_BLEND);
@ -439,8 +441,10 @@ void OpenGl_FrameStatsPrs::Render (const Handle(OpenGl_Workspace)& theWorkspace)
myChartLines->Bind (aCtx);
myChartLines->bindAttribute (aCtx, Graphic3d_TOA_POS, 3, GL_FLOAT, myChartLines->GetComponentsNb(), NULL);
myChartLines->bindAttribute (aCtx, Graphic3d_TOA_COLOR, 4, GL_UNSIGNED_BYTE, myChartLines->GetComponentsNb(), (void* )sizeof(Graphic3d_Vec3));
myChartLines->bindAttribute (aCtx, Graphic3d_TOA_COLOR_BACK, 5, GL_UNSIGNED_BYTE, myChartLines->GetComponentsNb(), (void*)sizeof(Graphic3d_Vec3));
aCtx->core15fwd->glDrawArrays (GL_LINES, 0, myChartLines->GetElemsNb());
myChartLines->Unbind (aCtx);
myChartLines->unbindAttribute (aCtx, Graphic3d_TOA_COLOR_BACK);
myChartLines->unbindAttribute (aCtx, Graphic3d_TOA_COLOR);
myChartLines->unbindAttribute (aCtx, Graphic3d_TOA_POS);

View File

@ -432,6 +432,7 @@ void OpenGl_PrimitiveArray::drawArray (const Handle(OpenGl_Workspace)& theWorksp
{
// disable per-vertex color
OpenGl_VertexBuffer::unbindAttribute (aGlContext, Graphic3d_TOA_COLOR);
OpenGl_VertexBuffer::unbindAttribute (aGlContext, Graphic3d_TOA_COLOR_BACK);
}
if (!myVboIndices.IsNull())
{

View File

@ -510,6 +510,7 @@ Standard_Boolean OpenGl_ShaderProgram::Initialize (const Handle(OpenGl_Context)&
SetAttributeName (theCtx, Graphic3d_TOA_NORM, "occNormal");
SetAttributeName (theCtx, Graphic3d_TOA_UV, "occTexCoord");
SetAttributeName (theCtx, Graphic3d_TOA_COLOR, "occVertColor");
SetAttributeName (theCtx, Graphic3d_TOA_COLOR_BACK, "occVertColorBack");
// bind custom Vertex Attributes
if (!myProxy.IsNull())

View File

@ -205,7 +205,15 @@ void OpenGl_VertexBuffer::bindFixed (const Handle(OpenGl_Context)& theCtx,
{
theCtx->core11ffp->glEnableClientState (GL_COLOR_ARRAY);
theCtx->core11ffp->glColorPointer (theNbComp, theDataType, theStride, theOffset);
theCtx->core11ffp->glColorMaterial (GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
theCtx->core11ffp->glColorMaterial (GL_FRONT,GL_AMBIENT_AND_DIFFUSE);
theCtx->core11fwd->glEnable (GL_COLOR_MATERIAL);
return;
}
case Graphic3d_TOA_COLOR_BACK:
{
theCtx->core11ffp->glEnableClientState (GL_COLOR_ARRAY);
theCtx->core11ffp->glColorPointer (theNbComp, theDataType, theStride, theOffset);
theCtx->core11ffp->glColorMaterial (GL_BACK, GL_AMBIENT_AND_DIFFUSE);
theCtx->core11fwd->glEnable (GL_COLOR_MATERIAL);
return;
}
@ -229,6 +237,7 @@ void OpenGl_VertexBuffer::unbindFixed (const Handle(OpenGl_Context)& theCtx,
case Graphic3d_TOA_NORM: theCtx->core11ffp->glDisableClientState (GL_NORMAL_ARRAY); return;
case Graphic3d_TOA_UV: theCtx->core11ffp->glDisableClientState (GL_TEXTURE_COORD_ARRAY); return;
case Graphic3d_TOA_COLOR: unbindFixedColor (theCtx); return;
case Graphic3d_TOA_COLOR_BACK:
case Graphic3d_TOA_CUSTOM:
{
return;

View File

@ -55,6 +55,7 @@
THE_ATTRIBUTE vec3 occNormal;
THE_ATTRIBUTE vec4 occTexCoord;
THE_ATTRIBUTE vec4 occVertColor;
THE_ATTRIBUTE vec4 occVertColorBack;
#elif defined(FRAGMENT_SHADER)
#if (__VERSION__ >= 130)
#ifdef OCC_ENABLE_draw_buffers

View File

@ -58,6 +58,7 @@ static const char Shaders_Declarations_glsl[] =
" THE_ATTRIBUTE vec3 occNormal;\n"
" THE_ATTRIBUTE vec4 occTexCoord;\n"
" THE_ATTRIBUTE vec4 occVertColor;\n"
" THE_ATTRIBUTE vec4 occVertColorBack;\n"
"#elif defined(FRAGMENT_SHADER)\n"
" #if (__VERSION__ >= 130)\n"
" #ifdef OCC_ENABLE_draw_buffers\n"