diff --git a/src/OpenGl/OpenGl_Context.cxx b/src/OpenGl/OpenGl_Context.cxx index 4fa36fffae..6d07a82a8c 100644 --- a/src/OpenGl/OpenGl_Context.cxx +++ b/src/OpenGl/OpenGl_Context.cxx @@ -180,7 +180,7 @@ OpenGl_Context::OpenGl_Context (const Handle(OpenGl_Caps)& theCaps) #endif myToCullBackFaces (false), myReadBuffer (0), - myDrawBuffers (1), + myDrawBuffers (0, 7), myDefaultVao (0), myColorMask (true), myAlphaToCoverage (false), @@ -410,12 +410,8 @@ void OpenGl_Context::SetDrawBuffer (const Standard_Integer theDrawBuffer) } ::glDrawBuffer (aDrawBuffer); - myDrawBuffers.Clear(); - - if (aDrawBuffer != GL_NONE) - { - myDrawBuffers.SetValue (0, aDrawBuffer); - } + myDrawBuffers.Init (GL_NONE); + myDrawBuffers.SetValue (0, aDrawBuffer); #else (void )theDrawBuffer; #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()); - 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; 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; } - else if (theDrawBuffers[anI] != GL_NONE) + else { myDrawBuffers.SetValue (anI, theDrawBuffers[anI]); } @@ -491,31 +492,24 @@ void OpenGl_Context::FetchState() ::glGetIntegerv (GL_READ_BUFFER, &myReadBuffer); // 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) { - Standard_Integer aDrawBuffer; - ::glGetIntegerv (GL_DRAW_BUFFER, &aDrawBuffer); - - if (aDrawBuffer != GL_NONE) - { - myDrawBuffers.SetValue (0, aDrawBuffer); - } + myDrawBuffers.SetValue (0, aDrawBuffer); } else { - Standard_Integer aDrawBuffer; - for (Standard_Integer anI = 0; anI < myMaxDrawBuffers; ++anI) { ::glGetIntegerv (GL_DRAW_BUFFER0 + anI, &aDrawBuffer); - - if (aDrawBuffer != GL_NONE) - { - myDrawBuffers.SetValue (anI, aDrawBuffer); - } + myDrawBuffers.SetValue (anI, aDrawBuffer); } } #endif @@ -1452,6 +1446,10 @@ void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile) { glGetIntegerv (GL_MAX_DRAW_BUFFERS, &myMaxDrawBuffers); glGetIntegerv (GL_MAX_COLOR_ATTACHMENTS, &myMaxColorAttachments); + if (myDrawBuffers.Length() < myMaxDrawBuffers) + { + myDrawBuffers.Resize (0, myMaxDrawBuffers - 1, false); + } } glGetIntegerv (GL_MAX_TEXTURE_SIZE, &myMaxTexDim); diff --git a/src/OpenGl/OpenGl_Context.hxx b/src/OpenGl/OpenGl_Context.hxx index 96ac2636ee..36ef156f87 100644 --- a/src/OpenGl/OpenGl_Context.hxx +++ b/src/OpenGl/OpenGl_Context.hxx @@ -622,9 +622,12 @@ public: //! @name methods to alter or retrieve current state Standard_EXPORT void SetReadBuffer (const Standard_Integer theReadBuffer); //! 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(). @@ -884,7 +887,6 @@ private: // context info typedef NCollection_Shared< NCollection_DataMap > OpenGl_DelayReleaseMap; typedef NCollection_Shared< NCollection_List > OpenGl_ResourcesStack; - typedef NCollection_SparseArray OpenGl_DrawBuffers; Handle(OpenGl_ResourcesMap) mySharedResources; //!< shared resources with unique identification key 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 bool myToCullBackFaces; //!< back face culling mode enabled state (glIsEnabled (GL_CULL_FACE)) Standard_Integer myReadBuffer; //!< current read buffer - OpenGl_DrawBuffers myDrawBuffers; //!< current draw buffers + NCollection_Array1 + myDrawBuffers; //!< current draw buffers unsigned int myDefaultVao; //!< default Vertex Array Object 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