1 /**************************************************************************
3 * Copyright 2019 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
30 * Miscellantous state tracker utility functions, macros.
38 #include "state_tracker/st_context.h"
46 /** For drawing quads for glClear, glDraw/CopyPixels, glBitmap, etc. */
56 /* Invalidate the readpixels cache to ensure we don't read stale data.
59 st_invalidate_readpix_cache(struct st_context
*st
)
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
);
72 st_fb_orientation(const struct gl_framebuffer
*fb
)
74 if (fb
&& fb
->FlipY
) {
75 /* Drawing into a window (on-screen buffer).
77 * Negate Y scale to flip image vertically.
78 * The NDC Y coords prior to viewport transformation are in the range
79 * [y=-1=bottom, y=1=top]
80 * Hardware window coords are in the range [y=0=top, y=H-1=bottom] where
81 * H is the window height.
82 * Use the viewport transformation to invert Y.
87 /* Drawing into user-created FBO (very likely a texture).
89 * For textures, T=0=Bottom, so by extension Y=0=Bottom for rendering.
97 st_user_clip_planes_enabled(struct gl_context
*ctx
)
99 return (ctx
->API
== API_OPENGL_COMPAT
||
100 ctx
->API
== API_OPENGLES
) && /* only ES 1.x */
101 ctx
->Transform
.ClipPlanesEnabled
;
105 st_point_size_per_vertex(struct gl_context
*ctx
)
107 const struct gl_program
*vertProg
= ctx
->VertexProgram
._Current
;
109 if (vertProg
->Id
== 0) {
110 if (vertProg
->info
.outputs_written
&
111 BITFIELD64_BIT(VARYING_SLOT_PSIZ
)) {
112 /* generated program which emits point size */
116 else if (ctx
->API
!= API_OPENGLES2
) {
117 /* PointSizeEnabled is always set in ES2 contexts */
118 return ctx
->VertexProgram
.PointSizeEnabled
;
121 /* ST_NEW_TESSEVAL_PROGRAM | ST_NEW_GEOMETRY_PROGRAM */
122 /* We have to check the last bound stage and see if it writes psize */
123 struct gl_program
*last
= NULL
;
124 if (ctx
->GeometryProgram
._Current
)
125 last
= ctx
->GeometryProgram
._Current
;
126 else if (ctx
->TessEvalProgram
._Current
)
127 last
= ctx
->TessEvalProgram
._Current
;
128 else if (ctx
->VertexProgram
._Current
)
129 last
= ctx
->VertexProgram
._Current
;
131 return !!(last
->info
.outputs_written
&
132 BITFIELD64_BIT(VARYING_SLOT_PSIZ
));
138 /** clear-alloc a struct-sized object, with casting */
139 #define ST_CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T))