1848b8605Smrg/** 2848b8605Smrg * \file blend.h 3848b8605Smrg * Blending functions operations. 4848b8605Smrg */ 5848b8605Smrg 6848b8605Smrg/* 7848b8605Smrg * Mesa 3-D graphics library 8848b8605Smrg * 9848b8605Smrg * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. 10848b8605Smrg * 11848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 12848b8605Smrg * copy of this software and associated documentation files (the "Software"), 13848b8605Smrg * to deal in the Software without restriction, including without limitation 14848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 15848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the 16848b8605Smrg * Software is furnished to do so, subject to the following conditions: 17848b8605Smrg * 18848b8605Smrg * The above copyright notice and this permission notice shall be included 19848b8605Smrg * in all copies or substantial portions of the Software. 20848b8605Smrg * 21848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 22848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 24848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25848b8605Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 26848b8605Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27848b8605Smrg * OTHER DEALINGS IN THE SOFTWARE. 28848b8605Smrg */ 29848b8605Smrg 30848b8605Smrg 31848b8605Smrg 32848b8605Smrg#ifndef BLEND_H 33848b8605Smrg#define BLEND_H 34848b8605Smrg 35848b8605Smrg 36848b8605Smrg#include "glheader.h" 37b8e80941Smrg#include "context.h" 38848b8605Smrg#include "formats.h" 39b8e80941Smrg#include "extensions.h" 40848b8605Smrg 41848b8605Smrgstruct gl_context; 42b8e80941Smrgstruct gl_framebuffer; 43848b8605Smrg 44848b8605Smrg 45848b8605Smrgextern void GLAPIENTRY 46848b8605Smrg_mesa_BlendFunc( GLenum sfactor, GLenum dfactor ); 47848b8605Smrg 48b8e80941Smrgextern void GLAPIENTRY 49b8e80941Smrg_mesa_BlendFunc_no_error(GLenum sfactor, GLenum dfactor); 50848b8605Smrg 51848b8605Smrgextern void GLAPIENTRY 52848b8605Smrg_mesa_BlendFuncSeparate( GLenum sfactorRGB, GLenum dfactorRGB, 53848b8605Smrg GLenum sfactorA, GLenum dfactorA ); 54848b8605Smrg 55b8e80941Smrgextern void GLAPIENTRY 56b8e80941Smrg_mesa_BlendFuncSeparate_no_error(GLenum sfactorRGB, GLenum dfactorRGB, 57b8e80941Smrg GLenum sfactorA, GLenum dfactorA); 58848b8605Smrg 59b8e80941Smrgextern void GLAPIENTRY 60b8e80941Smrg_mesa_BlendFunciARB_no_error(GLuint buf, GLenum sfactor, GLenum dfactor); 61848b8605Smrgextern void GLAPIENTRY 62848b8605Smrg_mesa_BlendFunciARB(GLuint buf, GLenum sfactor, GLenum dfactor); 63848b8605Smrg 64848b8605Smrg 65b8e80941Smrgextern void GLAPIENTRY 66b8e80941Smrg_mesa_BlendFuncSeparateiARB_no_error(GLuint buf, GLenum sfactorRGB, 67b8e80941Smrg GLenum dfactorRGB, GLenum sfactorA, 68b8e80941Smrg GLenum dfactorA); 69848b8605Smrgextern void GLAPIENTRY 70848b8605Smrg_mesa_BlendFuncSeparateiARB(GLuint buf, GLenum sfactorRGB, GLenum dfactorRGB, 71848b8605Smrg GLenum sfactorA, GLenum dfactorA); 72848b8605Smrg 73848b8605Smrg 74848b8605Smrgextern void GLAPIENTRY 75848b8605Smrg_mesa_BlendEquation( GLenum mode ); 76848b8605Smrg 77848b8605Smrg 78b8e80941Smrgvoid GLAPIENTRY 79b8e80941Smrg_mesa_BlendEquationiARB_no_error(GLuint buf, GLenum mode); 80b8e80941Smrg 81848b8605Smrgextern void GLAPIENTRY 82848b8605Smrg_mesa_BlendEquationiARB(GLuint buf, GLenum mode); 83848b8605Smrg 84848b8605Smrg 85b8e80941Smrgvoid GLAPIENTRY 86b8e80941Smrg_mesa_BlendEquationSeparate_no_error(GLenum modeRGB, GLenum modeA); 87b8e80941Smrg 88848b8605Smrgextern void GLAPIENTRY 89848b8605Smrg_mesa_BlendEquationSeparate( GLenum modeRGB, GLenum modeA ); 90848b8605Smrg 91848b8605Smrg 92b8e80941Smrgextern void GLAPIENTRY 93b8e80941Smrg_mesa_BlendEquationSeparateiARB_no_error(GLuint buf, GLenum modeRGB, 94b8e80941Smrg GLenum modeA); 95848b8605Smrgextern void GLAPIENTRY 96848b8605Smrg_mesa_BlendEquationSeparateiARB(GLuint buf, GLenum modeRGB, GLenum modeA); 97848b8605Smrg 98848b8605Smrg 99848b8605Smrgextern void GLAPIENTRY 100848b8605Smrg_mesa_BlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); 101848b8605Smrg 102848b8605Smrg 103848b8605Smrgextern void GLAPIENTRY 104848b8605Smrg_mesa_AlphaFunc( GLenum func, GLclampf ref ); 105848b8605Smrg 106848b8605Smrg 107848b8605Smrgextern void GLAPIENTRY 108848b8605Smrg_mesa_LogicOp( GLenum opcode ); 109848b8605Smrg 110848b8605Smrg 111b8e80941Smrgextern void GLAPIENTRY 112b8e80941Smrg_mesa_LogicOp_no_error(GLenum opcode); 113b8e80941Smrg 114b8e80941Smrg 115848b8605Smrgextern void GLAPIENTRY 116848b8605Smrg_mesa_IndexMask( GLuint mask ); 117848b8605Smrg 118848b8605Smrgextern void GLAPIENTRY 119848b8605Smrg_mesa_ColorMask( GLboolean red, GLboolean green, 120848b8605Smrg GLboolean blue, GLboolean alpha ); 121848b8605Smrg 122848b8605Smrgextern void GLAPIENTRY 123848b8605Smrg_mesa_ColorMaski( GLuint buf, GLboolean red, GLboolean green, 124848b8605Smrg GLboolean blue, GLboolean alpha ); 125848b8605Smrg 126848b8605Smrg 127848b8605Smrgextern void GLAPIENTRY 128848b8605Smrg_mesa_ClampColor(GLenum target, GLenum clamp); 129848b8605Smrg 130848b8605Smrgextern GLboolean 131b8e80941Smrg_mesa_get_clamp_fragment_color(const struct gl_context *ctx, 132b8e80941Smrg const struct gl_framebuffer *drawFb); 133848b8605Smrg 134848b8605Smrgextern GLboolean 135b8e80941Smrg_mesa_get_clamp_vertex_color(const struct gl_context *ctx, 136b8e80941Smrg const struct gl_framebuffer *drawFb); 137848b8605Smrg 138848b8605Smrgextern GLboolean 139b8e80941Smrg_mesa_get_clamp_read_color(const struct gl_context *ctx, 140b8e80941Smrg const struct gl_framebuffer *readFb); 141848b8605Smrg 142848b8605Smrgextern void 143b8e80941Smrg_mesa_update_clamp_fragment_color(struct gl_context *ctx, 144b8e80941Smrg const struct gl_framebuffer *drawFb); 145848b8605Smrg 146848b8605Smrgextern void 147b8e80941Smrg_mesa_update_clamp_vertex_color(struct gl_context *ctx, 148b8e80941Smrg const struct gl_framebuffer *drawFb); 149848b8605Smrg 150848b8605Smrgextern mesa_format 151848b8605Smrg_mesa_get_render_format(const struct gl_context *ctx, mesa_format format); 152848b8605Smrg 153848b8605Smrgextern void 154848b8605Smrg_mesa_init_color( struct gl_context * ctx ); 155848b8605Smrg 156b8e80941Smrg 157b8e80941Smrgstatic inline enum gl_advanced_blend_mode 158b8e80941Smrg_mesa_get_advanced_blend_sh_constant(GLbitfield blend_enabled, 159b8e80941Smrg enum gl_advanced_blend_mode mode) 160b8e80941Smrg{ 161b8e80941Smrg return blend_enabled ? mode : BLEND_NONE; 162b8e80941Smrg} 163b8e80941Smrg 164b8e80941Smrgstatic inline bool 165b8e80941Smrg_mesa_advanded_blend_sh_constant_changed(struct gl_context *ctx, 166b8e80941Smrg GLbitfield new_blend_enabled, 167b8e80941Smrg enum gl_advanced_blend_mode new_mode) 168b8e80941Smrg{ 169b8e80941Smrg return _mesa_get_advanced_blend_sh_constant(new_blend_enabled, new_mode) != 170b8e80941Smrg _mesa_get_advanced_blend_sh_constant(ctx->Color.BlendEnabled, 171b8e80941Smrg ctx->Color._AdvancedBlendMode); 172b8e80941Smrg} 173b8e80941Smrg 174b8e80941Smrgstatic inline void 175b8e80941Smrg_mesa_flush_vertices_for_blend_state(struct gl_context *ctx) 176b8e80941Smrg{ 177b8e80941Smrg if (!ctx->DriverFlags.NewBlend) { 178b8e80941Smrg FLUSH_VERTICES(ctx, _NEW_COLOR); 179b8e80941Smrg } else { 180b8e80941Smrg FLUSH_VERTICES(ctx, 0); 181b8e80941Smrg ctx->NewDriverState |= ctx->DriverFlags.NewBlend; 182b8e80941Smrg } 183b8e80941Smrg} 184b8e80941Smrg 185b8e80941Smrgstatic inline void 186b8e80941Smrg_mesa_flush_vertices_for_blend_adv(struct gl_context *ctx, 187b8e80941Smrg GLbitfield new_blend_enabled, 188b8e80941Smrg enum gl_advanced_blend_mode new_mode) 189b8e80941Smrg{ 190b8e80941Smrg /* The advanced blend mode needs _NEW_COLOR to update the state constant. */ 191b8e80941Smrg if (_mesa_has_KHR_blend_equation_advanced(ctx) && 192b8e80941Smrg _mesa_advanded_blend_sh_constant_changed(ctx, new_blend_enabled, 193b8e80941Smrg new_mode)) { 194b8e80941Smrg FLUSH_VERTICES(ctx, _NEW_COLOR); 195b8e80941Smrg ctx->NewDriverState |= ctx->DriverFlags.NewBlend; 196b8e80941Smrg return; 197b8e80941Smrg } 198b8e80941Smrg _mesa_flush_vertices_for_blend_state(ctx); 199b8e80941Smrg} 200b8e80941Smrg 201b8e80941Smrgstatic inline GLbitfield 202b8e80941Smrg_mesa_replicate_colormask(GLbitfield mask0, unsigned num_buffers) 203b8e80941Smrg{ 204b8e80941Smrg GLbitfield mask = mask0; 205b8e80941Smrg 206b8e80941Smrg for (unsigned i = 1; i < num_buffers; i++) 207b8e80941Smrg mask |= mask0 << (i * 4); 208b8e80941Smrg return mask; 209b8e80941Smrg} 210b8e80941Smrg 211848b8605Smrg#endif 212