context.h revision c1f859d4
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 "glapi/glapi.h"
53#include "imports.h"
54#include "mtypes.h"
55
56
57/** \name Visual-related functions */
58/*@{*/
59
60extern GLvisual *
61_mesa_create_visual( GLboolean rgbFlag,
62                     GLboolean dbFlag,
63                     GLboolean stereoFlag,
64                     GLint redBits,
65                     GLint greenBits,
66                     GLint blueBits,
67                     GLint alphaBits,
68                     GLint indexBits,
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 rgbFlag,
80                         GLboolean dbFlag,
81                         GLboolean stereoFlag,
82                         GLint redBits,
83                         GLint greenBits,
84                         GLint blueBits,
85                         GLint alphaBits,
86                         GLint indexBits,
87                         GLint depthBits,
88                         GLint stencilBits,
89                         GLint accumRedBits,
90                         GLint accumGreenBits,
91                         GLint accumBlueBits,
92                         GLint accumAlphaBits,
93                         GLint numSamples );
94
95extern void
96_mesa_destroy_visual( GLvisual *vis );
97
98/*@}*/
99
100
101/** \name Context-related functions */
102/*@{*/
103
104extern GLcontext *
105_mesa_create_context( const GLvisual *visual,
106                      GLcontext *share_list,
107                      const struct dd_function_table *driverFunctions,
108                      void *driverContext );
109
110extern GLboolean
111_mesa_initialize_context( GLcontext *ctx,
112                          const GLvisual *visual,
113                          GLcontext *share_list,
114                          const struct dd_function_table *driverFunctions,
115                          void *driverContext );
116
117extern void
118_mesa_initialize_context_extra(GLcontext *ctx);
119
120extern void
121_mesa_free_context_data( GLcontext *ctx );
122
123extern void
124_mesa_destroy_context( GLcontext *ctx );
125
126
127extern void
128_mesa_copy_context(const GLcontext *src, GLcontext *dst, GLuint mask);
129
130
131extern void
132_mesa_make_current( GLcontext *ctx, GLframebuffer *drawBuffer,
133                    GLframebuffer *readBuffer );
134
135extern GLboolean
136_mesa_share_state(GLcontext *ctx, GLcontext *ctxToShare);
137
138extern GLcontext *
139_mesa_get_current_context(void);
140
141/*@}*/
142
143
144extern void
145_mesa_notifySwapBuffers(__GLcontext *gc);
146
147
148extern struct _glapi_table *
149_mesa_get_dispatch(GLcontext *ctx);
150
151
152
153/** \name Miscellaneous */
154/*@{*/
155
156extern void
157_mesa_record_error( GLcontext *ctx, GLenum error );
158
159extern void GLAPIENTRY
160_mesa_Finish( void );
161
162extern void GLAPIENTRY
163_mesa_Flush( void );
164
165/*@}*/
166
167
168
169/**
170 * \name Macros for flushing buffered rendering commands before state changes,
171 * checking if inside glBegin/glEnd, etc.
172 */
173/*@{*/
174
175/**
176 * Flush vertices.
177 *
178 * \param ctx GL context.
179 * \param newstate new state.
180 *
181 * Checks if dd_function_table::NeedFlush is marked to flush stored vertices,
182 * and calls dd_function_table::FlushVertices if so. Marks
183 * __GLcontextRec::NewState with \p newstate.
184 */
185#define FLUSH_VERTICES(ctx, newstate)				\
186do {								\
187   if (MESA_VERBOSE & VERBOSE_STATE)				\
188      _mesa_debug(ctx, "FLUSH_VERTICES in %s\n", MESA_FUNCTION);\
189   if (ctx->Driver.NeedFlush & FLUSH_STORED_VERTICES)		\
190      ctx->Driver.FlushVertices(ctx, FLUSH_STORED_VERTICES);	\
191   ctx->NewState |= newstate;					\
192} while (0)
193
194/**
195 * Flush current state.
196 *
197 * \param ctx GL context.
198 * \param newstate new state.
199 *
200 * Checks if dd_function_table::NeedFlush is marked to flush current state,
201 * and calls dd_function_table::FlushVertices if so. Marks
202 * __GLcontextRec::NewState with \p newstate.
203 */
204#define FLUSH_CURRENT(ctx, newstate)				\
205do {								\
206   if (MESA_VERBOSE & VERBOSE_STATE)				\
207      _mesa_debug(ctx, "FLUSH_CURRENT in %s\n", MESA_FUNCTION);	\
208   if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT)		\
209      ctx->Driver.FlushVertices(ctx, FLUSH_UPDATE_CURRENT);	\
210   ctx->NewState |= newstate;					\
211} while (0)
212
213/**
214 * Macro to assert that the API call was made outside the
215 * glBegin()/glEnd() pair, with return value.
216 *
217 * \param ctx GL context.
218 * \param retval value to return value in case the assertion fails.
219 */
220#define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval)		\
221do {									\
222   if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) {	\
223      _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd");	\
224      return retval;							\
225   }									\
226} while (0)
227
228/**
229 * Macro to assert that the API call was made outside the
230 * glBegin()/glEnd() pair.
231 *
232 * \param ctx GL context.
233 */
234#define ASSERT_OUTSIDE_BEGIN_END(ctx)					\
235do {									\
236   if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) {	\
237      _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd");	\
238      return;								\
239   }									\
240} while (0)
241
242/**
243 * Macro to assert that the API call was made outside the
244 * glBegin()/glEnd() pair and flush the vertices.
245 *
246 * \param ctx GL context.
247 */
248#define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx)				\
249do {									\
250   ASSERT_OUTSIDE_BEGIN_END(ctx);					\
251   FLUSH_VERTICES(ctx, 0);						\
252} while (0)
253
254/**
255 * Macro to assert that the API call was made outside the
256 * glBegin()/glEnd() pair and flush the vertices, with return value.
257 *
258 * \param ctx GL context.
259 * \param retval value to return value in case the assertion fails.
260 */
261#define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, retval)	\
262do {									\
263   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval);			\
264   FLUSH_VERTICES(ctx, 0);						\
265} while (0)
266
267/*@}*/
268
269
270
271/**
272 * Is the secondary color needed?
273 */
274#define NEED_SECONDARY_COLOR(CTX)					\
275   (((CTX)->Light.Enabled &&						\
276     (CTX)->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)	\
277    || (CTX)->Fog.ColorSumEnabled					\
278    || ((CTX)->VertexProgram._Current &&				\
279        ((CTX)->VertexProgram._Current != (CTX)->VertexProgram._TnlProgram) &&    \
280        ((CTX)->VertexProgram._Current->Base.InputsRead & VERT_BIT_COLOR1)) \
281    || ((CTX)->FragmentProgram._Current &&				\
282        ((CTX)->FragmentProgram._Current != (CTX)->FragmentProgram._TexEnvProgram) &&  \
283        ((CTX)->FragmentProgram._Current->Base.InputsRead & FRAG_BIT_COL1)) \
284   )
285
286
287/**
288 * Is RGBA LogicOp enabled?
289 */
290#define RGBA_LOGICOP_ENABLED(CTX) \
291  ((CTX)->Color.ColorLogicOpEnabled || \
292   ((CTX)->Color.BlendEnabled && (CTX)->Color.BlendEquationRGB == GL_LOGIC_OP))
293
294
295#endif /* CONTEXT_H */
296