Lines Matching refs:ctx
49 legal_src_factor(const struct gl_context *ctx, GLenum factor)
68 return _mesa_is_desktop_gl(ctx) || ctx->API == API_OPENGLES2;
73 return ctx->API != API_OPENGLES
74 && ctx->Extensions.ARB_blend_func_extended;
86 legal_dst_factor(const struct gl_context *ctx, GLenum factor)
104 return _mesa_is_desktop_gl(ctx) || ctx->API == API_OPENGLES2;
106 return (ctx->API != API_OPENGLES
107 && ctx->Extensions.ARB_blend_func_extended)
108 || _mesa_is_gles3(ctx);
113 return ctx->API != API_OPENGLES
114 && ctx->Extensions.ARB_blend_func_extended;
127 validate_blend_factors(struct gl_context *ctx, const char *func,
131 if (!legal_src_factor(ctx, sfactorRGB)) {
132 _mesa_error(ctx, GL_INVALID_ENUM,
138 if (!legal_dst_factor(ctx, dfactorRGB)) {
139 _mesa_error(ctx, GL_INVALID_ENUM,
145 if (sfactorA != sfactorRGB && !legal_src_factor(ctx, sfactorA)) {
146 _mesa_error(ctx, GL_INVALID_ENUM,
152 if (dfactorA != dfactorRGB && !legal_dst_factor(ctx, dfactorA)) {
153 _mesa_error(ctx, GL_INVALID_ENUM,
173 update_uses_dual_src(struct gl_context *ctx, int buf)
176 (blend_factor_is_dual_src(ctx->Color.Blend[buf].SrcRGB) ||
177 blend_factor_is_dual_src(ctx->Color.Blend[buf].DstRGB) ||
178 blend_factor_is_dual_src(ctx->Color.Blend[buf].SrcA) ||
179 blend_factor_is_dual_src(ctx->Color.Blend[buf].DstA));
181 if (((ctx->Color._BlendUsesDualSrc >> buf) & 0x1) != uses_dual_src) {
183 ctx->Color._BlendUsesDualSrc |= 1 << buf;
185 ctx->Color._BlendUsesDualSrc &= ~(1 << buf);
197 num_buffers(const struct gl_context *ctx)
199 return ctx->Extensions.ARB_draw_buffers_blend
200 ? ctx->Const.MaxDrawBuffers : 1;
206 skip_blend_state_update(const struct gl_context *ctx,
211 if (ctx->Color._BlendFuncPerBuffer) {
212 const unsigned numBuffers = num_buffers(ctx);
216 if (ctx->Color.Blend[buf].SrcRGB != sfactorRGB ||
217 ctx->Color.Blend[buf].DstRGB != dfactorRGB ||
218 ctx->Color.Blend[buf].SrcA != sfactorA ||
219 ctx->Color.Blend[buf].DstA != dfactorA) {
226 if (ctx->Color.Blend[0].SrcRGB != sfactorRGB ||
227 ctx->Color.Blend[0].DstRGB != dfactorRGB ||
228 ctx->Color.Blend[0].SrcA != sfactorA ||
229 ctx->Color.Blend[0].DstA != dfactorA) {
239 blend_func_separate(struct gl_context *ctx,
243 FLUSH_VERTICES(ctx, 0, GL_COLOR_BUFFER_BIT);
244 ctx->NewDriverState |= ST_NEW_BLEND;
246 const unsigned numBuffers = num_buffers(ctx);
248 ctx->Color.Blend[buf].SrcRGB = sfactorRGB;
249 ctx->Color.Blend[buf].DstRGB = dfactorRGB;
250 ctx->Color.Blend[buf].SrcA = sfactorA;
251 ctx->Color.Blend[buf].DstA = dfactorA;
254 GLbitfield old_blend_uses_dual_src = ctx->Color._BlendUsesDualSrc;
255 update_uses_dual_src(ctx, 0);
257 if (ctx->Color._BlendUsesDualSrc & 0x1)
258 ctx->Color._BlendUsesDualSrc |= BITFIELD_RANGE(1, numBuffers - 1);
260 ctx->Color._BlendUsesDualSrc = 0;
262 if (ctx->Color._BlendUsesDualSrc != old_blend_uses_dual_src)
263 _mesa_update_valid_to_render_state(ctx);
265 ctx->Color._BlendFuncPerBuffer = GL_FALSE;
280 GET_CURRENT_CONTEXT(ctx);
282 if (skip_blend_state_update(ctx, sfactor, dfactor, sfactor, dfactor))
285 if (!validate_blend_factors(ctx, "glBlendFunc",
290 blend_func_separate(ctx, sfactor, dfactor, sfactor, dfactor);
297 GET_CURRENT_CONTEXT(ctx);
299 if (skip_blend_state_update(ctx, sfactor, dfactor, sfactor, dfactor))
302 blend_func_separate(ctx, sfactor, dfactor, sfactor, dfactor);
318 GET_CURRENT_CONTEXT(ctx);
321 _mesa_debug(ctx, "glBlendFuncSeparate %s %s %s %s\n",
329 if (skip_blend_state_update(ctx, sfactorRGB, dfactorRGB, sfactorA, dfactorA))
332 if (!validate_blend_factors(ctx, "glBlendFuncSeparate",
338 blend_func_separate(ctx, sfactorRGB, dfactorRGB, sfactorA, dfactorA);
346 GET_CURRENT_CONTEXT(ctx);
348 if (skip_blend_state_update(ctx, sfactorRGB, dfactorRGB, sfactorA, dfactorA))
351 blend_func_separate(ctx, sfactorRGB, dfactorRGB, sfactorA, dfactorA);
377 GET_CURRENT_CONTEXT(ctx);
380 if (!ctx->Extensions.ARB_draw_buffers_blend) {
381 _mesa_error(ctx, GL_INVALID_OPERATION, "glBlendFunc[Separate]i()");
385 if (buf >= ctx->Const.MaxDrawBuffers) {
386 _mesa_error(ctx, GL_INVALID_VALUE, "glBlendFuncSeparatei(buffer=%u)",
392 if (ctx->Color.Blend[buf].SrcRGB == sfactorRGB &&
393 ctx->Color.Blend[buf].DstRGB == dfactorRGB &&
394 ctx->Color.Blend[buf].SrcA == sfactorA &&
395 ctx->Color.Blend[buf].DstA == dfactorA)
398 if (!no_error && !validate_blend_factors(ctx, "glBlendFuncSeparatei",
404 FLUSH_VERTICES(ctx, 0, GL_COLOR_BUFFER_BIT);
405 ctx->NewDriverState |= ST_NEW_BLEND;
407 ctx->Color.Blend[buf].SrcRGB = sfactorRGB;
408 ctx->Color.Blend[buf].DstRGB = dfactorRGB;
409 ctx->Color.Blend[buf].SrcA = sfactorA;
410 ctx->Color.Blend[buf].DstA = dfactorA;
411 if (update_uses_dual_src(ctx, buf))
412 _mesa_update_valid_to_render_state(ctx);
413 ctx->Color._BlendFuncPerBuffer = GL_TRUE;
444 legal_simple_blend_equation(const struct gl_context *ctx, GLenum mode)
504 advanced_blend_mode(const struct gl_context *ctx, GLenum mode)
506 return _mesa_has_KHR_blend_equation_advanced(ctx) ?
511 set_advanced_blend_mode(struct gl_context *ctx,
514 if (ctx->Color._AdvancedBlendMode != advanced_mode) {
515 ctx->Color._AdvancedBlendMode = advanced_mode;
516 _mesa_update_valid_to_render_state(ctx);
524 GET_CURRENT_CONTEXT(ctx);
525 const unsigned numBuffers = num_buffers(ctx);
528 enum gl_advanced_blend_mode advanced_mode = advanced_blend_mode(ctx, mode);
531 _mesa_debug(ctx, "glBlendEquation(%s)\n",
534 if (ctx->Color._BlendEquationPerBuffer) {
537 if (ctx->Color.Blend[buf].EquationRGB != mode ||
538 ctx->Color.Blend[buf].EquationA != mode) {
546 if (ctx->Color.Blend[0].EquationRGB != mode ||
547 ctx->Color.Blend[0].EquationA != mode) {
556 if (!legal_simple_blend_equation(ctx, mode) && !advanced_mode) {
557 _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquation");
561 _mesa_flush_vertices_for_blend_adv(ctx, ctx->Color.BlendEnabled,
565 ctx->Color.Blend[buf].EquationRGB = mode;
566 ctx->Color.Blend[buf].EquationA = mode;
568 ctx->Color._BlendEquationPerBuffer = GL_FALSE;
569 set_advanced_blend_mode(ctx, advanced_mode);
577 blend_equationi(struct gl_context *ctx, GLuint buf, GLenum mode,
580 if (ctx->Color.Blend[buf].EquationRGB == mode &&
581 ctx->Color.Blend[buf].EquationA == mode)
584 _mesa_flush_vertices_for_blend_adv(ctx, ctx->Color.BlendEnabled,
586 ctx->Color.Blend[buf].EquationRGB = mode;
587 ctx->Color.Blend[buf].EquationA = mode;
588 ctx->Color._BlendEquationPerBuffer = GL_TRUE;
591 set_advanced_blend_mode(ctx, advanced_mode);
598 GET_CURRENT_CONTEXT(ctx);
600 enum gl_advanced_blend_mode advanced_mode = advanced_blend_mode(ctx, mode);
601 blend_equationi(ctx, buf, mode, advanced_mode);
608 GET_CURRENT_CONTEXT(ctx);
609 enum gl_advanced_blend_mode advanced_mode = advanced_blend_mode(ctx, mode);
612 _mesa_debug(ctx, "glBlendEquationi(%u, %s)\n",
615 if (buf >= ctx->Const.MaxDrawBuffers) {
616 _mesa_error(ctx, GL_INVALID_VALUE, "glBlendEquationi(buffer=%u)",
621 if (!legal_simple_blend_equation(ctx, mode) && !advanced_mode) {
622 _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquationi");
626 blend_equationi(ctx, buf, mode, advanced_mode);
631 blend_equation_separate(struct gl_context *ctx, GLenum modeRGB, GLenum modeA,
634 const unsigned numBuffers = num_buffers(ctx);
638 if (ctx->Color._BlendEquationPerBuffer) {
641 if (ctx->Color.Blend[buf].EquationRGB != modeRGB ||
642 ctx->Color.Blend[buf].EquationA != modeA) {
649 if (ctx->Color.Blend[0].EquationRGB != modeRGB ||
650 ctx->Color.Blend[0].EquationA != modeA) {
659 if ((modeRGB != modeA) && !ctx->Extensions.EXT_blend_equation_separate) {
660 _mesa_error(ctx, GL_INVALID_OPERATION,
671 if (!legal_simple_blend_equation(ctx, modeRGB)) {
672 _mesa_error(ctx, GL_INVALID_ENUM,
677 if (!legal_simple_blend_equation(ctx, modeA)) {
678 _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquationSeparateEXT(modeA)");
683 _mesa_flush_vertices_for_blend_state(ctx);
686 ctx->Color.Blend[buf].EquationRGB = modeRGB;
687 ctx->Color.Blend[buf].EquationA = modeA;
689 ctx->Color._BlendEquationPerBuffer = GL_FALSE;
690 set_advanced_blend_mode(ctx, BLEND_NONE);
697 GET_CURRENT_CONTEXT(ctx);
698 blend_equation_separate(ctx, modeRGB, modeA, true);
705 GET_CURRENT_CONTEXT(ctx);
708 _mesa_debug(ctx, "glBlendEquationSeparateEXT(%s %s)\n",
712 blend_equation_separate(ctx, modeRGB, modeA, false);
717 blend_equation_separatei(struct gl_context *ctx, GLuint buf, GLenum modeRGB,
720 if (ctx->Color.Blend[buf].EquationRGB == modeRGB &&
721 ctx->Color.Blend[buf].EquationA == modeA)
731 if (!legal_simple_blend_equation(ctx, modeRGB)) {
732 _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquationSeparatei(modeRGB)");
736 if (!legal_simple_blend_equation(ctx, modeA)) {
737 _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquationSeparatei(modeA)");
742 _mesa_flush_vertices_for_blend_state(ctx);
743 ctx->Color.Blend[buf].EquationRGB = modeRGB;
744 ctx->Color.Blend[buf].EquationA = modeA;
745 ctx->Color._BlendEquationPerBuffer = GL_TRUE;
746 set_advanced_blend_mode(ctx, BLEND_NONE);
754 GET_CURRENT_CONTEXT(ctx);
755 blend_equation_separatei(ctx, buf, modeRGB, modeA, true);
765 GET_CURRENT_CONTEXT(ctx);
768 _mesa_debug(ctx, "glBlendEquationSeparatei(%u, %s %s)\n", buf,
772 if (buf >= ctx->Const.MaxDrawBuffers) {
773 _mesa_error(ctx, GL_INVALID_VALUE, "glBlendEquationSeparatei(buffer=%u)",
778 blend_equation_separatei(ctx, buf, modeRGB, modeA, false);
800 GET_CURRENT_CONTEXT(ctx);
807 if (TEST_EQ_4V(tmp, ctx->Color.BlendColorUnclamped))
810 FLUSH_VERTICES(ctx, 0, GL_COLOR_BUFFER_BIT);
811 ctx->NewDriverState |= ST_NEW_BLEND_COLOR;
812 COPY_4FV( ctx->Color.BlendColorUnclamped, tmp );
814 ctx->Color.BlendColor[0] = CLAMP(tmp[0], 0.0F, 1.0F);
815 ctx->Color.BlendColor[1] = CLAMP(tmp[1], 0.0F, 1.0F);
816 ctx->Color.BlendColor[2] = CLAMP(tmp[2], 0.0F, 1.0F);
817 ctx->Color.BlendColor[3] = CLAMP(tmp[3], 0.0F, 1.0F);
834 GET_CURRENT_CONTEXT(ctx);
837 _mesa_debug(ctx, "glAlphaFunc(%s, %f)\n",
840 if (ctx->Color.AlphaFunc == func && ctx->Color.AlphaRefUnclamped == ref)
852 FLUSH_VERTICES(ctx, 0, GL_COLOR_BUFFER_BIT);
853 ctx->NewDriverState |= ctx->DriverFlags.NewAlphaTest;
854 ctx->Color.AlphaFunc = func;
855 ctx->Color.AlphaRefUnclamped = ref;
856 ctx->Color.AlphaRef = CLAMP(ref, 0.0F, 1.0F);
860 _mesa_error( ctx, GL_INVALID_ENUM, "glAlphaFunc(func)" );
885 logic_op(struct gl_context *ctx, GLenum opcode, bool no_error)
887 if (ctx->Color.LogicOp == opcode)
910 _mesa_error( ctx, GL_INVALID_ENUM, "glLogicOp" );
915 FLUSH_VERTICES(ctx, 0, GL_COLOR_BUFFER_BIT);
916 ctx->NewDriverState |= ST_NEW_BLEND;
917 ctx->Color.LogicOp = opcode;
918 ctx->Color._LogicOp = color_logicop_mapping[opcode & 0x0f];
919 _mesa_update_allow_draw_out_of_order(ctx);
936 GET_CURRENT_CONTEXT(ctx);
939 _mesa_debug(ctx, "glLogicOp(%s)\n", _mesa_enum_to_string(opcode));
941 logic_op(ctx, opcode, false);
948 GET_CURRENT_CONTEXT(ctx);
949 logic_op(ctx, opcode, true);
956 GET_CURRENT_CONTEXT(ctx);
958 if (ctx->Color.IndexMask == mask)
961 FLUSH_VERTICES(ctx, 0, GL_COLOR_BUFFER_BIT);
962 ctx->NewDriverState |= ST_NEW_BLEND;
963 ctx->Color.IndexMask = mask;
985 GET_CURRENT_CONTEXT(ctx);
988 _mesa_debug(ctx, "glColorMask(%d, %d, %d, %d)\n",
995 mask = _mesa_replicate_colormask(mask, ctx->Const.MaxDrawBuffers);
997 if (ctx->Color.ColorMask == mask)
1000 FLUSH_VERTICES(ctx, 0, GL_COLOR_BUFFER_BIT);
1001 ctx->NewDriverState |= ST_NEW_BLEND;
1002 ctx->Color.ColorMask = mask;
1003 _mesa_update_allow_draw_out_of_order(ctx);
1014 GET_CURRENT_CONTEXT(ctx);
1017 _mesa_debug(ctx, "glColorMaski %u %d %d %d %d\n",
1020 if (buf >= ctx->Const.MaxDrawBuffers) {
1021 _mesa_error(ctx, GL_INVALID_VALUE, "glColorMaski(buf=%u)", buf);
1030 if (GET_COLORMASK(ctx->Color.ColorMask, buf) == mask)
1033 FLUSH_VERTICES(ctx, 0, GL_COLOR_BUFFER_BIT);
1034 ctx->NewDriverState |= ST_NEW_BLEND;
1035 ctx->Color.ColorMask &= ~(0xf << (4 * buf));
1036 ctx->Color.ColorMask |= mask << (4 * buf);
1037 _mesa_update_allow_draw_out_of_order(ctx);
1044 GET_CURRENT_CONTEXT(ctx);
1049 if (ctx->Version <= 30 && !ctx->Extensions.ARB_color_buffer_float) {
1050 _mesa_error(ctx, GL_INVALID_OPERATION, "glClampColor()");
1055 _mesa_error(ctx, GL_INVALID_ENUM, "glClampColorARB(clamp)");
1061 if (ctx->API == API_OPENGL_CORE)
1063 FLUSH_VERTICES(ctx, _NEW_LIGHT_STATE, GL_LIGHTING_BIT | GL_ENABLE_BIT);
1064 ctx->Light.ClampVertexColor = clamp;
1065 _mesa_update_clamp_vertex_color(ctx, ctx->DrawBuffer);
1068 if (ctx->API == API_OPENGL_CORE)
1070 if (ctx->Color.ClampFragmentColor != clamp) {
1071 FLUSH_VERTICES(ctx, 0, GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT);
1072 ctx->Color.ClampFragmentColor = clamp;
1073 _mesa_update_clamp_fragment_color(ctx, ctx->DrawBuffer);
1077 ctx->Color.ClampReadColor = clamp;
1078 ctx->PopAttribState |= GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT;
1086 _mesa_error(ctx, GL_INVALID_ENUM, "glClampColor(%s)",
1104 _mesa_get_clamp_fragment_color(const struct gl_context *ctx,
1107 return get_clamp_color(drawFb, ctx->Color.ClampFragmentColor);
1111 _mesa_get_clamp_vertex_color(const struct gl_context *ctx,
1114 return get_clamp_color(drawFb, ctx->Light.ClampVertexColor);
1118 _mesa_get_clamp_read_color(const struct gl_context *ctx,
1121 return get_clamp_color(readFb, ctx->Color.ClampReadColor);
1125 * Update the ctx->Color._ClampFragmentColor field
1128 _mesa_update_clamp_fragment_color(struct gl_context *ctx,
1142 clamp = _mesa_get_clamp_fragment_color(ctx, drawFb);
1144 if (ctx->Color._ClampFragmentColor == clamp)
1147 ctx->NewState |= _NEW_FRAG_CLAMP; /* for state constants */
1148 ctx->NewDriverState |= ctx->DriverFlags.NewFragClamp;
1149 ctx->Color._ClampFragmentColor = clamp;
1153 * Update the ctx->Color._ClampVertexColor field
1156 _mesa_update_clamp_vertex_color(struct gl_context *ctx,
1159 ctx->Light._ClampVertexColor =
1160 _mesa_get_clamp_vertex_color(ctx, drawFb);
1170 * \param ctx GL context.
1175 void _mesa_init_color( struct gl_context * ctx )
1180 ctx->Color.IndexMask = ~0u;
1181 ctx->Color.ColorMask = 0xffffffff;
1182 ctx->Color.ClearIndex = 0;
1183 ASSIGN_4V( ctx->Color.ClearColor.f, 0, 0, 0, 0 );
1184 ctx->Color.AlphaEnabled = GL_FALSE;
1185 ctx->Color.AlphaFunc = GL_ALWAYS;
1186 ctx->Color.AlphaRef = 0;
1187 ctx->Color.BlendEnabled = 0x0;
1188 for (i = 0; i < ARRAY_SIZE(ctx->Color.Blend); i++) {
1189 ctx->Color.Blend[i].SrcRGB = GL_ONE;
1190 ctx->Color.Blend[i].DstRGB = GL_ZERO;
1191 ctx->Color.Blend[i].SrcA = GL_ONE;
1192 ctx->Color.Blend[i].DstA = GL_ZERO;
1193 ctx->Color.Blend[i].EquationRGB = GL_FUNC_ADD;
1194 ctx->Color.Blend[i].EquationA = GL_FUNC_ADD;
1196 ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
1197 ASSIGN_4V( ctx->Color.BlendColorUnclamped, 0.0, 0.0, 0.0, 0.0 );
1198 ctx->Color.IndexLogicOpEnabled = GL_FALSE;
1199 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
1200 ctx->Color.LogicOp = GL_COPY;
1201 ctx->Color._LogicOp = COLOR_LOGICOP_COPY;
1202 ctx->Color.DitherFlag = GL_TRUE;
1206 if (ctx->Visual.doubleBufferMode || _mesa_is_gles(ctx)) {
1207 ctx->Color.DrawBuffer[0] = GL_BACK;
1210 ctx->Color.DrawBuffer[0] = GL_FRONT;
1213 ctx->Color.ClampFragmentColor = ctx->API == API_OPENGL_COMPAT ?
1215 ctx->Color._ClampFragmentColor = GL_FALSE;
1216 ctx->Color.ClampReadColor = GL_FIXED_ONLY_ARB;
1221 ctx->Color.sRGBEnabled = _mesa_is_gles(ctx);
1223 ctx->Color.BlendCoherent = true;