@@ -698,56 +698,35 @@ void State::setStencilClearValue(int stencil)
698698
699699void State::setColorMask (bool red, bool green, bool blue, bool alpha)
700700{
701- for (BlendState &blendState : mBlendStateArray )
702- {
703- blendState.colorMaskRed = red;
704- blendState.colorMaskGreen = green;
705- blendState.colorMaskBlue = blue;
706- blendState.colorMaskAlpha = alpha;
707- }
701+ mBlendState .colorMaskRed = red;
702+ mBlendState .colorMaskGreen = green;
703+ mBlendState .colorMaskBlue = blue;
704+ mBlendState .colorMaskAlpha = alpha;
708705
709706 mBlendStateExt .setColorMask (red, green, blue, alpha);
710707 mDirtyBits .set (DIRTY_BIT_COLOR_MASK);
711708}
712709
713710void State::setColorMaskIndexed (bool red, bool green, bool blue, bool alpha, GLuint index)
714711{
715- ASSERT (index < mBlendStateArray .size ());
716- mBlendStateArray [index].colorMaskRed = red;
717- mBlendStateArray [index].colorMaskGreen = green;
718- mBlendStateArray [index].colorMaskBlue = blue;
719- mBlendStateArray [index].colorMaskAlpha = alpha;
720-
721712 mBlendStateExt .setColorMaskIndexed (index, red, green, blue, alpha);
722713 mDirtyBits .set (DIRTY_BIT_COLOR_MASK);
723714}
724715
725716bool State::allActiveDrawBufferChannelsMasked () const
726717{
727- for (size_t drawBufferIndex : mDrawFramebuffer ->getDrawBufferMask ())
728- {
729- const BlendState &blendState = mBlendStateArray [drawBufferIndex];
730- if (blendState.colorMaskRed || blendState.colorMaskGreen || blendState.colorMaskBlue ||
731- blendState.colorMaskAlpha )
732- {
733- return false ;
734- }
735- }
736- return true ;
718+ // Compare current color mask with all-disabled color mask, while ignoring disabled draw
719+ // buffers.
720+ return (mBlendStateExt .compareColorMask (0 ) & mDrawFramebuffer ->getDrawBufferMask ()).none ();
737721}
738722
739723bool State::anyActiveDrawBufferChannelMasked () const
740724{
741- for (size_t drawBufferIndex : mDrawFramebuffer ->getDrawBufferMask ())
742- {
743- const BlendState &blendState = mBlendStateArray [drawBufferIndex];
744- if (!(blendState.colorMaskRed && blendState.colorMaskGreen && blendState.colorMaskBlue &&
745- blendState.colorMaskAlpha ))
746- {
747- return true ;
748- }
749- }
750- return false ;
725+ // Compare current color mask with all-enabled color mask, while ignoring disabled draw
726+ // buffers.
727+ return (mBlendStateExt .compareColorMask (mBlendStateExt .mMaxColorMask ) &
728+ mDrawFramebuffer ->getDrawBufferMask ())
729+ .any ();
751730}
752731
753732void State::setDepthMask (bool mask)
@@ -813,31 +792,25 @@ void State::setDepthRange(float zNear, float zFar)
813792
814793void State::setBlend (bool enabled)
815794{
816- for (BlendState &blendState : mBlendStateArray )
817- {
818- blendState.blend = enabled;
819- }
795+ mBlendState .blend = enabled;
796+
820797 mBlendStateExt .setEnabled (enabled);
821798 mDirtyBits .set (DIRTY_BIT_BLEND_ENABLED);
822799}
823800
824801void State::setBlendIndexed (bool enabled, GLuint index)
825802{
826- ASSERT (index < mBlendStateArray .size ());
827- mBlendStateArray [index].blend = enabled;
828803 mBlendStateExt .setEnabledIndexed (index, enabled);
829804 mDirtyBits .set (DIRTY_BIT_BLEND_ENABLED);
830805}
831806
832807void State::setBlendFactors (GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha)
833808{
834- for (BlendState &blendState : mBlendStateArray )
835- {
836- blendState.sourceBlendRGB = sourceRGB;
837- blendState.destBlendRGB = destRGB;
838- blendState.sourceBlendAlpha = sourceAlpha;
839- blendState.destBlendAlpha = destAlpha;
840- }
809+
810+ mBlendState .sourceBlendRGB = sourceRGB;
811+ mBlendState .destBlendRGB = destRGB;
812+ mBlendState .sourceBlendAlpha = sourceAlpha;
813+ mBlendState .destBlendAlpha = destAlpha;
841814
842815 if (mNoSimultaneousConstantColorAndAlphaBlendFunc )
843816 {
@@ -870,12 +843,6 @@ void State::setBlendFactorsIndexed(GLenum sourceRGB,
870843 GLenum destAlpha,
871844 GLuint index)
872845{
873- ASSERT (index < mBlendStateArray .size ());
874- mBlendStateArray [index].sourceBlendRGB = sourceRGB;
875- mBlendStateArray [index].destBlendRGB = destRGB;
876- mBlendStateArray [index].sourceBlendAlpha = sourceAlpha;
877- mBlendStateArray [index].destBlendAlpha = destAlpha;
878-
879846 if (mNoSimultaneousConstantColorAndAlphaBlendFunc )
880847 {
881848 mBlendFuncConstantColorDrawBuffers .set (index, hasConstantColor (sourceRGB, destRGB));
@@ -911,22 +878,15 @@ void State::setBlendColor(float red, float green, float blue, float alpha)
911878
912879void State::setBlendEquation (GLenum rgbEquation, GLenum alphaEquation)
913880{
914- for (BlendState &blendState : mBlendStateArray )
915- {
916- blendState.blendEquationRGB = rgbEquation;
917- blendState.blendEquationAlpha = alphaEquation;
918- }
881+ mBlendState .blendEquationRGB = rgbEquation;
882+ mBlendState .blendEquationAlpha = alphaEquation;
919883
920884 mBlendStateExt .setEquations (rgbEquation, alphaEquation);
921885 mDirtyBits .set (DIRTY_BIT_BLEND_EQUATIONS);
922886}
923887
924888void State::setBlendEquationIndexed (GLenum rgbEquation, GLenum alphaEquation, GLuint index)
925889{
926- ASSERT (index < mBlendStateArray .size ());
927- mBlendStateArray [index].blendEquationRGB = rgbEquation;
928- mBlendStateArray [index].blendEquationAlpha = alphaEquation;
929-
930890 mBlendStateExt .setEquationsIndexed (index, rgbEquation, alphaEquation);
931891 mDirtyBits .set (DIRTY_BIT_BLEND_EQUATIONS);
932892}
@@ -2232,12 +2192,16 @@ void State::getBooleanv(GLenum pname, GLboolean *params) const
22322192 *params = mDepthStencil .depthMask ;
22332193 break ;
22342194 case GL_COLOR_WRITEMASK:
2195+ {
22352196 // non-indexed get returns the state of draw buffer zero
2236- params[0 ] = mBlendStateArray [0 ].colorMaskRed ;
2237- params[1 ] = mBlendStateArray [0 ].colorMaskGreen ;
2238- params[2 ] = mBlendStateArray [0 ].colorMaskBlue ;
2239- params[3 ] = mBlendStateArray [0 ].colorMaskAlpha ;
2197+ bool r, g, b, a;
2198+ mBlendStateExt .getColorMaskIndexed (0 , &r, &g, &b, &a);
2199+ params[0 ] = r;
2200+ params[1 ] = g;
2201+ params[2 ] = b;
2202+ params[3 ] = a;
22402203 break ;
2204+ }
22412205 case GL_CULL_FACE:
22422206 *params = mRasterizer .cullFace ;
22432207 break ;
@@ -2264,7 +2228,7 @@ void State::getBooleanv(GLenum pname, GLboolean *params) const
22642228 break ;
22652229 case GL_BLEND:
22662230 // non-indexed get returns the state of draw buffer zero
2267- *params = mBlendStateArray [ 0 ]. blend ;
2231+ *params = mBlendStateExt . mEnabledMask . test ( 0 ) ;
22682232 break ;
22692233 case GL_DITHER:
22702234 *params = mRasterizer .dither ;
@@ -2579,22 +2543,22 @@ angle::Result State::getIntegerv(const Context *context, GLenum pname, GLint *pa
25792543 break ;
25802544 case GL_BLEND_SRC_RGB:
25812545 // non-indexed get returns the state of draw buffer zero
2582- *params = mBlendStateArray [ 0 ]. sourceBlendRGB ;
2546+ *params = mBlendStateExt . getSrcColorIndexed ( 0 ) ;
25832547 break ;
25842548 case GL_BLEND_SRC_ALPHA:
2585- *params = mBlendStateArray [ 0 ]. sourceBlendAlpha ;
2549+ *params = mBlendStateExt . getSrcAlphaIndexed ( 0 ) ;
25862550 break ;
25872551 case GL_BLEND_DST_RGB:
2588- *params = mBlendStateArray [ 0 ]. destBlendRGB ;
2552+ *params = mBlendStateExt . getDstColorIndexed ( 0 ) ;
25892553 break ;
25902554 case GL_BLEND_DST_ALPHA:
2591- *params = mBlendStateArray [ 0 ]. destBlendAlpha ;
2555+ *params = mBlendStateExt . getDstAlphaIndexed ( 0 ) ;
25922556 break ;
25932557 case GL_BLEND_EQUATION_RGB:
2594- *params = mBlendStateArray [ 0 ]. blendEquationRGB ;
2558+ *params = mBlendStateExt . getEquationColorIndexed ( 0 ) ;
25952559 break ;
25962560 case GL_BLEND_EQUATION_ALPHA:
2597- *params = mBlendStateArray [ 0 ]. blendEquationAlpha ;
2561+ *params = mBlendStateExt . getEquationAlphaIndexed ( 0 ) ;
25982562 break ;
25992563 case GL_STENCIL_WRITEMASK:
26002564 *params = CastMaskValue (mDepthStencil .stencilWritemask );
@@ -2852,10 +2816,10 @@ angle::Result State::getIntegerv(const Context *context, GLenum pname, GLint *pa
28522816 break ;
28532817 case GL_BLEND_SRC:
28542818 // non-indexed get returns the state of draw buffer zero
2855- *params = mBlendStateArray [ 0 ]. sourceBlendRGB ;
2819+ *params = mBlendStateExt . getSrcColorIndexed ( 0 ) ;
28562820 break ;
28572821 case GL_BLEND_DST:
2858- *params = mBlendStateArray [ 0 ]. destBlendRGB ;
2822+ *params = mBlendStateExt . getDstColorIndexed ( 0 ) ;
28592823 break ;
28602824 case GL_PERSPECTIVE_CORRECTION_HINT:
28612825 case GL_POINT_SMOOTH_HINT:
@@ -2921,28 +2885,28 @@ void State::getIntegeri_v(GLenum target, GLuint index, GLint *data) const
29212885 switch (target)
29222886 {
29232887 case GL_BLEND_SRC_RGB:
2924- ASSERT (static_cast <size_t >(index) < mBlendStateArray . size () );
2925- *data = mBlendStateArray [index]. sourceBlendRGB ;
2888+ ASSERT (static_cast <size_t >(index) < mBlendStateExt . mMaxDrawBuffers );
2889+ *data = mBlendStateExt . getSrcColorIndexed (index) ;
29262890 break ;
29272891 case GL_BLEND_SRC_ALPHA:
2928- ASSERT (static_cast <size_t >(index) < mBlendStateArray . size () );
2929- *data = mBlendStateArray [index]. sourceBlendAlpha ;
2892+ ASSERT (static_cast <size_t >(index) < mBlendStateExt . mMaxDrawBuffers );
2893+ *data = mBlendStateExt . getSrcAlphaIndexed (index) ;
29302894 break ;
29312895 case GL_BLEND_DST_RGB:
2932- ASSERT (static_cast <size_t >(index) < mBlendStateArray . size () );
2933- *data = mBlendStateArray [index]. destBlendRGB ;
2896+ ASSERT (static_cast <size_t >(index) < mBlendStateExt . mMaxDrawBuffers );
2897+ *data = mBlendStateExt . getDstColorIndexed (index) ;
29342898 break ;
29352899 case GL_BLEND_DST_ALPHA:
2936- ASSERT (static_cast <size_t >(index) < mBlendStateArray . size () );
2937- *data = mBlendStateArray [index]. destBlendAlpha ;
2900+ ASSERT (static_cast <size_t >(index) < mBlendStateExt . mMaxDrawBuffers );
2901+ *data = mBlendStateExt . getDstAlphaIndexed (index) ;
29382902 break ;
29392903 case GL_BLEND_EQUATION_RGB:
2940- ASSERT (static_cast <size_t >(index) < mBlendStateArray . size () );
2941- *data = mBlendStateArray [index]. blendEquationRGB ;
2904+ ASSERT (static_cast <size_t >(index) < mBlendStateExt . mMaxDrawBuffers );
2905+ *data = mBlendStateExt . getEquationColorIndexed (index) ;
29422906 break ;
29432907 case GL_BLEND_EQUATION_ALPHA:
2944- ASSERT (static_cast <size_t >(index) < mBlendStateArray . size () );
2945- *data = mBlendStateArray [index]. blendEquationAlpha ;
2908+ ASSERT (static_cast <size_t >(index) < mBlendStateExt . mMaxDrawBuffers );
2909+ *data = mBlendStateExt . getEquationAlphaIndexed (index) ;
29462910 break ;
29472911 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
29482912 ASSERT (static_cast <size_t >(index) < mTransformFeedback ->getIndexedBufferCount ());
@@ -3053,12 +3017,16 @@ void State::getBooleani_v(GLenum target, GLuint index, GLboolean *data) const
30533017 switch (target)
30543018 {
30553019 case GL_COLOR_WRITEMASK:
3056- ASSERT (static_cast <size_t >(index) < mBlendStateArray .size ());
3057- data[0 ] = mBlendStateArray [index].colorMaskRed ;
3058- data[1 ] = mBlendStateArray [index].colorMaskGreen ;
3059- data[2 ] = mBlendStateArray [index].colorMaskBlue ;
3060- data[3 ] = mBlendStateArray [index].colorMaskAlpha ;
3020+ {
3021+ ASSERT (static_cast <size_t >(index) < mBlendStateExt .mMaxDrawBuffers );
3022+ bool r, g, b, a;
3023+ mBlendStateExt .getColorMaskIndexed (index, &r, &g, &b, &a);
3024+ data[0 ] = r;
3025+ data[1 ] = g;
3026+ data[2 ] = b;
3027+ data[3 ] = a;
30613028 break ;
3029+ }
30623030 case GL_IMAGE_BINDING_LAYERED:
30633031 ASSERT (static_cast <size_t >(index) < mImageUnits .size ());
30643032 *data = mImageUnits [index].layered ;
0 commit comments