1848b8605Smrg/*
2848b8605Smrg * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3848b8605Smrg * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
4848b8605Smrg *
5848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
6848b8605Smrg * copy of this software and associated documentation files (the "Software"),
7848b8605Smrg * to deal in the Software without restriction, including without limitation
8848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the
10848b8605Smrg * Software is furnished to do so, subject to the following conditions:
11848b8605Smrg *
12848b8605Smrg * The above copyright notice including the dates of first publication and
13848b8605Smrg * either this permission notice or a reference to
14848b8605Smrg * http://oss.sgi.com/projects/FreeB/
15848b8605Smrg * shall be included in all copies or substantial portions of the Software.
16848b8605Smrg *
17848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20848b8605Smrg * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21848b8605Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22848b8605Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23848b8605Smrg * SOFTWARE.
24848b8605Smrg *
25848b8605Smrg * Except as contained in this notice, the name of Silicon Graphics, Inc.
26848b8605Smrg * shall not be used in advertising or otherwise to promote the sale, use or
27848b8605Smrg * other dealings in this Software without prior written authorization from
28848b8605Smrg * Silicon Graphics, Inc.
29848b8605Smrg */
30848b8605Smrg
31848b8605Smrg#include <assert.h>
32848b8605Smrg#include "glxclient.h"
33848b8605Smrg#include "indirect.h"
34848b8605Smrg#include "indirect_vertex_array.h"
35848b8605Smrg
36848b8605Smrg/*****************************************************************************/
37848b8605Smrg
38848b8605Smrg#ifndef GLX_USE_APPLEGL
39848b8605Smrgstatic void
40848b8605Smrgdo_enable_disable(GLenum array, GLboolean val)
41848b8605Smrg{
42848b8605Smrg   struct glx_context *gc = __glXGetCurrentContext();
43848b8605Smrg   __GLXattribute *state = (__GLXattribute *) (gc->client_state_private);
44848b8605Smrg   unsigned index = 0;
45848b8605Smrg
46848b8605Smrg   if (array == GL_TEXTURE_COORD_ARRAY) {
47848b8605Smrg      index = __glXGetActiveTextureUnit(state);
48848b8605Smrg   }
49848b8605Smrg
50848b8605Smrg   if (!__glXSetArrayEnable(state, array, index, val)) {
51848b8605Smrg      __glXSetError(gc, GL_INVALID_ENUM);
52848b8605Smrg   }
53848b8605Smrg}
54848b8605Smrg
55848b8605Smrgvoid
56848b8605Smrg__indirect_glEnableClientState(GLenum array)
57848b8605Smrg{
58848b8605Smrg   do_enable_disable(array, GL_TRUE);
59848b8605Smrg}
60848b8605Smrg
61848b8605Smrgvoid
62848b8605Smrg__indirect_glDisableClientState(GLenum array)
63848b8605Smrg{
64848b8605Smrg   do_enable_disable(array, GL_FALSE);
65848b8605Smrg}
66848b8605Smrg
67848b8605Smrg/************************************************************************/
68848b8605Smrg
69848b8605Smrgvoid
70848b8605Smrg__indirect_glPushClientAttrib(GLuint mask)
71848b8605Smrg{
72848b8605Smrg   struct glx_context *gc = __glXGetCurrentContext();
73848b8605Smrg   __GLXattribute *state = (__GLXattribute *) (gc->client_state_private);
74848b8605Smrg   __GLXattribute **spp = gc->attributes.stackPointer, *sp;
75848b8605Smrg
76848b8605Smrg   if (spp < &gc->attributes.stack[__GL_CLIENT_ATTRIB_STACK_DEPTH]) {
77848b8605Smrg      if (!(sp = *spp)) {
78848b8605Smrg         sp = malloc(sizeof(__GLXattribute));
79848b8605Smrg         if (sp == NULL) {
80848b8605Smrg            __glXSetError(gc, GL_OUT_OF_MEMORY);
81848b8605Smrg            return;
82848b8605Smrg         }
83848b8605Smrg         *spp = sp;
84848b8605Smrg      }
85848b8605Smrg      sp->mask = mask;
86848b8605Smrg      gc->attributes.stackPointer = spp + 1;
87848b8605Smrg      if (mask & GL_CLIENT_PIXEL_STORE_BIT) {
88848b8605Smrg         sp->storePack = state->storePack;
89848b8605Smrg         sp->storeUnpack = state->storeUnpack;
90848b8605Smrg      }
91848b8605Smrg      if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) {
92848b8605Smrg         __glXPushArrayState(state);
93848b8605Smrg      }
94848b8605Smrg   }
95848b8605Smrg   else {
96848b8605Smrg      __glXSetError(gc, GL_STACK_OVERFLOW);
97848b8605Smrg      return;
98848b8605Smrg   }
99848b8605Smrg}
100848b8605Smrg
101848b8605Smrgvoid
102848b8605Smrg__indirect_glPopClientAttrib(void)
103848b8605Smrg{
104848b8605Smrg   struct glx_context *gc = __glXGetCurrentContext();
105848b8605Smrg   __GLXattribute *state = (__GLXattribute *) (gc->client_state_private);
106848b8605Smrg   __GLXattribute **spp = gc->attributes.stackPointer, *sp;
107848b8605Smrg   GLuint mask;
108848b8605Smrg
109848b8605Smrg   if (spp > &gc->attributes.stack[0]) {
110848b8605Smrg      --spp;
111848b8605Smrg      sp = *spp;
112848b8605Smrg      assert(sp != 0);
113848b8605Smrg      mask = sp->mask;
114848b8605Smrg      gc->attributes.stackPointer = spp;
115848b8605Smrg
116848b8605Smrg      if (mask & GL_CLIENT_PIXEL_STORE_BIT) {
117848b8605Smrg         state->storePack = sp->storePack;
118848b8605Smrg         state->storeUnpack = sp->storeUnpack;
119848b8605Smrg      }
120848b8605Smrg      if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) {
121848b8605Smrg         __glXPopArrayState(state);
122848b8605Smrg      }
123848b8605Smrg
124848b8605Smrg      sp->mask = 0;
125848b8605Smrg   }
126848b8605Smrg   else {
127848b8605Smrg      __glXSetError(gc, GL_STACK_UNDERFLOW);
128848b8605Smrg      return;
129848b8605Smrg   }
130848b8605Smrg}
131848b8605Smrg#endif
132848b8605Smrg
133848b8605Smrgvoid
134848b8605Smrg__glFreeAttributeState(struct glx_context * gc)
135848b8605Smrg{
136848b8605Smrg   __GLXattribute *sp, **spp;
137848b8605Smrg
138848b8605Smrg   for (spp = &gc->attributes.stack[0];
139848b8605Smrg        spp < &gc->attributes.stack[__GL_CLIENT_ATTRIB_STACK_DEPTH]; spp++) {
140848b8605Smrg      sp = *spp;
141848b8605Smrg      if (sp) {
142848b8605Smrg         free((char *) sp);
143848b8605Smrg      }
144848b8605Smrg      else {
145848b8605Smrg         break;
146848b8605Smrg      }
147848b8605Smrg   }
148848b8605Smrg}
149