1b8e80941Smrg/************************************************************************** 2b8e80941Smrg * 3b8e80941Smrg * Copyright 2019 VMware, Inc. 4b8e80941Smrg * All Rights Reserved. 5b8e80941Smrg * 6b8e80941Smrg * Permission is hereby granted, free of charge, to any person obtaining a 7b8e80941Smrg * copy of this software and associated documentation files (the 8b8e80941Smrg * "Software"), to deal in the Software without restriction, including 9b8e80941Smrg * without limitation the rights to use, copy, modify, merge, publish, 10b8e80941Smrg * distribute, sub license, and/or sell copies of the Software, and to 11b8e80941Smrg * permit persons to whom the Software is furnished to do so, subject to 12b8e80941Smrg * the following conditions: 13b8e80941Smrg * 14b8e80941Smrg * The above copyright notice and this permission notice (including the 15b8e80941Smrg * next paragraph) shall be included in all copies or substantial portions 16b8e80941Smrg * of the Software. 17b8e80941Smrg * 18b8e80941Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19b8e80941Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20b8e80941Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21b8e80941Smrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22b8e80941Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23b8e80941Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24b8e80941Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25b8e80941Smrg * 26b8e80941Smrg **************************************************************************/ 27b8e80941Smrg 28b8e80941Smrg 29b8e80941Smrg/* 30b8e80941Smrg * Miscellantous state tracker utility functions, macros. 31b8e80941Smrg */ 32b8e80941Smrg 33b8e80941Smrg 34b8e80941Smrg#ifndef ST_UTIL 35b8e80941Smrg#define ST_UTIL 36b8e80941Smrg 37b8e80941Smrg 38b8e80941Smrg#include "state_tracker/st_context.h" 39b8e80941Smrg 40b8e80941Smrg 41b8e80941Smrg#ifdef __cplusplus 42b8e80941Smrgextern "C" { 43b8e80941Smrg#endif 44b8e80941Smrg 45b8e80941Smrg 46b8e80941Smrg/** For drawing quads for glClear, glDraw/CopyPixels, glBitmap, etc. */ 47b8e80941Smrgstruct st_util_vertex 48b8e80941Smrg{ 49b8e80941Smrg float x, y, z; 50b8e80941Smrg float r, g, b, a; 51b8e80941Smrg float s, t; 52b8e80941Smrg}; 53b8e80941Smrg 54b8e80941Smrg 55b8e80941Smrg 56b8e80941Smrg/* Invalidate the readpixels cache to ensure we don't read stale data. 57b8e80941Smrg */ 58b8e80941Smrgstatic inline void 59b8e80941Smrgst_invalidate_readpix_cache(struct st_context *st) 60b8e80941Smrg{ 61b8e80941Smrg if (unlikely(st->readpix_cache.src)) { 62b8e80941Smrg pipe_resource_reference(&st->readpix_cache.src, NULL); 63b8e80941Smrg pipe_resource_reference(&st->readpix_cache.cache, NULL); 64b8e80941Smrg } 65b8e80941Smrg} 66b8e80941Smrg 67b8e80941Smrg 68b8e80941Smrg#define Y_0_TOP 1 69b8e80941Smrg#define Y_0_BOTTOM 2 70b8e80941Smrg 71b8e80941Smrgstatic inline GLuint 72b8e80941Smrgst_fb_orientation(const struct gl_framebuffer *fb) 73b8e80941Smrg{ 74b8e80941Smrg if (fb && _mesa_is_winsys_fbo(fb)) { 75b8e80941Smrg /* Drawing into a window (on-screen buffer). 76b8e80941Smrg * 77b8e80941Smrg * Negate Y scale to flip image vertically. 78b8e80941Smrg * The NDC Y coords prior to viewport transformation are in the range 79b8e80941Smrg * [y=-1=bottom, y=1=top] 80b8e80941Smrg * Hardware window coords are in the range [y=0=top, y=H-1=bottom] where 81b8e80941Smrg * H is the window height. 82b8e80941Smrg * Use the viewport transformation to invert Y. 83b8e80941Smrg */ 84b8e80941Smrg return Y_0_TOP; 85b8e80941Smrg } 86b8e80941Smrg else { 87b8e80941Smrg /* Drawing into user-created FBO (very likely a texture). 88b8e80941Smrg * 89b8e80941Smrg * For textures, T=0=Bottom, so by extension Y=0=Bottom for rendering. 90b8e80941Smrg */ 91b8e80941Smrg return Y_0_BOTTOM; 92b8e80941Smrg } 93b8e80941Smrg} 94b8e80941Smrg 95b8e80941Smrg 96b8e80941Smrgstatic inline bool 97b8e80941Smrgst_user_clip_planes_enabled(struct gl_context *ctx) 98b8e80941Smrg{ 99b8e80941Smrg return (ctx->API == API_OPENGL_COMPAT || 100b8e80941Smrg ctx->API == API_OPENGLES) && /* only ES 1.x */ 101b8e80941Smrg ctx->Transform.ClipPlanesEnabled; 102b8e80941Smrg} 103b8e80941Smrg 104b8e80941Smrg 105b8e80941Smrg/** clear-alloc a struct-sized object, with casting */ 106b8e80941Smrg#define ST_CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T)) 107b8e80941Smrg 108b8e80941Smrg 109b8e80941Smrg#ifdef __cplusplus 110b8e80941Smrg} 111b8e80941Smrg#endif 112b8e80941Smrg 113b8e80941Smrg 114b8e80941Smrg#endif /* ST_UTIL */ 115