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