1/*
2 * Copyright © 2020 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24#include "main/glthread_marshal.h"
25#include "main/dispatch.h"
26
27uint32_t
28_mesa_unmarshal_GetIntegerv(struct gl_context *ctx,
29                            const struct marshal_cmd_GetIntegerv *cmd,
30                            const uint64_t *last)
31{
32   unreachable("never executed");
33   return 0;
34}
35
36void GLAPIENTRY
37_mesa_marshal_GetIntegerv(GLenum pname, GLint *p)
38{
39   GET_CURRENT_CONTEXT(ctx);
40
41   /* TODO: Use get_hash_params.py to return values for items containing:
42    * - CONST(
43    * - CONTEXT_[A-Z]*(Const
44    */
45
46   switch (pname) {
47   case GL_ACTIVE_TEXTURE:
48      *p = GL_TEXTURE0 + ctx->GLThread.ActiveTexture;
49      return;
50   case GL_ARRAY_BUFFER_BINDING:
51      *p = ctx->GLThread.CurrentArrayBufferName;
52      return;
53   case GL_ATTRIB_STACK_DEPTH:
54      *p = ctx->GLThread.AttribStackDepth;
55      return;
56   case GL_CLIENT_ACTIVE_TEXTURE:
57      *p = ctx->GLThread.ClientActiveTexture;
58      return;
59   case GL_CLIENT_ATTRIB_STACK_DEPTH:
60      *p = ctx->GLThread.ClientAttribStackTop;
61      return;
62   case GL_CURRENT_PROGRAM:
63      *p = ctx->GLThread.CurrentProgram;
64      return;
65   case GL_DRAW_INDIRECT_BUFFER_BINDING:
66      *p = ctx->GLThread.CurrentDrawIndirectBufferName;
67      return;
68   case GL_DRAW_FRAMEBUFFER_BINDING: /* == GL_FRAMEBUFFER_BINDING */
69      *p = ctx->GLThread.CurrentDrawFramebuffer;
70      return;
71   case GL_PIXEL_PACK_BUFFER_BINDING:
72      *p = ctx->GLThread.CurrentPixelPackBufferName;
73      return;
74   case GL_PIXEL_UNPACK_BUFFER_BINDING:
75      *p = ctx->GLThread.CurrentPixelUnpackBufferName;
76      return;
77   case GL_QUERY_BUFFER_BINDING:
78      *p = ctx->GLThread.CurrentQueryBufferName;
79      return;
80
81   case GL_MATRIX_MODE:
82      *p = ctx->GLThread.MatrixMode;
83      return;
84   case GL_CURRENT_MATRIX_STACK_DEPTH_ARB:
85      *p = ctx->GLThread.MatrixStackDepth[ctx->GLThread.MatrixIndex] + 1;
86      return;
87   case GL_MODELVIEW_STACK_DEPTH:
88      *p = ctx->GLThread.MatrixStackDepth[M_MODELVIEW] + 1;
89      return;
90   case GL_PROJECTION_STACK_DEPTH:
91      *p = ctx->GLThread.MatrixStackDepth[M_PROJECTION] + 1;
92      return;
93   case GL_TEXTURE_STACK_DEPTH:
94      *p = ctx->GLThread.MatrixStackDepth[M_TEXTURE0 + ctx->GLThread.ActiveTexture] + 1;
95      return;
96
97   case GL_VERTEX_ARRAY:
98      *p = (ctx->GLThread.CurrentVAO->UserEnabled & (1 << VERT_ATTRIB_POS)) != 0;
99      return;
100   case GL_NORMAL_ARRAY:
101      *p = (ctx->GLThread.CurrentVAO->UserEnabled & (1 << VERT_ATTRIB_NORMAL)) != 0;
102      return;
103   case GL_COLOR_ARRAY:
104      *p = (ctx->GLThread.CurrentVAO->UserEnabled & (1 << VERT_ATTRIB_COLOR0)) != 0;
105      return;
106   case GL_SECONDARY_COLOR_ARRAY:
107      *p = (ctx->GLThread.CurrentVAO->UserEnabled & (1 << VERT_ATTRIB_COLOR1)) != 0;
108      return;
109   case GL_FOG_COORD_ARRAY:
110      *p = (ctx->GLThread.CurrentVAO->UserEnabled & (1 << VERT_ATTRIB_FOG)) != 0;
111      return;
112   case GL_INDEX_ARRAY:
113      *p = (ctx->GLThread.CurrentVAO->UserEnabled & (1 << VERT_ATTRIB_COLOR_INDEX)) != 0;
114      return;
115   case GL_EDGE_FLAG_ARRAY:
116      *p = (ctx->GLThread.CurrentVAO->UserEnabled & (1 << VERT_ATTRIB_EDGEFLAG)) != 0;
117      return;
118   case GL_TEXTURE_COORD_ARRAY:
119      *p = (ctx->GLThread.CurrentVAO->UserEnabled &
120            (1 << (VERT_ATTRIB_TEX0 + ctx->GLThread.ClientActiveTexture))) != 0;
121      return;
122   case GL_POINT_SIZE_ARRAY_OES:
123      *p = (ctx->GLThread.CurrentVAO->UserEnabled & (1 << VERT_ATTRIB_POINT_SIZE)) != 0;
124      return;
125   }
126
127   _mesa_glthread_finish_before(ctx, "GetIntegerv");
128   CALL_GetIntegerv(ctx->CurrentServerDispatch, (pname, p));
129}
130
131/* TODO: Implement glGetBooleanv, glGetFloatv, etc. if needed */
132