1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-06 18:26:22 +03:00

0030005: Visualization, OpenGl_Context - replace NCollection_SparseArray with NCollection_Array1 for myDrawBuffers

This commit is contained in:
kgv 2018-07-31 22:12:04 +03:00 committed by bugmaster
parent b11aef43d4
commit c348746059
2 changed files with 29 additions and 28 deletions

View File

@ -180,7 +180,7 @@ OpenGl_Context::OpenGl_Context (const Handle(OpenGl_Caps)& theCaps)
#endif #endif
myToCullBackFaces (false), myToCullBackFaces (false),
myReadBuffer (0), myReadBuffer (0),
myDrawBuffers (1), myDrawBuffers (0, 7),
myDefaultVao (0), myDefaultVao (0),
myColorMask (true), myColorMask (true),
myAlphaToCoverage (false), myAlphaToCoverage (false),
@ -410,12 +410,8 @@ void OpenGl_Context::SetDrawBuffer (const Standard_Integer theDrawBuffer)
} }
::glDrawBuffer (aDrawBuffer); ::glDrawBuffer (aDrawBuffer);
myDrawBuffers.Clear(); myDrawBuffers.Init (GL_NONE);
myDrawBuffers.SetValue (0, aDrawBuffer);
if (aDrawBuffer != GL_NONE)
{
myDrawBuffers.SetValue (0, aDrawBuffer);
}
#else #else
(void )theDrawBuffer; (void )theDrawBuffer;
#endif #endif
@ -429,7 +425,12 @@ void OpenGl_Context::SetDrawBuffers (const Standard_Integer theNb, const Standar
{ {
Standard_ASSERT_RETURN (hasDrawBuffers, "Multiple draw buffers feature is not supported by the context", Standard_ASSERT_DO_NOTHING()); Standard_ASSERT_RETURN (hasDrawBuffers, "Multiple draw buffers feature is not supported by the context", Standard_ASSERT_DO_NOTHING());
myDrawBuffers.Clear(); if (myDrawBuffers.Length() < theNb)
{
// should actually never happen here
myDrawBuffers.Resize (0, theNb - 1, false);
}
myDrawBuffers.Init (GL_NONE);
Standard_Boolean useDefaultFbo = Standard_False; Standard_Boolean useDefaultFbo = Standard_False;
for (Standard_Integer anI = 0; anI < theNb; ++anI) for (Standard_Integer anI = 0; anI < theNb; ++anI)
@ -438,7 +439,7 @@ void OpenGl_Context::SetDrawBuffers (const Standard_Integer theNb, const Standar
{ {
useDefaultFbo = Standard_True; useDefaultFbo = Standard_True;
} }
else if (theDrawBuffers[anI] != GL_NONE) else
{ {
myDrawBuffers.SetValue (anI, theDrawBuffers[anI]); myDrawBuffers.SetValue (anI, theDrawBuffers[anI]);
} }
@ -491,31 +492,24 @@ void OpenGl_Context::FetchState()
::glGetIntegerv (GL_READ_BUFFER, &myReadBuffer); ::glGetIntegerv (GL_READ_BUFFER, &myReadBuffer);
// cache draw buffers state // cache draw buffers state
myDrawBuffers.Clear(); if (myDrawBuffers.Length() < myMaxDrawBuffers)
{
myDrawBuffers.Resize (0, myMaxDrawBuffers - 1, false);
}
myDrawBuffers.Init (GL_NONE);
Standard_Integer aDrawBuffer = GL_NONE;
if (myMaxDrawBuffers == 1) if (myMaxDrawBuffers == 1)
{ {
Standard_Integer aDrawBuffer;
::glGetIntegerv (GL_DRAW_BUFFER, &aDrawBuffer); ::glGetIntegerv (GL_DRAW_BUFFER, &aDrawBuffer);
myDrawBuffers.SetValue (0, aDrawBuffer);
if (aDrawBuffer != GL_NONE)
{
myDrawBuffers.SetValue (0, aDrawBuffer);
}
} }
else else
{ {
Standard_Integer aDrawBuffer;
for (Standard_Integer anI = 0; anI < myMaxDrawBuffers; ++anI) for (Standard_Integer anI = 0; anI < myMaxDrawBuffers; ++anI)
{ {
::glGetIntegerv (GL_DRAW_BUFFER0 + anI, &aDrawBuffer); ::glGetIntegerv (GL_DRAW_BUFFER0 + anI, &aDrawBuffer);
myDrawBuffers.SetValue (anI, aDrawBuffer);
if (aDrawBuffer != GL_NONE)
{
myDrawBuffers.SetValue (anI, aDrawBuffer);
}
} }
} }
#endif #endif
@ -1452,6 +1446,10 @@ void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile)
{ {
glGetIntegerv (GL_MAX_DRAW_BUFFERS, &myMaxDrawBuffers); glGetIntegerv (GL_MAX_DRAW_BUFFERS, &myMaxDrawBuffers);
glGetIntegerv (GL_MAX_COLOR_ATTACHMENTS, &myMaxColorAttachments); glGetIntegerv (GL_MAX_COLOR_ATTACHMENTS, &myMaxColorAttachments);
if (myDrawBuffers.Length() < myMaxDrawBuffers)
{
myDrawBuffers.Resize (0, myMaxDrawBuffers - 1, false);
}
} }
glGetIntegerv (GL_MAX_TEXTURE_SIZE, &myMaxTexDim); glGetIntegerv (GL_MAX_TEXTURE_SIZE, &myMaxTexDim);

View File

@ -622,9 +622,12 @@ public: //! @name methods to alter or retrieve current state
Standard_EXPORT void SetReadBuffer (const Standard_Integer theReadBuffer); Standard_EXPORT void SetReadBuffer (const Standard_Integer theReadBuffer);
//! Return active draw buffer attached to a render target referred by index (layout location). //! Return active draw buffer attached to a render target referred by index (layout location).
Standard_Integer DrawBuffer (const Standard_Integer theIndex = 0) Standard_Integer DrawBuffer (Standard_Integer theIndex = 0) const
{ {
return myDrawBuffers.IsBound (theIndex) ? myDrawBuffers.Value (theIndex) : GL_NONE; return theIndex >= myDrawBuffers.Lower()
&& theIndex <= myDrawBuffers.Upper()
? myDrawBuffers.Value (theIndex)
: GL_NONE;
} }
//! Switch draw buffer, wrapper for ::glDrawBuffer(). //! Switch draw buffer, wrapper for ::glDrawBuffer().
@ -884,7 +887,6 @@ private: // context info
typedef NCollection_Shared< NCollection_DataMap<TCollection_AsciiString, Standard_Integer> > OpenGl_DelayReleaseMap; typedef NCollection_Shared< NCollection_DataMap<TCollection_AsciiString, Standard_Integer> > OpenGl_DelayReleaseMap;
typedef NCollection_Shared< NCollection_List<Handle(OpenGl_Resource)> > OpenGl_ResourcesStack; typedef NCollection_Shared< NCollection_List<Handle(OpenGl_Resource)> > OpenGl_ResourcesStack;
typedef NCollection_SparseArray<Standard_Integer> OpenGl_DrawBuffers;
Handle(OpenGl_ResourcesMap) mySharedResources; //!< shared resources with unique identification key Handle(OpenGl_ResourcesMap) mySharedResources; //!< shared resources with unique identification key
Handle(OpenGl_DelayReleaseMap) myDelayed; //!< shared resources for delayed release Handle(OpenGl_DelayReleaseMap) myDelayed; //!< shared resources for delayed release
@ -932,7 +934,8 @@ private: //! @name fields tracking current state
Graphic3d_PolygonOffset myPolygonOffset; //!< currently applied polygon offset Graphic3d_PolygonOffset myPolygonOffset; //!< currently applied polygon offset
bool myToCullBackFaces; //!< back face culling mode enabled state (glIsEnabled (GL_CULL_FACE)) bool myToCullBackFaces; //!< back face culling mode enabled state (glIsEnabled (GL_CULL_FACE))
Standard_Integer myReadBuffer; //!< current read buffer Standard_Integer myReadBuffer; //!< current read buffer
OpenGl_DrawBuffers myDrawBuffers; //!< current draw buffers NCollection_Array1<Standard_Integer>
myDrawBuffers; //!< current draw buffers
unsigned int myDefaultVao; //!< default Vertex Array Object unsigned int myDefaultVao; //!< default Vertex Array Object
Standard_Boolean myColorMask; //!< flag indicating writing into color buffer is enabled or disabled (glColorMask) Standard_Boolean myColorMask; //!< flag indicating writing into color buffer is enabled or disabled (glColorMask)
Standard_Boolean myAlphaToCoverage; //!< flag indicating GL_SAMPLE_ALPHA_TO_COVERAGE state Standard_Boolean myAlphaToCoverage; //!< flag indicating GL_SAMPLE_ALPHA_TO_COVERAGE state