Ignore:
Timestamp:
May 23, 2000, 10:41:28 PM (25 years ago)
Author:
jeroen
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/opengl/mesa/blend.c

    r2962 r3598  
    1 /* $Id: blend.c,v 1.2 2000-03-01 18:49:23 jeroen Exp $ */
     1/* $Id: blend.c,v 1.3 2000-05-23 20:40:24 jeroen Exp $ */
    22
    33/*
    44 * Mesa 3-D graphics library
    5  * Version:  3.1
     5 * Version:  3.3
    66 *
    77 * Copyright (C) 1999  Brian Paul   All Rights Reserved.
     
    3030#include "all.h"
    3131#else
    32 #ifndef XFree86Server
    33 #include <stdio.h>
    34 #include <assert.h>
    35 #include <stdlib.h>
    36 #else
    37 #include "GL/xf86glx.h"
    38 #endif
     32#include "glheader.h"
    3933#include "alphabuf.h"
    4034#include "blend.h"
     
    4842
    4943#ifdef __WIN32OS2__
    50 #include <os2win.h>
    5144#include <cpuhlp.h>
    5245#endif
    5346
    54 void gl_BlendFunc( GLcontext *ctx, GLenum sfactor, GLenum dfactor )
    55 {
     47void
     48_mesa_BlendFunc( GLenum sfactor, GLenum dfactor )
     49{
     50   GET_CURRENT_CONTEXT(ctx);
    5651   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glBlendFunc");
    5752
     
    111106
    112107
    113 /* GL_INGR_blend_func_separate */
     108/* GL_EXT_blend_func_separate */
    114109void
    115 gl_BlendFuncSeparate( GLcontext *ctx, GLenum sfactorRGB, GLenum dfactorRGB,
    116                       GLenum sfactorA, GLenum dfactorA )
    117 {
     110_mesa_BlendFuncSeparateEXT( GLenum sfactorRGB, GLenum dfactorRGB,
     111                            GLenum sfactorA, GLenum dfactorA )
     112{
     113   GET_CURRENT_CONTEXT(ctx);
    118114   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glBlendFuncSeparate");
    119115
     
    219215
    220216/* This is really an extension function! */
    221 void gl_BlendEquation( GLcontext *ctx, GLenum mode )
    222 {
     217void
     218_mesa_BlendEquation( GLenum mode )
     219{
     220   GET_CURRENT_CONTEXT(ctx);
    223221   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glBlendEquation");
    224222
     
    261259
    262260
    263 void gl_BlendColor( GLcontext *ctx, GLclampf red, GLclampf green,
    264                     GLclampf blue, GLclampf alpha )
    265 {
     261void
     262_mesa_BlendColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
     263{
     264   GET_CURRENT_CONTEXT(ctx);
    266265   ctx->Color.BlendColor[0] = CLAMP( red,   0.0F, 1.0F );
    267266   ctx->Color.BlendColor[1] = CLAMP( green, 0.0F, 1.0F );
     
    270269}
    271270
    272 
     271#ifdef USE_MMX_ASM
     272#define _BLENDAPI _ASMAPI
     273#else
     274#define _BLENDAPI
     275#endif
    273276
    274277/*
    275278 * Common transparency blending mode.
    276279 */
    277 static void __cdecl blend_transparency( GLcontext *ctx, GLuint n, const GLubyte mask[],
    278                                 GLubyte rgba[][4], CONST GLubyte dest[][4] )
     280static void _BLENDAPI
     281blend_transparency( GLcontext *ctx, GLuint n, const GLubyte mask[],
     282                    GLubyte rgba[][4], CONST GLubyte dest[][4] )
    279283{
    280284   GLuint i;
     
    286290   for (i=0;i<n;i++) {
    287291      if (mask[i]) {
    288          GLint t = rgba[i][ACOMP];  /* t in [0,255] */
     292         const GLint t = rgba[i][ACOMP];  /* t in [0,255] */
    289293         if (t == 0) {
     294            /* 0% alpha */
    290295            rgba[i][RCOMP] = dest[i][RCOMP];
    291296            rgba[i][GCOMP] = dest[i][GCOMP];
     
    293298            rgba[i][ACOMP] = dest[i][ACOMP];
    294299         }
    295          else if (t == 255) {
    296             /* no-op */
     300         else if (t == CHAN_MAX) {
     301            /* 100% alpha, no-op */
    297302         }
    298303         else {
    299             GLint s = 255 - t;
    300             GLint r = (rgba[i][RCOMP] * t + dest[i][RCOMP] * s) >> 8;
    301             GLint g = (rgba[i][GCOMP] * t + dest[i][GCOMP] * s) >> 8;
    302             GLint b = (rgba[i][BCOMP] * t + dest[i][BCOMP] * s) >> 8;
    303             GLint a = (rgba[i][ACOMP] * t + dest[i][ACOMP] * s) >> 8;
    304             ASSERT(r <= 255);
    305             ASSERT(g <= 255);
    306             ASSERT(b <= 255);
    307             ASSERT(a <= 255);
     304            const GLint s = CHAN_MAX - t;
     305            const GLint r = (rgba[i][RCOMP] * t + dest[i][RCOMP] * s) >> 8;
     306            const GLint g = (rgba[i][GCOMP] * t + dest[i][GCOMP] * s) >> 8;
     307            const GLint b = (rgba[i][BCOMP] * t + dest[i][BCOMP] * s) >> 8;
     308            const GLint a = (rgba[i][ACOMP] * t + dest[i][ACOMP] * s) >> 8;
     309            ASSERT(r <= CHAN_MAX);
     310            ASSERT(g <= CHAN_MAX);
     311            ASSERT(b <= CHAN_MAX);
     312            ASSERT(a <= CHAN_MAX);
    308313            rgba[i][RCOMP] = (GLubyte) r;
    309314            rgba[i][GCOMP] = (GLubyte) g;
     
    320325 * Add src and dest.
    321326 */
    322 static void __cdecl blend_add( GLcontext *ctx, GLuint n, const GLubyte mask[],
    323                        GLubyte rgba[][4], CONST GLubyte dest[][4] )
     327static void _BLENDAPI
     328blend_add( GLcontext *ctx, GLuint n, const GLubyte mask[],
     329           GLubyte rgba[][4], CONST GLubyte dest[][4] )
    324330{
    325331   GLuint i;
     
    335341         GLint b = rgba[i][BCOMP] + dest[i][BCOMP];
    336342         GLint a = rgba[i][ACOMP] + dest[i][ACOMP];
    337          rgba[i][RCOMP] = (GLubyte) MIN2( r, 255 );
    338          rgba[i][GCOMP] = (GLubyte) MIN2( g, 255 );
    339          rgba[i][BCOMP] = (GLubyte) MIN2( b, 255 );
    340          rgba[i][ACOMP] = (GLubyte) MIN2( a, 255 );
     343         rgba[i][RCOMP] = (GLubyte) MIN2( r, CHAN_MAX );
     344         rgba[i][GCOMP] = (GLubyte) MIN2( g, CHAN_MAX );
     345         rgba[i][BCOMP] = (GLubyte) MIN2( b, CHAN_MAX );
     346         rgba[i][ACOMP] = (GLubyte) MIN2( a, CHAN_MAX );
    341347      }
    342348   }
     
    348354 * Blend min function  (for GL_EXT_blend_minmax)
    349355 */
    350 static void __cdecl blend_min( GLcontext *ctx, GLuint n, const GLubyte mask[],
    351                        GLubyte rgba[][4], CONST GLubyte dest[][4] )
     356static void _BLENDAPI
     357blend_min( GLcontext *ctx, GLuint n, const GLubyte mask[],
     358           GLubyte rgba[][4], CONST GLubyte dest[][4] )
    352359{
    353360   GLuint i;
     
    370377 * Blend max function  (for GL_EXT_blend_minmax)
    371378 */
    372 static void __cdecl blend_max( GLcontext *ctx, GLuint n, const GLubyte mask[],
    373                        GLubyte rgba[][4], CONST GLubyte dest[][4] )
     379static void _BLENDAPI
     380blend_max( GLcontext *ctx, GLuint n, const GLubyte mask[],
     381           GLubyte rgba[][4], CONST GLubyte dest[][4] )
    374382{
    375383   GLuint i;
     
    392400 * Modulate:  result = src * dest
    393401 */
    394 static void __cdecl blend_modulate( GLcontext *ctx, GLuint n, const GLubyte mask[],
    395                             GLubyte rgba[][4], CONST GLubyte dest[][4] )
     402static void _BLENDAPI
     403blend_modulate( GLcontext *ctx, GLuint n, const GLubyte mask[],
     404                GLubyte rgba[][4], CONST GLubyte dest[][4] )
    396405{
    397406   GLuint i;
     
    421430 * Input:  dest - the pixels from the dest color buffer
    422431 */
    423 static void __cdecl blend_general( GLcontext *ctx, GLuint n, const GLubyte mask[],
    424                            GLubyte rgba[][4], CONST GLubyte dest[][4] )
    425 {
    426    GLfloat rscale = 1.0F / 255.0F;
    427    GLfloat gscale = 1.0F / 255.0F;
    428    GLfloat bscale = 1.0F / 255.0F;
    429    GLfloat ascale = 1.0F / 255.0F;
     432static void _BLENDAPI
     433blend_general( GLcontext *ctx, GLuint n, const GLubyte mask[],
     434               GLubyte rgba[][4], CONST GLubyte dest[][4] )
     435{
     436   GLfloat rscale = 1.0F / CHAN_MAXF;
     437   GLfloat gscale = 1.0F / CHAN_MAXF;
     438   GLfloat bscale = 1.0F / CHAN_MAXF;
     439   GLfloat ascale = 1.0F / CHAN_MAXF;
    430440   GLuint i;
    431441
     
    481491               break;
    482492            case GL_SRC_ALPHA_SATURATE:
    483 #ifdef __WIN32OS2__
    484                if(As < 255 - Ad) {
    485 #else
    486                if (As < 1.0F - (GLfloat) Ad * ascale) {
    487 #endif
     493               if (As < CHAN_MAX - Ad) {
    488494                  sR = sG = sB = (GLfloat) As * ascale;
    489495               }
     
    704710
    705711         /* final clamping */
    706          rgba[i][RCOMP] = (GLubyte) (GLint) CLAMP( r, 0.0F, 255.0F );
    707          rgba[i][GCOMP] = (GLubyte) (GLint) CLAMP( g, 0.0F, 255.0F );
    708          rgba[i][BCOMP] = (GLubyte) (GLint) CLAMP( b, 0.0F, 255.0F );
    709          rgba[i][ACOMP] = (GLubyte) (GLint) CLAMP( a, 0.0F, 255.0F );
     712         rgba[i][RCOMP] = (GLubyte) (GLint) CLAMP( r, 0.0F, CHAN_MAXF );
     713         rgba[i][GCOMP] = (GLubyte) (GLint) CLAMP( g, 0.0F, CHAN_MAXF );
     714         rgba[i][BCOMP] = (GLubyte) (GLint) CLAMP( b, 0.0F, CHAN_MAXF );
     715         rgba[i][ACOMP] = (GLubyte) (GLint) CLAMP( a, 0.0F, CHAN_MAXF );
    710716      }
    711717   }
     
    783789 * In/Out:  rgba - pixel values
    784790 */
    785 void gl_blend_span( GLcontext *ctx, GLuint n, GLint x, GLint y,
    786                     GLubyte rgba[][4], const GLubyte mask[] )
     791void
     792_mesa_blend_span( GLcontext *ctx, GLuint n, GLint x, GLint y,
     793                  GLubyte rgba[][4], const GLubyte mask[] )
    787794{
    788795   GLubyte dest[MAX_WIDTH][4];
     
    794801
    795802   /* Read span of current frame buffer pixels */
    796    gl_read_rgba_span( ctx, n, x, y, dest );
     803   gl_read_rgba_span( ctx, ctx->DrawBuffer, n, x, y, dest );
    797804
    798805   if (!ctx->Color.BlendFunc)
     
    813820 * In/Out:  rgba - pixel values
    814821 */
    815 void gl_blend_pixels( GLcontext *ctx,
    816                       GLuint n, const GLint x[], const GLint y[],
    817                       GLubyte rgba[][4], const GLubyte mask[] )
     822void
     823_mesa_blend_pixels( GLcontext *ctx,
     824                    GLuint n, const GLint x[], const GLint y[],
     825                    GLubyte rgba[][4], const GLubyte mask[] )
    818826{
    819827   GLubyte dest[PB_SIZE][4];
Note: See TracChangeset for help on using the changeset viewer.