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 42extern "C" { 43#endif 44 45 46/** For drawing quads for glClear, glDraw/CopyPixels, glBitmap, etc. */ 47struct 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 */ 58static inline void 59st_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 68#define Y_0_TOP 1 69#define Y_0_BOTTOM 2 70 71static inline GLuint 72st_fb_orientation(const struct gl_framebuffer *fb) 73{ 74 if (fb && _mesa_is_winsys_fbo(fb)) { 75 /* Drawing into a window (on-screen buffer). 76 * 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. 83 */ 84 return Y_0_TOP; 85 } 86 else { 87 /* Drawing into user-created FBO (very likely a texture). 88 * 89 * For textures, T=0=Bottom, so by extension Y=0=Bottom for rendering. 90 */ 91 return Y_0_BOTTOM; 92 } 93} 94 95 96static inline bool 97st_user_clip_planes_enabled(struct gl_context *ctx) 98{ 99 return (ctx->API == API_OPENGL_COMPAT || 100 ctx->API == API_OPENGLES) && /* only ES 1.x */ 101 ctx->Transform.ClipPlanesEnabled; 102} 103 104 105/** clear-alloc a struct-sized object, with casting */ 106#define ST_CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T)) 107 108 109#ifdef __cplusplus 110} 111#endif 112 113 114#endif /* ST_UTIL */ 115