xref: /aosp_15_r20/external/mesa3d/src/mesa/main/glthread_get.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
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 
27 uint32_t
_mesa_unmarshal_GetIntegerv(struct gl_context * ctx,const struct marshal_cmd_GetIntegerv * restrict cmd)28 _mesa_unmarshal_GetIntegerv(struct gl_context *ctx,
29                             const struct marshal_cmd_GetIntegerv *restrict cmd)
30 {
31    unreachable("never executed");
32    return 0;
33 }
34 
35 void GLAPIENTRY
_mesa_marshal_GetIntegerv(GLenum pname,GLint * p)36 _mesa_marshal_GetIntegerv(GLenum pname, GLint *p)
37 {
38    GET_CURRENT_CONTEXT(ctx);
39 
40    /* This will generate GL_INVALID_OPERATION, as it should. */
41    if (ctx->GLThread.inside_begin_end)
42       goto sync;
43 
44    /* TODO: Use get_hash_params.py to return values for items containing:
45     * - CONST(
46     * - CONTEXT_[A-Z]*(Const
47     */
48 
49    switch (pname) {
50    case GL_ACTIVE_TEXTURE:
51       *p = GL_TEXTURE0 + ctx->GLThread.ActiveTexture;
52       return;
53    case GL_ARRAY_BUFFER_BINDING:
54       *p = ctx->GLThread.CurrentArrayBufferName;
55       return;
56    case GL_ATTRIB_STACK_DEPTH:
57       *p = ctx->GLThread.AttribStackDepth;
58       return;
59    case GL_CLIENT_ACTIVE_TEXTURE:
60       *p = GL_TEXTURE0 + ctx->GLThread.ClientActiveTexture;
61       return;
62    case GL_CLIENT_ATTRIB_STACK_DEPTH:
63       *p = ctx->GLThread.ClientAttribStackTop;
64       return;
65    case GL_CURRENT_PROGRAM:
66       *p = ctx->GLThread.CurrentProgram;
67       return;
68    case GL_DRAW_INDIRECT_BUFFER_BINDING:
69       *p = ctx->GLThread.CurrentDrawIndirectBufferName;
70       return;
71    case GL_DRAW_FRAMEBUFFER_BINDING:
72       *p = ctx->GLThread.CurrentDrawFramebuffer;
73       return;
74    case GL_READ_FRAMEBUFFER_BINDING:
75       *p = ctx->GLThread.CurrentReadFramebuffer;
76       return;
77    case GL_PIXEL_PACK_BUFFER_BINDING:
78       *p = ctx->GLThread.CurrentPixelPackBufferName;
79       return;
80    case GL_PIXEL_UNPACK_BUFFER_BINDING:
81       *p = ctx->GLThread.CurrentPixelUnpackBufferName;
82       return;
83    case GL_QUERY_BUFFER_BINDING:
84       *p = ctx->GLThread.CurrentQueryBufferName;
85       return;
86 
87    case GL_MATRIX_MODE:
88       *p = ctx->GLThread.MatrixMode;
89       return;
90    case GL_CURRENT_MATRIX_STACK_DEPTH_ARB:
91       *p = ctx->GLThread.MatrixStackDepth[ctx->GLThread.MatrixIndex] + 1;
92       return;
93    case GL_MODELVIEW_STACK_DEPTH:
94       *p = ctx->GLThread.MatrixStackDepth[M_MODELVIEW] + 1;
95       return;
96    case GL_PROJECTION_STACK_DEPTH:
97       *p = ctx->GLThread.MatrixStackDepth[M_PROJECTION] + 1;
98       return;
99    case GL_TEXTURE_STACK_DEPTH:
100       *p = ctx->GLThread.MatrixStackDepth[M_TEXTURE0 + ctx->GLThread.ActiveTexture] + 1;
101       return;
102 
103    case GL_VERTEX_ARRAY:
104       *p = (ctx->GLThread.CurrentVAO->UserEnabled & (1 << VERT_ATTRIB_POS)) != 0;
105       return;
106    case GL_NORMAL_ARRAY:
107       *p = (ctx->GLThread.CurrentVAO->UserEnabled & (1 << VERT_ATTRIB_NORMAL)) != 0;
108       return;
109    case GL_COLOR_ARRAY:
110       *p = (ctx->GLThread.CurrentVAO->UserEnabled & (1 << VERT_ATTRIB_COLOR0)) != 0;
111       return;
112    case GL_SECONDARY_COLOR_ARRAY:
113       *p = (ctx->GLThread.CurrentVAO->UserEnabled & (1 << VERT_ATTRIB_COLOR1)) != 0;
114       return;
115    case GL_FOG_COORD_ARRAY:
116       *p = (ctx->GLThread.CurrentVAO->UserEnabled & (1 << VERT_ATTRIB_FOG)) != 0;
117       return;
118    case GL_INDEX_ARRAY:
119       *p = (ctx->GLThread.CurrentVAO->UserEnabled & (1 << VERT_ATTRIB_COLOR_INDEX)) != 0;
120       return;
121    case GL_EDGE_FLAG_ARRAY:
122       *p = (ctx->GLThread.CurrentVAO->UserEnabled & (1 << VERT_ATTRIB_EDGEFLAG)) != 0;
123       return;
124    case GL_TEXTURE_COORD_ARRAY:
125       *p = (ctx->GLThread.CurrentVAO->UserEnabled &
126             (1 << (VERT_ATTRIB_TEX0 + ctx->GLThread.ClientActiveTexture))) != 0;
127       return;
128    case GL_POINT_SIZE_ARRAY_OES:
129       *p = (ctx->GLThread.CurrentVAO->UserEnabled & (1 << VERT_ATTRIB_POINT_SIZE)) != 0;
130       return;
131    }
132 
133 sync:
134    _mesa_glthread_finish_before(ctx, "GetIntegerv");
135    CALL_GetIntegerv(ctx->Dispatch.Current, (pname, p));
136 }
137 
138 /* TODO: Implement glGetBooleanv, glGetFloatv, etc. if needed */
139