context.h revision cdc920a0
1/*
2 * Mesa 3-D graphics library
3 * Version:  6.5.1
4 *
5 * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR 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 * - GLcontext: this contains the Mesa rendering state
33 * - GLvisual:  this describes the color buffer (RGB vs. ci), whether or not
34 *   there's a depth buffer, stencil buffer, etc.
35 * - GLframebuffer:  contains pointers to the depth buffer, stencil buffer,
36 *   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, GLcontext, GLvisual, and GLframebuffer are base classes
42 * 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
56struct _glapi_table;
57
58
59/** \name Visual-related functions */
60/*@{*/
61
62extern GLvisual *
63_mesa_create_visual( GLboolean dbFlag,
64                     GLboolean stereoFlag,
65                     GLint redBits,
66                     GLint greenBits,
67                     GLint blueBits,
68                     GLint alphaBits,
69                     GLint depthBits,
70                     GLint stencilBits,
71                     GLint accumRedBits,
72                     GLint accumGreenBits,
73                     GLint accumBlueBits,
74                     GLint accumAlphaBits,
75                     GLint numSamples );
76
77extern GLboolean
78_mesa_initialize_visual( GLvisual *v,
79                         GLboolean dbFlag,
80                         GLboolean stereoFlag,
81                         GLint redBits,
82                         GLint greenBits,
83                         GLint blueBits,
84                         GLint alphaBits,
85                         GLint depthBits,
86                         GLint stencilBits,
87                         GLint accumRedBits,
88                         GLint accumGreenBits,
89                         GLint accumBlueBits,
90                         GLint accumAlphaBits,
91                         GLint numSamples );
92
93extern void
94_mesa_destroy_visual( GLvisual *vis );
95
96/*@}*/
97
98
99/** \name Context-related functions */
100/*@{*/
101
102extern GLcontext *
103_mesa_create_context( const GLvisual *visual,
104                      GLcontext *share_list,
105                      const struct dd_function_table *driverFunctions,
106                      void *driverContext );
107
108extern GLboolean
109_mesa_initialize_context( GLcontext *ctx,
110                          const GLvisual *visual,
111                          GLcontext *share_list,
112                          const struct dd_function_table *driverFunctions,
113                          void *driverContext );
114
115extern void
116_mesa_initialize_context_extra(GLcontext *ctx);
117
118extern void
119_mesa_free_context_data( GLcontext *ctx );
120
121extern void
122_mesa_destroy_context( GLcontext *ctx );
123
124
125extern void
126_mesa_copy_context(const GLcontext *src, GLcontext *dst, GLuint mask);
127
128
129extern void
130_mesa_check_init_viewport(GLcontext *ctx, GLuint width, GLuint height);
131
132extern GLboolean
133_mesa_make_current( GLcontext *ctx, GLframebuffer *drawBuffer,
134                    GLframebuffer *readBuffer );
135
136extern GLboolean
137_mesa_share_state(GLcontext *ctx, GLcontext *ctxToShare);
138
139extern GLcontext *
140_mesa_get_current_context(void);
141
142/*@}*/
143
144
145extern void
146_mesa_notifySwapBuffers(__GLcontext *gc);
147
148
149extern struct _glapi_table *
150_mesa_get_dispatch(GLcontext *ctx);
151
152
153void
154_mesa_set_mvp_with_dp4( GLcontext *ctx,
155                        GLboolean flag );
156
157
158extern GLboolean
159_mesa_valid_to_render(GLcontext *ctx, const char *where);
160
161
162
163/** \name Miscellaneous */
164/*@{*/
165
166extern void
167_mesa_record_error( GLcontext *ctx, GLenum error );
168
169
170extern void
171_mesa_finish(GLcontext *ctx);
172
173extern void
174_mesa_flush(GLcontext *ctx);
175
176
177extern void GLAPIENTRY
178_mesa_Finish( void );
179
180extern void GLAPIENTRY
181_mesa_Flush( void );
182
183/*@}*/
184
185
186/**
187 * \name Macros for flushing buffered rendering commands before state changes,
188 * checking if inside glBegin/glEnd, etc.
189 */
190/*@{*/
191
192/**
193 * Flush vertices.
194 *
195 * \param ctx GL context.
196 * \param newstate new state.
197 *
198 * Checks if dd_function_table::NeedFlush is marked to flush stored vertices,
199 * and calls dd_function_table::FlushVertices if so. Marks
200 * __GLcontextRec::NewState with \p newstate.
201 */
202#define FLUSH_VERTICES(ctx, newstate)				\
203do {								\
204   if (MESA_VERBOSE & VERBOSE_STATE)				\
205      _mesa_debug(ctx, "FLUSH_VERTICES in %s\n", MESA_FUNCTION);\
206   if (ctx->Driver.NeedFlush & FLUSH_STORED_VERTICES)		\
207      ctx->Driver.FlushVertices(ctx, FLUSH_STORED_VERTICES);	\
208   ctx->NewState |= newstate;					\
209} while (0)
210
211/**
212 * Flush current state.
213 *
214 * \param ctx GL context.
215 * \param newstate new state.
216 *
217 * Checks if dd_function_table::NeedFlush is marked to flush current state,
218 * and calls dd_function_table::FlushVertices if so. Marks
219 * __GLcontextRec::NewState with \p newstate.
220 */
221#define FLUSH_CURRENT(ctx, newstate)				\
222do {								\
223   if (MESA_VERBOSE & VERBOSE_STATE)				\
224      _mesa_debug(ctx, "FLUSH_CURRENT in %s\n", MESA_FUNCTION);	\
225   if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT)		\
226      ctx->Driver.FlushVertices(ctx, FLUSH_UPDATE_CURRENT);	\
227   ctx->NewState |= newstate;					\
228} while (0)
229
230/**
231 * Macro to assert that the API call was made outside the
232 * glBegin()/glEnd() pair, with return value.
233 *
234 * \param ctx GL context.
235 * \param retval value to return value in case the assertion fails.
236 */
237#define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval)		\
238do {									\
239   if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) {	\
240      _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd");	\
241      return retval;							\
242   }									\
243} while (0)
244
245/**
246 * Macro to assert that the API call was made outside the
247 * glBegin()/glEnd() pair.
248 *
249 * \param ctx GL context.
250 */
251#define ASSERT_OUTSIDE_BEGIN_END(ctx)					\
252do {									\
253   if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) {	\
254      _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd");	\
255      return;								\
256   }									\
257} while (0)
258
259/**
260 * Macro to assert that the API call was made outside the
261 * glBegin()/glEnd() pair and flush the vertices.
262 *
263 * \param ctx GL context.
264 */
265#define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx)				\
266do {									\
267   ASSERT_OUTSIDE_BEGIN_END(ctx);					\
268   FLUSH_VERTICES(ctx, 0);						\
269} while (0)
270
271/**
272 * Macro to assert that the API call was made outside the
273 * glBegin()/glEnd() pair and flush the vertices, with return value.
274 *
275 * \param ctx GL context.
276 * \param retval value to return value in case the assertion fails.
277 */
278#define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, retval)	\
279do {									\
280   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval);			\
281   FLUSH_VERTICES(ctx, 0);						\
282} while (0)
283
284/*@}*/
285
286
287
288/**
289 * Is the secondary color needed?
290 */
291#define NEED_SECONDARY_COLOR(CTX)					\
292   (((CTX)->Light.Enabled &&						\
293     (CTX)->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)	\
294    || (CTX)->Fog.ColorSumEnabled					\
295    || ((CTX)->VertexProgram._Current &&				\
296        ((CTX)->VertexProgram._Current != (CTX)->VertexProgram._TnlProgram) &&    \
297        ((CTX)->VertexProgram._Current->Base.InputsRead & VERT_BIT_COLOR1)) \
298    || ((CTX)->FragmentProgram._Current &&				\
299        ((CTX)->FragmentProgram._Current != (CTX)->FragmentProgram._TexEnvProgram) &&  \
300        ((CTX)->FragmentProgram._Current->Base.InputsRead & FRAG_BIT_COL1)) \
301   )
302
303
304/**
305 * Is RGBA LogicOp enabled?
306 */
307#define RGBA_LOGICOP_ENABLED(CTX) \
308  ((CTX)->Color.ColorLogicOpEnabled || \
309   ((CTX)->Color.BlendEnabled && (CTX)->Color.BlendEquationRGB == GL_LOGIC_OP))
310
311
312#endif /* CONTEXT_H */
313