1 /*
2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * SPDX-License-Identifier: SGI-B-2.0
6 */
7
8 #include <assert.h>
9 #include "glxclient.h"
10 #include "indirect.h"
11 #include "indirect_vertex_array.h"
12
13 /*****************************************************************************/
14
15 #if !defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE)
16 static void
do_enable_disable(GLenum array,GLboolean val)17 do_enable_disable(GLenum array, GLboolean val)
18 {
19 struct glx_context *gc = __glXGetCurrentContext();
20 __GLXattribute *state = (__GLXattribute *) (gc->client_state_private);
21 unsigned index = 0;
22
23 if (array == GL_TEXTURE_COORD_ARRAY) {
24 index = __glXGetActiveTextureUnit(state);
25 }
26
27 if (!__glXSetArrayEnable(state, array, index, val)) {
28 __glXSetError(gc, GL_INVALID_ENUM);
29 }
30 }
31
32 void
__indirect_glEnableClientState(GLenum array)33 __indirect_glEnableClientState(GLenum array)
34 {
35 do_enable_disable(array, GL_TRUE);
36 }
37
38 void
__indirect_glDisableClientState(GLenum array)39 __indirect_glDisableClientState(GLenum array)
40 {
41 do_enable_disable(array, GL_FALSE);
42 }
43
44 /************************************************************************/
45
46 void
__indirect_glPushClientAttrib(GLuint mask)47 __indirect_glPushClientAttrib(GLuint mask)
48 {
49 struct glx_context *gc = __glXGetCurrentContext();
50 __GLXattribute *state = (__GLXattribute *) (gc->client_state_private);
51 __GLXattribute **spp = gc->attributes.stackPointer, *sp;
52
53 if (spp < &gc->attributes.stack[__GL_CLIENT_ATTRIB_STACK_DEPTH]) {
54 if (!(sp = *spp)) {
55 sp = malloc(sizeof(__GLXattribute));
56 if (sp == NULL) {
57 __glXSetError(gc, GL_OUT_OF_MEMORY);
58 return;
59 }
60 *spp = sp;
61 }
62 sp->mask = mask;
63 gc->attributes.stackPointer = spp + 1;
64 if (mask & GL_CLIENT_PIXEL_STORE_BIT) {
65 sp->storePack = state->storePack;
66 sp->storeUnpack = state->storeUnpack;
67 }
68 if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) {
69 __glXPushArrayState(state);
70 }
71 }
72 else {
73 __glXSetError(gc, GL_STACK_OVERFLOW);
74 return;
75 }
76 }
77
78 void
__indirect_glPopClientAttrib(void)79 __indirect_glPopClientAttrib(void)
80 {
81 struct glx_context *gc = __glXGetCurrentContext();
82 __GLXattribute *state = (__GLXattribute *) (gc->client_state_private);
83 __GLXattribute **spp = gc->attributes.stackPointer, *sp;
84 GLuint mask;
85
86 if (spp > &gc->attributes.stack[0]) {
87 --spp;
88 sp = *spp;
89 assert(sp != 0);
90 mask = sp->mask;
91 gc->attributes.stackPointer = spp;
92
93 if (mask & GL_CLIENT_PIXEL_STORE_BIT) {
94 state->storePack = sp->storePack;
95 state->storeUnpack = sp->storeUnpack;
96 }
97 if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) {
98 __glXPopArrayState(state);
99 }
100
101 sp->mask = 0;
102 }
103 else {
104 __glXSetError(gc, GL_STACK_UNDERFLOW);
105 return;
106 }
107 }
108 #endif
109