xref: /aosp_15_r20/external/mesa3d/src/mesa/main/blend.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /**
2  * \file blend.h
3  * Blending functions operations.
4  */
5 
6 /*
7  * Mesa 3-D graphics library
8  *
9  * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27  * OTHER DEALINGS IN THE SOFTWARE.
28  */
29 
30 
31 
32 #ifndef BLEND_H
33 #define BLEND_H
34 
35 
36 #include "util/glheader.h"
37 #include "context.h"
38 #include "formats.h"
39 #include "extensions.h"
40 
41 #include "state_tracker/st_context.h"
42 
43 struct gl_context;
44 struct gl_framebuffer;
45 
46 extern GLboolean
47 _mesa_get_clamp_fragment_color(const struct gl_context *ctx,
48                                const struct gl_framebuffer *drawFb);
49 
50 extern GLboolean
51 _mesa_get_clamp_vertex_color(const struct gl_context *ctx,
52                              const struct gl_framebuffer *drawFb);
53 
54 extern GLboolean
55 _mesa_get_clamp_read_color(const struct gl_context *ctx,
56                            const struct gl_framebuffer *readFb);
57 
58 extern void
59 _mesa_update_clamp_fragment_color(struct gl_context *ctx,
60                                   const struct gl_framebuffer *drawFb);
61 
62 extern void
63 _mesa_update_clamp_vertex_color(struct gl_context *ctx,
64                                 const struct gl_framebuffer *drawFb);
65 
66 extern void
67 _mesa_init_color( struct gl_context * ctx );
68 
69 
70 static inline enum gl_advanced_blend_mode
_mesa_get_advanced_blend_sh_constant(GLbitfield blend_enabled,enum gl_advanced_blend_mode mode)71 _mesa_get_advanced_blend_sh_constant(GLbitfield blend_enabled,
72                                      enum gl_advanced_blend_mode mode)
73 {
74    return blend_enabled ? mode : BLEND_NONE;
75 }
76 
77 static inline bool
_mesa_advanded_blend_sh_constant_changed(struct gl_context * ctx,GLbitfield new_blend_enabled,enum gl_advanced_blend_mode new_mode)78 _mesa_advanded_blend_sh_constant_changed(struct gl_context *ctx,
79                                          GLbitfield new_blend_enabled,
80                                          enum gl_advanced_blend_mode new_mode)
81 {
82    return _mesa_get_advanced_blend_sh_constant(new_blend_enabled, new_mode) !=
83           _mesa_get_advanced_blend_sh_constant(ctx->Color.BlendEnabled,
84                                                ctx->Color._AdvancedBlendMode);
85 }
86 
87 static inline void
_mesa_flush_vertices_for_blend_state(struct gl_context * ctx)88 _mesa_flush_vertices_for_blend_state(struct gl_context *ctx)
89 {
90    FLUSH_VERTICES(ctx, 0, GL_COLOR_BUFFER_BIT);
91    ctx->NewDriverState |= ST_NEW_BLEND;
92 }
93 
94 static inline void
_mesa_flush_vertices_for_blend_adv(struct gl_context * ctx,GLbitfield new_blend_enabled,enum gl_advanced_blend_mode new_mode)95 _mesa_flush_vertices_for_blend_adv(struct gl_context *ctx,
96                                    GLbitfield new_blend_enabled,
97                                    enum gl_advanced_blend_mode new_mode)
98 {
99    /* The advanced blend mode needs _NEW_COLOR to update the state constant. */
100    if (_mesa_has_KHR_blend_equation_advanced(ctx) &&
101        _mesa_advanded_blend_sh_constant_changed(ctx, new_blend_enabled,
102                                                 new_mode)) {
103       FLUSH_VERTICES(ctx, _NEW_COLOR, GL_COLOR_BUFFER_BIT);
104       ctx->NewDriverState |= ST_NEW_BLEND;
105       return;
106    }
107    _mesa_flush_vertices_for_blend_state(ctx);
108 }
109 
110 static inline GLbitfield
_mesa_replicate_colormask(GLbitfield mask0,unsigned num_buffers)111 _mesa_replicate_colormask(GLbitfield mask0, unsigned num_buffers)
112 {
113    GLbitfield mask = mask0;
114 
115    for (unsigned i = 1; i < num_buffers; i++)
116       mask |= mask0 << (i * 4);
117    return mask;
118 }
119 
120 #endif
121