Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5564 serge 1
/*
2
 * Mesa 3-D graphics library
3
 *
4
 * Copyright (C) 1999-2006  Brian Paul   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 "Software"),
8
 * to deal in the Software without restriction, including without limitation
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
 * and/or sell copies of the Software, and to permit persons to whom the
11
 * Software is furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included
14
 * in all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
 * OTHER DEALINGS IN THE SOFTWARE.
23
 */
24
 
25
 
26
/**
27
 * \file context.h
28
 * Mesa context and visual-related functions.
29
 *
30
 * There are three large Mesa data types/classes which are meant to be
31
 * used by device drivers:
32
 * - struct gl_context: this contains the Mesa rendering state
33
 * - struct gl_config:  this describes the color buffer (RGB vs. ci), whether
34
 *   or not there's a depth buffer, stencil buffer, etc.
35
 * - struct gl_framebuffer:  contains pointers to the depth buffer, stencil
36
 *   buffer, accum buffer and alpha buffers.
37
 *
38
 * These types should be encapsulated by corresponding device driver
39
 * data types.  See xmesa.h and xmesaP.h for an example.
40
 *
41
 * In OOP terms, struct gl_context, struct gl_config, and struct gl_framebuffer
42
 * are base classes which the device driver must derive from.
43
 *
44
 * The following functions create and destroy these data types.
45
 */
46
 
47
 
48
#ifndef CONTEXT_H
49
#define CONTEXT_H
50
 
51
 
52
#include "imports.h"
53
#include "mtypes.h"
54
 
55
 
56
#ifdef __cplusplus
57
extern "C" {
58
#endif
59
 
60
 
61
struct _glapi_table;
62
 
63
 
64
/** \name Visual-related functions */
65
/*@{*/
66
 
67
extern struct gl_config *
68
_mesa_create_visual( GLboolean dbFlag,
69
                     GLboolean stereoFlag,
70
                     GLint redBits,
71
                     GLint greenBits,
72
                     GLint blueBits,
73
                     GLint alphaBits,
74
                     GLint depthBits,
75
                     GLint stencilBits,
76
                     GLint accumRedBits,
77
                     GLint accumGreenBits,
78
                     GLint accumBlueBits,
79
                     GLint accumAlphaBits,
80
                     GLint numSamples );
81
 
82
extern GLboolean
83
_mesa_initialize_visual( struct gl_config *v,
84
                         GLboolean dbFlag,
85
                         GLboolean stereoFlag,
86
                         GLint redBits,
87
                         GLint greenBits,
88
                         GLint blueBits,
89
                         GLint alphaBits,
90
                         GLint depthBits,
91
                         GLint stencilBits,
92
                         GLint accumRedBits,
93
                         GLint accumGreenBits,
94
                         GLint accumBlueBits,
95
                         GLint accumAlphaBits,
96
                         GLint numSamples );
97
 
98
extern void
99
_mesa_destroy_visual( struct gl_config *vis );
100
 
101
/*@}*/
102
 
103
 
104
/** \name Context-related functions */
105
/*@{*/
106
 
107
extern GLboolean
108
_mesa_initialize_context( struct gl_context *ctx,
109
                          gl_api api,
110
                          const struct gl_config *visual,
111
                          struct gl_context *share_list,
112
                          const struct dd_function_table *driverFunctions);
113
 
114
extern struct gl_context *
115
_mesa_create_context(gl_api api,
116
                     const struct gl_config *visual,
117
                     struct gl_context *share_list,
118
                     const struct dd_function_table *driverFunctions);
119
 
120
extern void
121
_mesa_free_context_data( struct gl_context *ctx );
122
 
123
extern void
124
_mesa_destroy_context( struct gl_context *ctx );
125
 
126
 
127
extern void
128
_mesa_copy_context(const struct gl_context *src, struct gl_context *dst, GLuint mask);
129
 
130
 
131
extern void
132
_mesa_check_init_viewport(struct gl_context *ctx, GLuint width, GLuint height);
133
 
134
extern GLboolean
135
_mesa_make_current( struct gl_context *ctx, struct gl_framebuffer *drawBuffer,
136
                    struct gl_framebuffer *readBuffer );
137
 
138
extern GLboolean
139
_mesa_share_state(struct gl_context *ctx, struct gl_context *ctxToShare);
140
 
141
extern struct gl_context *
142
_mesa_get_current_context(void);
143
 
144
/*@}*/
145
 
146
extern void
147
_mesa_init_constants(struct gl_constants *consts, gl_api api);
148
 
149
extern void
150
_mesa_init_get_hash(struct gl_context *ctx);
151
 
152
extern void
153
_mesa_notifySwapBuffers(struct gl_context *gc);
154
 
155
 
156
extern struct _glapi_table *
157
_mesa_get_dispatch(struct gl_context *ctx);
158
 
159
 
160
extern GLboolean
161
_mesa_valid_to_render(struct gl_context *ctx, const char *where);
162
 
163
 
164
 
165
/** \name Miscellaneous */
166
/*@{*/
167
 
168
extern void
169
_mesa_record_error( struct gl_context *ctx, GLenum error );
170
 
171
 
172
extern void
173
_mesa_finish(struct gl_context *ctx);
174
 
175
extern void
176
_mesa_flush(struct gl_context *ctx);
177
 
178
extern void GLAPIENTRY
179
_mesa_Finish( void );
180
 
181
extern void GLAPIENTRY
182
_mesa_Flush( void );
183
 
184
/*@}*/
185
 
186
 
187
/**
188
 * Are we currently between glBegin and glEnd?
189
 * During execution, not display list compilation.
190
 */
191
static inline GLboolean
192
_mesa_inside_begin_end(const struct gl_context *ctx)
193
{
194
   return ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END;
195
}
196
 
197
 
198
/**
199
 * Are we currently between glBegin and glEnd in a display list?
200
 */
201
static inline GLboolean
202
_mesa_inside_dlist_begin_end(const struct gl_context *ctx)
203
{
204
   return ctx->Driver.CurrentSavePrimitive <= PRIM_MAX;
205
}
206
 
207
 
208
 
209
/**
210
 * \name Macros for flushing buffered rendering commands before state changes,
211
 * checking if inside glBegin/glEnd, etc.
212
 */
213
/*@{*/
214
 
215
/**
216
 * Flush vertices.
217
 *
218
 * \param ctx GL context.
219
 * \param newstate new state.
220
 *
221
 * Checks if dd_function_table::NeedFlush is marked to flush stored vertices,
222
 * and calls dd_function_table::FlushVertices if so. Marks
223
 * __struct gl_contextRec::NewState with \p newstate.
224
 */
225
#define FLUSH_VERTICES(ctx, newstate)				\
226
do {								\
227
   if (MESA_VERBOSE & VERBOSE_STATE)				\
228
      _mesa_debug(ctx, "FLUSH_VERTICES in %s\n", MESA_FUNCTION);\
229
   if (ctx->Driver.NeedFlush & FLUSH_STORED_VERTICES)		\
230
      ctx->Driver.FlushVertices(ctx, FLUSH_STORED_VERTICES);	\
231
   ctx->NewState |= newstate;					\
232
} while (0)
233
 
234
/**
235
 * Flush current state.
236
 *
237
 * \param ctx GL context.
238
 * \param newstate new state.
239
 *
240
 * Checks if dd_function_table::NeedFlush is marked to flush current state,
241
 * and calls dd_function_table::FlushVertices if so. Marks
242
 * __struct gl_contextRec::NewState with \p newstate.
243
 */
244
#define FLUSH_CURRENT(ctx, newstate)				\
245
do {								\
246
   if (MESA_VERBOSE & VERBOSE_STATE)				\
247
      _mesa_debug(ctx, "FLUSH_CURRENT in %s\n", MESA_FUNCTION);	\
248
   if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT)		\
249
      ctx->Driver.FlushVertices(ctx, FLUSH_UPDATE_CURRENT);	\
250
   ctx->NewState |= newstate;					\
251
} while (0)
252
 
