Only a few blend modes have been optimized (min, max, transparency, add) more optimized cases can easily be added if needed. Celestia uses glBlendFunc(GL_SRC_ALPHA, GL_ONE), for example.
#include "main/glheader.h"
#include "main/context.h"
#include "main/colormac.h"
#include "main/macros.h"
#include "s_blend.h"
#include "s_context.h"
#include "s_span.h"
Defines | |
| #define | _BLENDAPI |
| #define | DIV255(X) (divtemp = (X), ((divtemp << 8) + divtemp + 256) >> 16) |
| Integer divide by 255 Declare "int divtemp" before using. | |
Functions | |
| static void _BLENDAPI | blend_noop (GLcontext *ctx, GLuint n, const GLubyte mask[], GLvoid *src, const GLvoid *dst, GLenum chanType) |
| Special case for glBlendFunc(GL_ZERO, GL_ONE). | |
| static void _BLENDAPI | blend_replace (GLcontext *ctx, GLuint n, const GLubyte mask[], GLvoid *src, const GLvoid *dst, GLenum chanType) |
| Special case for glBlendFunc(GL_ONE, GL_ZERO) Any chanType ok. | |
| static void _BLENDAPI | blend_transparency_ubyte (GLcontext *ctx, GLuint n, const GLubyte mask[], GLvoid *src, const GLvoid *dst, GLenum chanType) |
| Common transparency blending mode: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). | |
| static void _BLENDAPI | blend_transparency_ushort (GLcontext *ctx, GLuint n, const GLubyte mask[], GLvoid *src, const GLvoid *dst, GLenum chanType) |
| static void _BLENDAPI | blend_transparency_float (GLcontext *ctx, GLuint n, const GLubyte mask[], GLvoid *src, const GLvoid *dst, GLenum chanType) |
| static void _BLENDAPI | blend_add (GLcontext *ctx, GLuint n, const GLubyte mask[], GLvoid *src, const GLvoid *dst, GLenum chanType) |
| Add src and dest: glBlendFunc(GL_ONE, GL_ONE). | |
| static void _BLENDAPI | blend_min (GLcontext *ctx, GLuint n, const GLubyte mask[], GLvoid *src, const GLvoid *dst, GLenum chanType) |
| Blend min function. | |
| static void _BLENDAPI | blend_max (GLcontext *ctx, GLuint n, const GLubyte mask[], GLvoid *src, const GLvoid *dst, GLenum chanType) |
| Blend max function. | |
| static void _BLENDAPI | blend_modulate (GLcontext *ctx, GLuint n, const GLubyte mask[], GLvoid *src, const GLvoid *dst, GLenum chanType) |
| Modulate: result = src * dest Any chanType ok. | |
| static void | blend_general_float (GLcontext *ctx, GLuint n, const GLubyte mask[], GLfloat rgba[][4], GLfloat dest[][4], GLenum chanType) |
| Do any blending operation, using floating point. | |
| static void | blend_general (GLcontext *ctx, GLuint n, const GLubyte mask[], void *src, const void *dst, GLenum chanType) |
| Do any blending operation, any chanType. | |
| void | _swrast_choose_blend_func (GLcontext *ctx, GLenum chanType) |
| Analyze current blending parameters to pick fastest blending function. | |
| void | _swrast_blend_span (GLcontext *ctx, struct gl_renderbuffer *rb, SWspan *span) |
| Apply the blending operator to a span of pixels. | |
| #define _BLENDAPI |
| #define DIV255 | ( | X | ) | (divtemp = (X), ((divtemp << 8) + divtemp + 256) >> 16) |
Integer divide by 255 Declare "int divtemp" before using.
This satisfies Glean and should be reasonably fast. Contributed by Nathan Hand.
| void _swrast_blend_span | ( | GLcontext * | ctx, | |
| struct gl_renderbuffer * | rb, | |||
| SWspan * | span | |||
| ) |
Apply the blending operator to a span of pixels.
We can handle horizontal runs of pixels (spans) or arrays of x/y pixel coordinates.
| void _swrast_choose_blend_func | ( | GLcontext * | ctx, | |
| GLenum | chanType | |||
| ) |
Analyze current blending parameters to pick fastest blending function.
Result: the ctx->Color.BlendFunc pointer is updated.
| static void _BLENDAPI blend_add | ( | GLcontext * | ctx, | |
| GLuint | n, | |||
| const GLubyte | mask[], | |||
| GLvoid * | src, | |||
| const GLvoid * | dst, | |||
| GLenum | chanType | |||
| ) | [static] |
Add src and dest: glBlendFunc(GL_ONE, GL_ONE).
Any chanType ok.
| static void blend_general | ( | GLcontext * | ctx, | |
| GLuint | n, | |||
| const GLubyte | mask[], | |||
| void * | src, | |||
| const void * | dst, | |||
| GLenum | chanType | |||
| ) | [static] |
Do any blending operation, any chanType.
| static void blend_general_float | ( | GLcontext * | ctx, | |
| GLuint | n, | |||
| const GLubyte | mask[], | |||
| GLfloat | rgba[][4], | |||
| GLfloat | dest[][4], | |||
| GLenum | chanType | |||
| ) | [static] |
Do any blending operation, using floating point.
| n | number of pixels | |
| mask | fragment writemask array | |
| rgba | array of incoming (and modified) pixels | |
| dest | array of pixels from the dest color buffer |
| static void _BLENDAPI blend_max | ( | GLcontext * | ctx, | |
| GLuint | n, | |||
| const GLubyte | mask[], | |||
| GLvoid * | src, | |||
| const GLvoid * | dst, | |||
| GLenum | chanType | |||
| ) | [static] |
Blend max function.
Any chanType ok.
| static void _BLENDAPI blend_min | ( | GLcontext * | ctx, | |
| GLuint | n, | |||
| const GLubyte | mask[], | |||
| GLvoid * | src, | |||
| const GLvoid * | dst, | |||
| GLenum | chanType | |||
| ) | [static] |
Blend min function.
Any chanType ok.
| static void _BLENDAPI blend_modulate | ( | GLcontext * | ctx, | |
| GLuint | n, | |||
| const GLubyte | mask[], | |||
| GLvoid * | src, | |||
| const GLvoid * | dst, | |||
| GLenum | chanType | |||
| ) | [static] |
Modulate: result = src * dest Any chanType ok.
| static void _BLENDAPI blend_noop | ( | GLcontext * | ctx, | |
| GLuint | n, | |||
| const GLubyte | mask[], | |||
| GLvoid * | src, | |||
| const GLvoid * | dst, | |||
| GLenum | chanType | |||
| ) | [static] |
Special case for glBlendFunc(GL_ZERO, GL_ONE).
No-op means the framebuffer values remain unchanged. Any chanType ok.
| static void _BLENDAPI blend_replace | ( | GLcontext * | ctx, | |
| GLuint | n, | |||
| const GLubyte | mask[], | |||
| GLvoid * | src, | |||
| const GLvoid * | dst, | |||
| GLenum | chanType | |||
| ) | [static] |
Special case for glBlendFunc(GL_ONE, GL_ZERO) Any chanType ok.
| static void _BLENDAPI blend_transparency_float | ( | GLcontext * | ctx, | |
| GLuint | n, | |||
| const GLubyte | mask[], | |||
| GLvoid * | src, | |||
| const GLvoid * | dst, | |||
| GLenum | chanType | |||
| ) | [static] |
| static void _BLENDAPI blend_transparency_ubyte | ( | GLcontext * | ctx, | |
| GLuint | n, | |||
| const GLubyte | mask[], | |||
| GLvoid * | src, | |||
| const GLvoid * | dst, | |||
| GLenum | chanType | |||
| ) | [static] |
Common transparency blending mode: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA).
| static void _BLENDAPI blend_transparency_ushort | ( | GLcontext * | ctx, | |
| GLuint | n, | |||
| const GLubyte | mask[], | |||
| GLvoid * | src, | |||
| const GLvoid * | dst, | |||
| GLenum | chanType | |||
| ) | [static] |
1.5.4