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
&& _mesa_is_winsys_fbo(fb
)) {
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 /** clear-alloc a struct-sized object, with casting */
106 #define ST_CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T))