253
/**
254
 * Macro to assert that the API call was made outside the
255
 * glBegin()/glEnd() pair, with return value.
256
 *
257
 * \param ctx GL context.
258
 * \param retval value to return in case the assertion fails.
259
 */
260
#define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval)		\
261
do {									\
262
   if (_mesa_inside_begin_end(ctx)) {					\
263
      _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd");	\
264
      return retval;							\
265
   }									\
266
} while (0)
267
 
268
/**
269
 * Macro to assert that the API call was made outside the
270
 * glBegin()/glEnd() pair.
271
 *
272
 * \param ctx GL context.
273
 */
274
#define ASSERT_OUTSIDE_BEGIN_END(ctx)					\
275
do {									\
276
   if (_mesa_inside_begin_end(ctx)) {					\
277
      _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd");	\
278
      return;								\
279
   }									\
280
} while (0)
281
 
282
/*@}*/
283
 
284
 
285
/**
286
 * Checks if the context is for Desktop GL (Compatibility or Core)
287
 */
288
static inline bool
289
_mesa_is_desktop_gl(const struct gl_context *ctx)
290
{
291
   return ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGL_CORE;
292
}
293
 
294
 
295
/**
296
 * Checks if the context is for any GLES version
297
 */
298
static inline bool
299
_mesa_is_gles(const struct gl_context *ctx)
300
{
301
   return ctx->API == API_OPENGLES || ctx->API == API_OPENGLES2;
302
}
303
 
304
 
305
/**
306
 * Checks if the context is for GLES 3.0 or later
307
 */
308
static inline bool
309
_mesa_is_gles3(const struct gl_context *ctx)
310
{
311
   return ctx->API == API_OPENGLES2 && ctx->Version >= 30;
312
}
313
 
314
 
315
/**
316
 * Checks if the context is for GLES 3.1 or later
317
 */
318
static inline bool
319
_mesa_is_gles31(const struct gl_context *ctx)
320
{
321
   return ctx->API == API_OPENGLES2 && ctx->Version >= 31;
322
}
323
 
324
 
325
/**
326
 * Checks if the context supports geometry shaders.
327
 */
328
static inline bool
329
_mesa_has_geometry_shaders(const struct gl_context *ctx)
330
{
331
   return _mesa_is_desktop_gl(ctx) &&
332
      (ctx->Version >= 32 || ctx->Extensions.ARB_geometry_shader4);
333
}
334
 
335
 
336
/**
337
 * Checks if the context supports compute shaders.
338
 */
339
static inline bool
340
_mesa_has_compute_shaders(const struct gl_context *ctx)
341
{
342
   return (ctx->API == API_OPENGL_CORE && ctx->Extensions.ARB_compute_shader) ||
343
      (ctx->API == API_OPENGLES2 && ctx->Version >= 31);
344
}
345
 
346
 
347
#ifdef __cplusplus
348
}
349
#endif
350
 
351
 
352
#endif /* CONTEXT_H */