1 /**************************************************************************
2 *
3 * Copyright 2019 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 /*
30 * Miscellantous state tracker utility functions, macros.
31 */
32
33
34 #ifndef ST_UTIL
35 #define ST_UTIL
36
37
38 #include "state_tracker/st_context.h"
39
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45
46 /** For drawing quads for glClear, glDraw/CopyPixels, glBitmap, etc. */
47 struct st_util_vertex
48 {
49 float x, y, z;
50 float r, g, b, a;
51 float s, t;
52 };
53
54
55
56 /* Invalidate the readpixels cache to ensure we don't read stale data.
57 */
58 static inline void
st_invalidate_readpix_cache(struct st_context * st)59 st_invalidate_readpix_cache(struct st_context *st)
60 {
61 if (unlikely(st->readpix_cache.src)) {
62 pipe_resource_reference(&st->readpix_cache.src, NULL);
63 pipe_resource_reference(&st->readpix_cache.cache, NULL);
64 }
65 }
66
67 static inline bool
st_user_clip_planes_enabled(struct gl_context * ctx)68 st_user_clip_planes_enabled(struct gl_context *ctx)
69 {
70 return (ctx->API == API_OPENGL_COMPAT ||
71 ctx->API == API_OPENGLES) && /* only ES 1.x */
72 ctx->Transform.ClipPlanesEnabled;
73 }
74
75 static inline bool
st_point_size_per_vertex(struct gl_context * ctx)76 st_point_size_per_vertex(struct gl_context *ctx)
77 {
78 const struct gl_program *vertProg = ctx->VertexProgram._Current;
79 if (vertProg) {
80 if (vertProg->Id == 0) {
81 if (vertProg->info.outputs_written &
82 BITFIELD64_BIT(VARYING_SLOT_PSIZ)) {
83 /* generated program which emits point size */
84 return true;
85 }
86 }
87 else if (ctx->API != API_OPENGLES2) {
88 /* PointSizeEnabled is always set in ES2 contexts */
89 return ctx->VertexProgram.PointSizeEnabled;
90 }
91 else {
92 /* ST_NEW_TESSEVAL_PROGRAM | ST_NEW_GEOMETRY_PROGRAM */
93 /* We have to check the last bound stage and see if it writes psize */
94 struct gl_program *last = NULL;
95 if (ctx->GeometryProgram._Current)
96 last = ctx->GeometryProgram._Current;
97 else if (ctx->TessEvalProgram._Current)
98 last = ctx->TessEvalProgram._Current;
99 else if (ctx->VertexProgram._Current)
100 last = ctx->VertexProgram._Current;
101 if (last)
102 return !!(last->info.outputs_written &
103 BITFIELD64_BIT(VARYING_SLOT_PSIZ));
104 }
105 }
106 return false;
107 }
108
109 #ifdef __cplusplus
110 }
111 #endif
112
113
114 #endif /* ST_UTIL */
115