1*61046927SAndroid Build Coastguard Worker /*
2*61046927SAndroid Build Coastguard Worker * Mesa 3-D graphics library
3*61046927SAndroid Build Coastguard Worker *
4*61046927SAndroid Build Coastguard Worker * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
5*61046927SAndroid Build Coastguard Worker *
6*61046927SAndroid Build Coastguard Worker * Permission is hereby granted, free of charge, to any person obtaining a
7*61046927SAndroid Build Coastguard Worker * copy of this software and associated documentation files (the "Software"),
8*61046927SAndroid Build Coastguard Worker * to deal in the Software without restriction, including without limitation
9*61046927SAndroid Build Coastguard Worker * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10*61046927SAndroid Build Coastguard Worker * and/or sell copies of the Software, and to permit persons to whom the
11*61046927SAndroid Build Coastguard Worker * Software is furnished to do so, subject to the following conditions:
12*61046927SAndroid Build Coastguard Worker *
13*61046927SAndroid Build Coastguard Worker * The above copyright notice and this permission notice shall be included
14*61046927SAndroid Build Coastguard Worker * in all copies or substantial portions of the Software.
15*61046927SAndroid Build Coastguard Worker *
16*61046927SAndroid Build Coastguard Worker * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17*61046927SAndroid Build Coastguard Worker * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18*61046927SAndroid Build Coastguard Worker * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19*61046927SAndroid Build Coastguard Worker * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20*61046927SAndroid Build Coastguard Worker * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21*61046927SAndroid Build Coastguard Worker * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22*61046927SAndroid Build Coastguard Worker * OTHER DEALINGS IN THE SOFTWARE.
23*61046927SAndroid Build Coastguard Worker */
24*61046927SAndroid Build Coastguard Worker
25*61046927SAndroid Build Coastguard Worker
26*61046927SAndroid Build Coastguard Worker /**
27*61046927SAndroid Build Coastguard Worker * \file context.h
28*61046927SAndroid Build Coastguard Worker * Mesa context and visual-related functions.
29*61046927SAndroid Build Coastguard Worker *
30*61046927SAndroid Build Coastguard Worker * There are three large Mesa data types/classes which are meant to be
31*61046927SAndroid Build Coastguard Worker * used by device drivers:
32*61046927SAndroid Build Coastguard Worker * - struct gl_context: this contains the Mesa rendering state
33*61046927SAndroid Build Coastguard Worker * - struct gl_config: this describes the color buffer (RGB vs. ci), whether
34*61046927SAndroid Build Coastguard Worker * or not there's a depth buffer, stencil buffer, etc.
35*61046927SAndroid Build Coastguard Worker * - struct gl_framebuffer: contains pointers to the depth buffer, stencil
36*61046927SAndroid Build Coastguard Worker * buffer, accum buffer and alpha buffers.
37*61046927SAndroid Build Coastguard Worker *
38*61046927SAndroid Build Coastguard Worker * These types should be encapsulated by corresponding device driver
39*61046927SAndroid Build Coastguard Worker * data types. See xmesa.h and xmesaP.h for an example.
40*61046927SAndroid Build Coastguard Worker *
41*61046927SAndroid Build Coastguard Worker * In OOP terms, struct gl_context, struct gl_config, and struct gl_framebuffer
42*61046927SAndroid Build Coastguard Worker * are base classes which the device driver must derive from.
43*61046927SAndroid Build Coastguard Worker *
44*61046927SAndroid Build Coastguard Worker * The following functions create and destroy these data types.
45*61046927SAndroid Build Coastguard Worker */
46*61046927SAndroid Build Coastguard Worker
47*61046927SAndroid Build Coastguard Worker
48*61046927SAndroid Build Coastguard Worker #ifndef CONTEXT_H
49*61046927SAndroid Build Coastguard Worker #define CONTEXT_H
50*61046927SAndroid Build Coastguard Worker
51*61046927SAndroid Build Coastguard Worker
52*61046927SAndroid Build Coastguard Worker #include "errors.h"
53*61046927SAndroid Build Coastguard Worker
54*61046927SAndroid Build Coastguard Worker #include "extensions.h"
55*61046927SAndroid Build Coastguard Worker #include "mtypes.h"
56*61046927SAndroid Build Coastguard Worker #include "vbo/vbo.h"
57*61046927SAndroid Build Coastguard Worker
58*61046927SAndroid Build Coastguard Worker
59*61046927SAndroid Build Coastguard Worker #ifdef __cplusplus
60*61046927SAndroid Build Coastguard Worker extern "C" {
61*61046927SAndroid Build Coastguard Worker #endif
62*61046927SAndroid Build Coastguard Worker
63*61046927SAndroid Build Coastguard Worker
64*61046927SAndroid Build Coastguard Worker struct _glapi_table;
65*61046927SAndroid Build Coastguard Worker
66*61046927SAndroid Build Coastguard Worker
67*61046927SAndroid Build Coastguard Worker /** \name Context-related functions */
68*61046927SAndroid Build Coastguard Worker /*@{*/
69*61046927SAndroid Build Coastguard Worker
70*61046927SAndroid Build Coastguard Worker extern void
71*61046927SAndroid Build Coastguard Worker _mesa_initialize(const char *extensions_override);
72*61046927SAndroid Build Coastguard Worker
73*61046927SAndroid Build Coastguard Worker extern GLboolean
74*61046927SAndroid Build Coastguard Worker _mesa_initialize_context( struct gl_context *ctx,
75*61046927SAndroid Build Coastguard Worker gl_api api,
76*61046927SAndroid Build Coastguard Worker bool no_error,
77*61046927SAndroid Build Coastguard Worker const struct gl_config *visual,
78*61046927SAndroid Build Coastguard Worker struct gl_context *share_list,
79*61046927SAndroid Build Coastguard Worker const struct dd_function_table *driverFunctions);
80*61046927SAndroid Build Coastguard Worker
81*61046927SAndroid Build Coastguard Worker extern struct _glapi_table *
82*61046927SAndroid Build Coastguard Worker _mesa_alloc_dispatch_table(bool glthread);
83*61046927SAndroid Build Coastguard Worker
84*61046927SAndroid Build Coastguard Worker extern void
85*61046927SAndroid Build Coastguard Worker _mesa_init_dispatch(struct gl_context *ctx);
86*61046927SAndroid Build Coastguard Worker
87*61046927SAndroid Build Coastguard Worker extern bool
88*61046927SAndroid Build Coastguard Worker _mesa_alloc_dispatch_tables(gl_api api, struct gl_dispatch *d, bool glthread);
89*61046927SAndroid Build Coastguard Worker
90*61046927SAndroid Build Coastguard Worker extern bool
91*61046927SAndroid Build Coastguard Worker _mesa_initialize_dispatch_tables(struct gl_context *ctx);
92*61046927SAndroid Build Coastguard Worker
93*61046927SAndroid Build Coastguard Worker extern struct _glapi_table *
94*61046927SAndroid Build Coastguard Worker _mesa_new_nop_table(unsigned numEntries, bool glthread);
95*61046927SAndroid Build Coastguard Worker
96*61046927SAndroid Build Coastguard Worker extern void
97*61046927SAndroid Build Coastguard Worker _mesa_free_context_data(struct gl_context *ctx, bool destroy_debug_output);
98*61046927SAndroid Build Coastguard Worker
99*61046927SAndroid Build Coastguard Worker extern void
100*61046927SAndroid Build Coastguard Worker _mesa_copy_context(const struct gl_context *src, struct gl_context *dst, GLuint mask);
101*61046927SAndroid Build Coastguard Worker
102*61046927SAndroid Build Coastguard Worker extern GLboolean
103*61046927SAndroid Build Coastguard Worker _mesa_make_current( struct gl_context *ctx, struct gl_framebuffer *drawBuffer,
104*61046927SAndroid Build Coastguard Worker struct gl_framebuffer *readBuffer );
105*61046927SAndroid Build Coastguard Worker
106*61046927SAndroid Build Coastguard Worker extern GLboolean
107*61046927SAndroid Build Coastguard Worker _mesa_share_state(struct gl_context *ctx, struct gl_context *ctxToShare);
108*61046927SAndroid Build Coastguard Worker
109*61046927SAndroid Build Coastguard Worker extern struct gl_context *
110*61046927SAndroid Build Coastguard Worker _mesa_get_current_context(void);
111*61046927SAndroid Build Coastguard Worker
112*61046927SAndroid Build Coastguard Worker /*@}*/
113*61046927SAndroid Build Coastguard Worker
114*61046927SAndroid Build Coastguard Worker extern void
115*61046927SAndroid Build Coastguard Worker _mesa_init_constants(struct gl_constants *consts, gl_api api);
116*61046927SAndroid Build Coastguard Worker
117*61046927SAndroid Build Coastguard Worker extern void
118*61046927SAndroid Build Coastguard Worker _mesa_set_context_lost_dispatch(struct gl_context *ctx);
119*61046927SAndroid Build Coastguard Worker
120*61046927SAndroid Build Coastguard Worker
121*61046927SAndroid Build Coastguard Worker
122*61046927SAndroid Build Coastguard Worker /** \name Miscellaneous */
123*61046927SAndroid Build Coastguard Worker /*@{*/
124*61046927SAndroid Build Coastguard Worker
125*61046927SAndroid Build Coastguard Worker extern void
126*61046927SAndroid Build Coastguard Worker _mesa_flush(struct gl_context *ctx);
127*61046927SAndroid Build Coastguard Worker
128*61046927SAndroid Build Coastguard Worker /*@}*/
129*61046927SAndroid Build Coastguard Worker
130*61046927SAndroid Build Coastguard Worker
131*61046927SAndroid Build Coastguard Worker /**
132*61046927SAndroid Build Coastguard Worker * Are we currently between glBegin and glEnd?
133*61046927SAndroid Build Coastguard Worker * During execution, not display list compilation.
134*61046927SAndroid Build Coastguard Worker */
135*61046927SAndroid Build Coastguard Worker static inline GLboolean
_mesa_inside_begin_end(const struct gl_context * ctx)136*61046927SAndroid Build Coastguard Worker _mesa_inside_begin_end(const struct gl_context *ctx)
137*61046927SAndroid Build Coastguard Worker {
138*61046927SAndroid Build Coastguard Worker return ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END;
139*61046927SAndroid Build Coastguard Worker }
140*61046927SAndroid Build Coastguard Worker
141*61046927SAndroid Build Coastguard Worker
142*61046927SAndroid Build Coastguard Worker /**
143*61046927SAndroid Build Coastguard Worker * Are we currently between glBegin and glEnd in a display list?
144*61046927SAndroid Build Coastguard Worker */
145*61046927SAndroid Build Coastguard Worker static inline GLboolean
_mesa_inside_dlist_begin_end(const struct gl_context * ctx)146*61046927SAndroid Build Coastguard Worker _mesa_inside_dlist_begin_end(const struct gl_context *ctx)
147*61046927SAndroid Build Coastguard Worker {
148*61046927SAndroid Build Coastguard Worker return ctx->Driver.CurrentSavePrimitive <= PRIM_MAX;
149*61046927SAndroid Build Coastguard Worker }
150*61046927SAndroid Build Coastguard Worker
151*61046927SAndroid Build Coastguard Worker
152*61046927SAndroid Build Coastguard Worker
153*61046927SAndroid Build Coastguard Worker /**
154*61046927SAndroid Build Coastguard Worker * \name Macros for flushing buffered rendering commands before state changes,
155*61046927SAndroid Build Coastguard Worker * checking if inside glBegin/glEnd, etc.
156*61046927SAndroid Build Coastguard Worker */
157*61046927SAndroid Build Coastguard Worker /*@{*/
158*61046927SAndroid Build Coastguard Worker
159*61046927SAndroid Build Coastguard Worker /**
160*61046927SAndroid Build Coastguard Worker * Flush vertices.
161*61046927SAndroid Build Coastguard Worker *
162*61046927SAndroid Build Coastguard Worker * \param ctx GL context.
163*61046927SAndroid Build Coastguard Worker * \param newstate new state.
164*61046927SAndroid Build Coastguard Worker *
165*61046927SAndroid Build Coastguard Worker * Checks if dd_function_table::NeedFlush is marked to flush stored vertices,
166*61046927SAndroid Build Coastguard Worker * and calls dd_function_table::FlushVertices if so. Marks
167*61046927SAndroid Build Coastguard Worker * __struct gl_contextRec::NewState with \p newstate.
168*61046927SAndroid Build Coastguard Worker */
169*61046927SAndroid Build Coastguard Worker #define FLUSH_VERTICES(ctx, newstate, pop_attrib_mask) \
170*61046927SAndroid Build Coastguard Worker do { \
171*61046927SAndroid Build Coastguard Worker if (MESA_VERBOSE & VERBOSE_STATE) \
172*61046927SAndroid Build Coastguard Worker _mesa_debug(ctx, "FLUSH_VERTICES in %s\n", __func__); \
173*61046927SAndroid Build Coastguard Worker if (ctx->Driver.NeedFlush & FLUSH_STORED_VERTICES) \
174*61046927SAndroid Build Coastguard Worker vbo_exec_FlushVertices(ctx, FLUSH_STORED_VERTICES); \
175*61046927SAndroid Build Coastguard Worker ctx->NewState |= newstate; \
176*61046927SAndroid Build Coastguard Worker ctx->PopAttribState |= pop_attrib_mask; \
177*61046927SAndroid Build Coastguard Worker } while (0)
178*61046927SAndroid Build Coastguard Worker
179*61046927SAndroid Build Coastguard Worker /**
180*61046927SAndroid Build Coastguard Worker * Flush current state.
181*61046927SAndroid Build Coastguard Worker *
182*61046927SAndroid Build Coastguard Worker * \param ctx GL context.
183*61046927SAndroid Build Coastguard Worker * \param newstate new state.
184*61046927SAndroid Build Coastguard Worker *
185*61046927SAndroid Build Coastguard Worker * Checks if dd_function_table::NeedFlush is marked to flush current state,
186*61046927SAndroid Build Coastguard Worker * and calls dd_function_table::FlushVertices if so. Marks
187*61046927SAndroid Build Coastguard Worker * __struct gl_contextRec::NewState with \p newstate.
188*61046927SAndroid Build Coastguard Worker */
189*61046927SAndroid Build Coastguard Worker #define FLUSH_CURRENT(ctx, newstate) \
190*61046927SAndroid Build Coastguard Worker do { \
191*61046927SAndroid Build Coastguard Worker if (MESA_VERBOSE & VERBOSE_STATE) \
192*61046927SAndroid Build Coastguard Worker _mesa_debug(ctx, "FLUSH_CURRENT in %s\n", __func__); \
193*61046927SAndroid Build Coastguard Worker if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) \
194*61046927SAndroid Build Coastguard Worker vbo_exec_FlushVertices(ctx, FLUSH_UPDATE_CURRENT); \
195*61046927SAndroid Build Coastguard Worker ctx->NewState |= newstate; \
196*61046927SAndroid Build Coastguard Worker } while (0)
197*61046927SAndroid Build Coastguard Worker
198*61046927SAndroid Build Coastguard Worker /**
199*61046927SAndroid Build Coastguard Worker * Flush vertices.
200*61046927SAndroid Build Coastguard Worker *
201*61046927SAndroid Build Coastguard Worker * \param ctx GL context.
202*61046927SAndroid Build Coastguard Worker *
203*61046927SAndroid Build Coastguard Worker * Checks if dd_function_table::NeedFlush is marked to flush stored vertices
204*61046927SAndroid Build Coastguard Worker * or current state and calls dd_function_table::FlushVertices if so.
205*61046927SAndroid Build Coastguard Worker */
206*61046927SAndroid Build Coastguard Worker #define FLUSH_FOR_DRAW(ctx) \
207*61046927SAndroid Build Coastguard Worker do { \
208*61046927SAndroid Build Coastguard Worker if (MESA_VERBOSE & VERBOSE_STATE) \
209*61046927SAndroid Build Coastguard Worker _mesa_debug(ctx, "FLUSH_FOR_DRAW in %s\n", __func__); \
210*61046927SAndroid Build Coastguard Worker if (ctx->Driver.NeedFlush) { \
211*61046927SAndroid Build Coastguard Worker if (ctx->_AllowDrawOutOfOrder) { \
212*61046927SAndroid Build Coastguard Worker if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) \
213*61046927SAndroid Build Coastguard Worker vbo_exec_FlushVertices(ctx, FLUSH_UPDATE_CURRENT); \
214*61046927SAndroid Build Coastguard Worker } else { \
215*61046927SAndroid Build Coastguard Worker vbo_exec_FlushVertices(ctx, ctx->Driver.NeedFlush); \
216*61046927SAndroid Build Coastguard Worker } \
217*61046927SAndroid Build Coastguard Worker } \
218*61046927SAndroid Build Coastguard Worker } while (0)
219*61046927SAndroid Build Coastguard Worker
220*61046927SAndroid Build Coastguard Worker /**
221*61046927SAndroid Build Coastguard Worker * Macro to assert that the API call was made outside the
222*61046927SAndroid Build Coastguard Worker * glBegin()/glEnd() pair, with return value.
223*61046927SAndroid Build Coastguard Worker *
224*61046927SAndroid Build Coastguard Worker * \param ctx GL context.
225*61046927SAndroid Build Coastguard Worker * \param retval value to return in case the assertion fails.
226*61046927SAndroid Build Coastguard Worker */
227*61046927SAndroid Build Coastguard Worker #define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval) \
228*61046927SAndroid Build Coastguard Worker do { \
229*61046927SAndroid Build Coastguard Worker if (_mesa_inside_begin_end(ctx)) { \
230*61046927SAndroid Build Coastguard Worker _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
231*61046927SAndroid Build Coastguard Worker return retval; \
232*61046927SAndroid Build Coastguard Worker } \
233*61046927SAndroid Build Coastguard Worker } while (0)
234*61046927SAndroid Build Coastguard Worker
235*61046927SAndroid Build Coastguard Worker /**
236*61046927SAndroid Build Coastguard Worker * Macro to assert that the API call was made outside the
237*61046927SAndroid Build Coastguard Worker * glBegin()/glEnd() pair.
238*61046927SAndroid Build Coastguard Worker *
239*61046927SAndroid Build Coastguard Worker * \param ctx GL context.
240*61046927SAndroid Build Coastguard Worker */
241*61046927SAndroid Build Coastguard Worker #define ASSERT_OUTSIDE_BEGIN_END(ctx) \
242*61046927SAndroid Build Coastguard Worker do { \
243*61046927SAndroid Build Coastguard Worker if (_mesa_inside_begin_end(ctx)) { \
244*61046927SAndroid Build Coastguard Worker _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \
245*61046927SAndroid Build Coastguard Worker return; \
246*61046927SAndroid Build Coastguard Worker } \
247*61046927SAndroid Build Coastguard Worker } while (0)
248*61046927SAndroid Build Coastguard Worker
249*61046927SAndroid Build Coastguard Worker /*@}*/
250*61046927SAndroid Build Coastguard Worker
251*61046927SAndroid Build Coastguard Worker
252*61046927SAndroid Build Coastguard Worker /**
253*61046927SAndroid Build Coastguard Worker * Checks if the context is for Desktop GL Compatibility
254*61046927SAndroid Build Coastguard Worker */
255*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_is_desktop_gl_compat(const struct gl_context * ctx)256*61046927SAndroid Build Coastguard Worker _mesa_is_desktop_gl_compat(const struct gl_context *ctx)
257*61046927SAndroid Build Coastguard Worker {
258*61046927SAndroid Build Coastguard Worker #if HAVE_OPENGL
259*61046927SAndroid Build Coastguard Worker return ctx->API == API_OPENGL_COMPAT;
260*61046927SAndroid Build Coastguard Worker #else
261*61046927SAndroid Build Coastguard Worker return false;
262*61046927SAndroid Build Coastguard Worker #endif
263*61046927SAndroid Build Coastguard Worker }
264*61046927SAndroid Build Coastguard Worker
265*61046927SAndroid Build Coastguard Worker /**
266*61046927SAndroid Build Coastguard Worker * Checks if the context is for Desktop GL Core
267*61046927SAndroid Build Coastguard Worker */
268*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_is_desktop_gl_core(const struct gl_context * ctx)269*61046927SAndroid Build Coastguard Worker _mesa_is_desktop_gl_core(const struct gl_context *ctx)
270*61046927SAndroid Build Coastguard Worker {
271*61046927SAndroid Build Coastguard Worker #if HAVE_OPENGL
272*61046927SAndroid Build Coastguard Worker return ctx->API == API_OPENGL_CORE;
273*61046927SAndroid Build Coastguard Worker #else
274*61046927SAndroid Build Coastguard Worker return false;
275*61046927SAndroid Build Coastguard Worker #endif
276*61046927SAndroid Build Coastguard Worker }
277*61046927SAndroid Build Coastguard Worker
278*61046927SAndroid Build Coastguard Worker /**
279*61046927SAndroid Build Coastguard Worker * Checks if the context is for Desktop GL (Compatibility or Core)
280*61046927SAndroid Build Coastguard Worker */
281*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_is_desktop_gl(const struct gl_context * ctx)282*61046927SAndroid Build Coastguard Worker _mesa_is_desktop_gl(const struct gl_context *ctx)
283*61046927SAndroid Build Coastguard Worker {
284*61046927SAndroid Build Coastguard Worker return _mesa_is_desktop_gl_compat(ctx) || _mesa_is_desktop_gl_core(ctx);
285*61046927SAndroid Build Coastguard Worker }
286*61046927SAndroid Build Coastguard Worker
287*61046927SAndroid Build Coastguard Worker /**
288*61046927SAndroid Build Coastguard Worker * Checks if the context is for GLES 1.0
289*61046927SAndroid Build Coastguard Worker */
290*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_is_gles1(const struct gl_context * ctx)291*61046927SAndroid Build Coastguard Worker _mesa_is_gles1(const struct gl_context *ctx)
292*61046927SAndroid Build Coastguard Worker {
293*61046927SAndroid Build Coastguard Worker #if HAVE_OPENGL_ES_1
294*61046927SAndroid Build Coastguard Worker return ctx->API == API_OPENGLES;
295*61046927SAndroid Build Coastguard Worker #else
296*61046927SAndroid Build Coastguard Worker return false;
297*61046927SAndroid Build Coastguard Worker #endif
298*61046927SAndroid Build Coastguard Worker }
299*61046927SAndroid Build Coastguard Worker
300*61046927SAndroid Build Coastguard Worker /**
301*61046927SAndroid Build Coastguard Worker * Checks if the context is for GLES 2.0 or later
302*61046927SAndroid Build Coastguard Worker */
303*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_is_gles2(const struct gl_context * ctx)304*61046927SAndroid Build Coastguard Worker _mesa_is_gles2(const struct gl_context *ctx)
305*61046927SAndroid Build Coastguard Worker {
306*61046927SAndroid Build Coastguard Worker return _mesa_is_api_gles2(ctx->API);
307*61046927SAndroid Build Coastguard Worker }
308*61046927SAndroid Build Coastguard Worker
309*61046927SAndroid Build Coastguard Worker /**
310*61046927SAndroid Build Coastguard Worker * Checks if the context is for any GLES version
311*61046927SAndroid Build Coastguard Worker */
312*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_is_gles(const struct gl_context * ctx)313*61046927SAndroid Build Coastguard Worker _mesa_is_gles(const struct gl_context *ctx)
314*61046927SAndroid Build Coastguard Worker {
315*61046927SAndroid Build Coastguard Worker return _mesa_is_gles1(ctx) || _mesa_is_gles2(ctx);
316*61046927SAndroid Build Coastguard Worker }
317*61046927SAndroid Build Coastguard Worker
318*61046927SAndroid Build Coastguard Worker /**
319*61046927SAndroid Build Coastguard Worker * Checks if the context is for GLES 3.0 or later
320*61046927SAndroid Build Coastguard Worker */
321*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_is_gles3(const struct gl_context * ctx)322*61046927SAndroid Build Coastguard Worker _mesa_is_gles3(const struct gl_context *ctx)
323*61046927SAndroid Build Coastguard Worker {
324*61046927SAndroid Build Coastguard Worker return _mesa_is_gles2(ctx) && ctx->Version >= 30;
325*61046927SAndroid Build Coastguard Worker }
326*61046927SAndroid Build Coastguard Worker
327*61046927SAndroid Build Coastguard Worker
328*61046927SAndroid Build Coastguard Worker /**
329*61046927SAndroid Build Coastguard Worker * Checks if the context is for GLES 3.1 or later
330*61046927SAndroid Build Coastguard Worker */
331*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_is_gles31(const struct gl_context * ctx)332*61046927SAndroid Build Coastguard Worker _mesa_is_gles31(const struct gl_context *ctx)
333*61046927SAndroid Build Coastguard Worker {
334*61046927SAndroid Build Coastguard Worker return _mesa_is_gles2(ctx) && ctx->Version >= 31;
335*61046927SAndroid Build Coastguard Worker }
336*61046927SAndroid Build Coastguard Worker
337*61046927SAndroid Build Coastguard Worker
338*61046927SAndroid Build Coastguard Worker /**
339*61046927SAndroid Build Coastguard Worker * Checks if the context is for GLES 3.2 or later
340*61046927SAndroid Build Coastguard Worker */
341*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_is_gles32(const struct gl_context * ctx)342*61046927SAndroid Build Coastguard Worker _mesa_is_gles32(const struct gl_context *ctx)
343*61046927SAndroid Build Coastguard Worker {
344*61046927SAndroid Build Coastguard Worker return _mesa_is_gles2(ctx) && ctx->Version >= 32;
345*61046927SAndroid Build Coastguard Worker }
346*61046927SAndroid Build Coastguard Worker
347*61046927SAndroid Build Coastguard Worker
348*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_is_gles2_compatible(const struct gl_context * ctx)349*61046927SAndroid Build Coastguard Worker _mesa_is_gles2_compatible(const struct gl_context *ctx)
350*61046927SAndroid Build Coastguard Worker {
351*61046927SAndroid Build Coastguard Worker return _mesa_is_gles2(ctx) || _mesa_has_ARB_ES2_compatibility(ctx);
352*61046927SAndroid Build Coastguard Worker }
353*61046927SAndroid Build Coastguard Worker
354*61046927SAndroid Build Coastguard Worker
355*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_is_gles3_compatible(const struct gl_context * ctx)356*61046927SAndroid Build Coastguard Worker _mesa_is_gles3_compatible(const struct gl_context *ctx)
357*61046927SAndroid Build Coastguard Worker {
358*61046927SAndroid Build Coastguard Worker return _mesa_is_gles3(ctx) || _mesa_has_ARB_ES3_compatibility(ctx);
359*61046927SAndroid Build Coastguard Worker }
360*61046927SAndroid Build Coastguard Worker
361*61046927SAndroid Build Coastguard Worker
362*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_is_gles31_compatible(const struct gl_context * ctx)363*61046927SAndroid Build Coastguard Worker _mesa_is_gles31_compatible(const struct gl_context *ctx)
364*61046927SAndroid Build Coastguard Worker {
365*61046927SAndroid Build Coastguard Worker return _mesa_is_gles31(ctx) || _mesa_has_ARB_ES3_1_compatibility(ctx);
366*61046927SAndroid Build Coastguard Worker }
367*61046927SAndroid Build Coastguard Worker
368*61046927SAndroid Build Coastguard Worker
369*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_is_gles32_compatible(const struct gl_context * ctx)370*61046927SAndroid Build Coastguard Worker _mesa_is_gles32_compatible(const struct gl_context *ctx)
371*61046927SAndroid Build Coastguard Worker {
372*61046927SAndroid Build Coastguard Worker return _mesa_is_gles32(ctx) || _mesa_has_ARB_ES3_2_compatibility(ctx);
373*61046927SAndroid Build Coastguard Worker }
374*61046927SAndroid Build Coastguard Worker
375*61046927SAndroid Build Coastguard Worker
376*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_is_no_error_enabled(const struct gl_context * ctx)377*61046927SAndroid Build Coastguard Worker _mesa_is_no_error_enabled(const struct gl_context *ctx)
378*61046927SAndroid Build Coastguard Worker {
379*61046927SAndroid Build Coastguard Worker return ctx->Const.ContextFlags & GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR;
380*61046927SAndroid Build Coastguard Worker }
381*61046927SAndroid Build Coastguard Worker
382*61046927SAndroid Build Coastguard Worker
383*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_has_integer_textures(const struct gl_context * ctx)384*61046927SAndroid Build Coastguard Worker _mesa_has_integer_textures(const struct gl_context *ctx)
385*61046927SAndroid Build Coastguard Worker {
386*61046927SAndroid Build Coastguard Worker return _mesa_has_EXT_texture_integer(ctx) || _mesa_is_gles3(ctx);
387*61046927SAndroid Build Coastguard Worker }
388*61046927SAndroid Build Coastguard Worker
389*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_has_half_float_textures(const struct gl_context * ctx)390*61046927SAndroid Build Coastguard Worker _mesa_has_half_float_textures(const struct gl_context *ctx)
391*61046927SAndroid Build Coastguard Worker {
392*61046927SAndroid Build Coastguard Worker return _mesa_has_ARB_texture_float(ctx) ||
393*61046927SAndroid Build Coastguard Worker _mesa_has_OES_texture_half_float(ctx);
394*61046927SAndroid Build Coastguard Worker }
395*61046927SAndroid Build Coastguard Worker
396*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_has_float_textures(const struct gl_context * ctx)397*61046927SAndroid Build Coastguard Worker _mesa_has_float_textures(const struct gl_context *ctx)
398*61046927SAndroid Build Coastguard Worker {
399*61046927SAndroid Build Coastguard Worker return _mesa_has_ARB_texture_float(ctx) ||
400*61046927SAndroid Build Coastguard Worker _mesa_has_OES_texture_float(ctx) || _mesa_is_gles3(ctx);
401*61046927SAndroid Build Coastguard Worker }
402*61046927SAndroid Build Coastguard Worker
403*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_has_texture_rgb10_a2ui(const struct gl_context * ctx)404*61046927SAndroid Build Coastguard Worker _mesa_has_texture_rgb10_a2ui(const struct gl_context *ctx)
405*61046927SAndroid Build Coastguard Worker {
406*61046927SAndroid Build Coastguard Worker return _mesa_has_ARB_texture_rgb10_a2ui(ctx) || _mesa_is_gles3(ctx);
407*61046927SAndroid Build Coastguard Worker }
408*61046927SAndroid Build Coastguard Worker
409*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_has_float_depth_buffer(const struct gl_context * ctx)410*61046927SAndroid Build Coastguard Worker _mesa_has_float_depth_buffer(const struct gl_context *ctx)
411*61046927SAndroid Build Coastguard Worker {
412*61046927SAndroid Build Coastguard Worker return _mesa_has_ARB_depth_buffer_float(ctx) || _mesa_is_gles3(ctx);
413*61046927SAndroid Build Coastguard Worker }
414*61046927SAndroid Build Coastguard Worker
415*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_has_packed_float(const struct gl_context * ctx)416*61046927SAndroid Build Coastguard Worker _mesa_has_packed_float(const struct gl_context *ctx)
417*61046927SAndroid Build Coastguard Worker {
418*61046927SAndroid Build Coastguard Worker return _mesa_has_EXT_packed_float(ctx) || _mesa_is_gles3(ctx);
419*61046927SAndroid Build Coastguard Worker }
420*61046927SAndroid Build Coastguard Worker
421*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_has_rg_textures(const struct gl_context * ctx)422*61046927SAndroid Build Coastguard Worker _mesa_has_rg_textures(const struct gl_context *ctx)
423*61046927SAndroid Build Coastguard Worker {
424*61046927SAndroid Build Coastguard Worker return _mesa_has_ARB_texture_rg(ctx) || _mesa_has_EXT_texture_rg(ctx) ||
425*61046927SAndroid Build Coastguard Worker _mesa_is_gles3(ctx);
426*61046927SAndroid Build Coastguard Worker }
427*61046927SAndroid Build Coastguard Worker
428*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_has_texture_shared_exponent(const struct gl_context * ctx)429*61046927SAndroid Build Coastguard Worker _mesa_has_texture_shared_exponent(const struct gl_context *ctx)
430*61046927SAndroid Build Coastguard Worker {
431*61046927SAndroid Build Coastguard Worker return _mesa_has_EXT_texture_shared_exponent(ctx) || _mesa_is_gles3(ctx);
432*61046927SAndroid Build Coastguard Worker }
433*61046927SAndroid Build Coastguard Worker
434*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_has_texture_type_2_10_10_10_REV(const struct gl_context * ctx)435*61046927SAndroid Build Coastguard Worker _mesa_has_texture_type_2_10_10_10_REV(const struct gl_context *ctx)
436*61046927SAndroid Build Coastguard Worker {
437*61046927SAndroid Build Coastguard Worker return _mesa_is_desktop_gl(ctx) ||
438*61046927SAndroid Build Coastguard Worker _mesa_has_EXT_texture_type_2_10_10_10_REV(ctx);
439*61046927SAndroid Build Coastguard Worker }
440*61046927SAndroid Build Coastguard Worker
441*61046927SAndroid Build Coastguard Worker /**
442*61046927SAndroid Build Coastguard Worker * Checks if the context supports geometry shaders.
443*61046927SAndroid Build Coastguard Worker */
444*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_has_geometry_shaders(const struct gl_context * ctx)445*61046927SAndroid Build Coastguard Worker _mesa_has_geometry_shaders(const struct gl_context *ctx)
446*61046927SAndroid Build Coastguard Worker {
447*61046927SAndroid Build Coastguard Worker return _mesa_has_OES_geometry_shader(ctx) ||
448*61046927SAndroid Build Coastguard Worker (_mesa_is_desktop_gl(ctx) && ctx->Version >= 32);
449*61046927SAndroid Build Coastguard Worker }
450*61046927SAndroid Build Coastguard Worker
451*61046927SAndroid Build Coastguard Worker
452*61046927SAndroid Build Coastguard Worker /**
453*61046927SAndroid Build Coastguard Worker * Checks if the context supports compute shaders.
454*61046927SAndroid Build Coastguard Worker */
455*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_has_compute_shaders(const struct gl_context * ctx)456*61046927SAndroid Build Coastguard Worker _mesa_has_compute_shaders(const struct gl_context *ctx)
457*61046927SAndroid Build Coastguard Worker {
458*61046927SAndroid Build Coastguard Worker return _mesa_has_ARB_compute_shader(ctx) ||
459*61046927SAndroid Build Coastguard Worker _mesa_is_gles31(ctx);
460*61046927SAndroid Build Coastguard Worker }
461*61046927SAndroid Build Coastguard Worker
462*61046927SAndroid Build Coastguard Worker /**
463*61046927SAndroid Build Coastguard Worker * Checks if the context supports tessellation.
464*61046927SAndroid Build Coastguard Worker */
465*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_has_tessellation(const struct gl_context * ctx)466*61046927SAndroid Build Coastguard Worker _mesa_has_tessellation(const struct gl_context *ctx)
467*61046927SAndroid Build Coastguard Worker {
468*61046927SAndroid Build Coastguard Worker /* _mesa_has_EXT_tessellation_shader(ctx) is redundant with the OES
469*61046927SAndroid Build Coastguard Worker * check, so don't bother calling it.
470*61046927SAndroid Build Coastguard Worker */
471*61046927SAndroid Build Coastguard Worker return _mesa_has_OES_tessellation_shader(ctx) ||
472*61046927SAndroid Build Coastguard Worker _mesa_has_ARB_tessellation_shader(ctx);
473*61046927SAndroid Build Coastguard Worker }
474*61046927SAndroid Build Coastguard Worker
475*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_has_texture_cube_map_array(const struct gl_context * ctx)476*61046927SAndroid Build Coastguard Worker _mesa_has_texture_cube_map_array(const struct gl_context *ctx)
477*61046927SAndroid Build Coastguard Worker {
478*61046927SAndroid Build Coastguard Worker return _mesa_has_ARB_texture_cube_map_array(ctx) ||
479*61046927SAndroid Build Coastguard Worker _mesa_has_OES_texture_cube_map_array(ctx);
480*61046927SAndroid Build Coastguard Worker }
481*61046927SAndroid Build Coastguard Worker
482*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_has_texture_view(const struct gl_context * ctx)483*61046927SAndroid Build Coastguard Worker _mesa_has_texture_view(const struct gl_context *ctx)
484*61046927SAndroid Build Coastguard Worker {
485*61046927SAndroid Build Coastguard Worker return _mesa_has_ARB_texture_view(ctx) ||
486*61046927SAndroid Build Coastguard Worker _mesa_has_OES_texture_view(ctx);
487*61046927SAndroid Build Coastguard Worker }
488*61046927SAndroid Build Coastguard Worker
489*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_hw_select_enabled(const struct gl_context * ctx)490*61046927SAndroid Build Coastguard Worker _mesa_hw_select_enabled(const struct gl_context *ctx)
491*61046927SAndroid Build Coastguard Worker {
492*61046927SAndroid Build Coastguard Worker return ctx->RenderMode == GL_SELECT &&
493*61046927SAndroid Build Coastguard Worker ctx->Const.HardwareAcceleratedSelect;
494*61046927SAndroid Build Coastguard Worker }
495*61046927SAndroid Build Coastguard Worker
496*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_has_occlusion_query(const struct gl_context * ctx)497*61046927SAndroid Build Coastguard Worker _mesa_has_occlusion_query(const struct gl_context *ctx)
498*61046927SAndroid Build Coastguard Worker {
499*61046927SAndroid Build Coastguard Worker return _mesa_has_ARB_occlusion_query(ctx) ||
500*61046927SAndroid Build Coastguard Worker _mesa_has_ARB_occlusion_query2(ctx) ||
501*61046927SAndroid Build Coastguard Worker (_mesa_is_desktop_gl(ctx) && ctx->Version >= 15);
502*61046927SAndroid Build Coastguard Worker }
503*61046927SAndroid Build Coastguard Worker
504*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_has_occlusion_query_boolean(const struct gl_context * ctx)505*61046927SAndroid Build Coastguard Worker _mesa_has_occlusion_query_boolean(const struct gl_context *ctx)
506*61046927SAndroid Build Coastguard Worker {
507*61046927SAndroid Build Coastguard Worker return _mesa_has_ARB_occlusion_query2(ctx) ||
508*61046927SAndroid Build Coastguard Worker _mesa_has_EXT_occlusion_query_boolean(ctx) ||
509*61046927SAndroid Build Coastguard Worker (_mesa_is_desktop_gl(ctx) && ctx->Version >= 33);
510*61046927SAndroid Build Coastguard Worker }
511*61046927SAndroid Build Coastguard Worker
512*61046927SAndroid Build Coastguard Worker static inline bool
_mesa_has_pipeline_statistics(const struct gl_context * ctx)513*61046927SAndroid Build Coastguard Worker _mesa_has_pipeline_statistics(const struct gl_context *ctx)
514*61046927SAndroid Build Coastguard Worker {
515*61046927SAndroid Build Coastguard Worker return _mesa_has_ARB_pipeline_statistics_query(ctx) ||
516*61046927SAndroid Build Coastguard Worker (_mesa_is_desktop_gl(ctx) && ctx->Version >= 46);
517*61046927SAndroid Build Coastguard Worker }
518*61046927SAndroid Build Coastguard Worker
519*61046927SAndroid Build Coastguard Worker #ifdef __cplusplus
520*61046927SAndroid Build Coastguard Worker }
521*61046927SAndroid Build Coastguard Worker #endif
522*61046927SAndroid Build Coastguard Worker
523*61046927SAndroid Build Coastguard Worker
524*61046927SAndroid Build Coastguard Worker #endif /* CONTEXT_H */
525