blob: 2012d00fd5f14a9d6ce2b7f79b5f0fb7c84bb4d7 [file] [log] [blame]
jtgafb833d1999-08-19 00:55:39 +00001/*
2 * Mesa 3-D graphics library
Brian Paul78b3b662005-09-27 15:52:27 +00003 * Version: 6.5
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00004 *
Brian Paule4b23562005-05-04 20:11:35 +00005 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00006 *
jtgafb833d1999-08-19 00:55:39 +00007 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000013 *
jtgafb833d1999-08-19 00:55:39 +000014 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000016 *
jtgafb833d1999-08-19 00:55:39 +000017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
Brian Paulfbd8f211999-11-11 01:22:25 +000025#include "glheader.h"
jtgafb833d1999-08-19 00:55:39 +000026#include "accum.h"
27#include "context.h"
Brian Paul3c634522002-10-24 23:57:19 +000028#include "imports.h"
Brian Paulebb248a2000-10-29 18:23:16 +000029#include "macros.h"
Brian Paulea39f042000-02-02 19:17:57 +000030#include "state.h"
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000031#include "mtypes.h"
Chia-I Wu2cf44392010-02-24 12:01:14 +080032#include "main/dispatch.h"
Chia-I Wua833ff02009-09-07 17:51:42 +080033
34
35#if FEATURE_accum
jtgafb833d1999-08-19 00:55:39 +000036
37
Kendall Bennettc40d1dd2003-10-21 22:22:17 +000038void GLAPIENTRY
Brian Paulfbd8f211999-11-11 01:22:25 +000039_mesa_ClearAccum( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha )
jtgafb833d1999-08-19 00:55:39 +000040{
Keith Whitwellcab974c2000-12-26 05:09:27 +000041 GLfloat tmp[4];
Brian Paulfbd8f211999-11-11 01:22:25 +000042 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +000043 ASSERT_OUTSIDE_BEGIN_END(ctx);
jtgafb833d1999-08-19 00:55:39 +000044
Brian Paul7c276322001-09-14 21:36:43 +000045 tmp[0] = CLAMP( red, -1.0F, 1.0F );
46 tmp[1] = CLAMP( green, -1.0F, 1.0F );
47 tmp[2] = CLAMP( blue, -1.0F, 1.0F );
48 tmp[3] = CLAMP( alpha, -1.0F, 1.0F );
Keith Whitwellcab974c2000-12-26 05:09:27 +000049
50 if (TEST_EQ_4V(tmp, ctx->Accum.ClearColor))
51 return;
52
53 FLUSH_VERTICES(ctx, _NEW_ACCUM);
54 COPY_4FV( ctx->Accum.ClearColor, tmp );
jtgafb833d1999-08-19 00:55:39 +000055}
56
Brian Paul3a0e0b22003-11-13 22:16:45 +000057
Chia-I Wua833ff02009-09-07 17:51:42 +080058static void GLAPIENTRY
Brian Paulfbd8f211999-11-11 01:22:25 +000059_mesa_Accum( GLenum op, GLfloat value )
jtgafb833d1999-08-19 00:55:39 +000060{
Brian Paulfbd8f211999-11-11 01:22:25 +000061 GET_CURRENT_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +000062 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
jtgafb833d1999-08-19 00:55:39 +000063
Brian Paule4b23562005-05-04 20:11:35 +000064 switch (op) {
65 case GL_ADD:
66 case GL_MULT:
67 case GL_ACCUM:
68 case GL_LOAD:
69 case GL_RETURN:
70 /* OK */
71 break;
72 default:
73 _mesa_error(ctx, GL_INVALID_ENUM, "glAccum(op)");
74 return;
75 }
76
Brian Paulb4269c02005-10-08 21:36:38 +000077 if (ctx->DrawBuffer->Visual.haveAccumBuffer == 0) {
Brian Pauldbd0fa92005-09-27 16:10:49 +000078 _mesa_error(ctx, GL_INVALID_OPERATION, "glAccum(no accum buffer)");
79 return;
80 }
81
Brian Paul78b3b662005-09-27 15:52:27 +000082 if (ctx->DrawBuffer != ctx->ReadBuffer) {
Brian Paul9b8059e2006-03-01 02:09:40 +000083 /* See GLX_SGI_make_current_read or WGL_ARB_make_current_read,
84 * or GL_EXT_framebuffer_blit.
85 */
Brian Paul78b3b662005-09-27 15:52:27 +000086 _mesa_error(ctx, GL_INVALID_OPERATION,
87 "glAccum(different read/draw buffers)");
88 return;
89 }
90
jtgafb833d1999-08-19 00:55:39 +000091 if (ctx->NewState)
Brian Pauld95000d2005-09-28 15:46:46 +000092 _mesa_update_state(ctx);
jtgafb833d1999-08-19 00:55:39 +000093
Brian Pauld95000d2005-09-28 15:46:46 +000094 if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
95 _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
96 "glAccum(incomplete framebuffer)");
Brian Paul3a0e0b22003-11-13 22:16:45 +000097 return;
98 }
99
Brian Pauld95000d2005-09-28 15:46:46 +0000100 if (ctx->RenderMode == GL_RENDER) {
Brian Paulccb64bb2006-10-18 18:35:09 +0000101 ctx->Driver.Accum(ctx, op, value);
jtgafb833d1999-08-19 00:55:39 +0000102 }
jtgafb833d1999-08-19 00:55:39 +0000103}
Keith Whitwell6dc85572003-07-17 13:43:59 +0000104
Brian Paule4b23562005-05-04 20:11:35 +0000105
Chia-I Wua833ff02009-09-07 17:51:42 +0800106void
107_mesa_init_accum_dispatch(struct _glapi_table *disp)
108{
109 SET_Accum(disp, _mesa_Accum);
110 SET_ClearAccum(disp, _mesa_ClearAccum);
111}
112
113
114#endif /* FEATURE_accum */
115
Brian Paule4b23562005-05-04 20:11:35 +0000116
Keith Whitwell6dc85572003-07-17 13:43:59 +0000117void
118_mesa_init_accum( GLcontext *ctx )
119{
120 /* Accumulate buffer group */
121 ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
122}