context.h revision 3464ebd5
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 * - 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 56struct _glapi_table; 57 58 59/** \name Visual-related functions */ 60/*@{*/ 61 62extern struct gl_config * 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( struct gl_config *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( struct gl_config *vis ); 95 96/*@}*/ 97 98 99/** \name Context-related functions */ 100/*@{*/ 101 102extern GLboolean 103_mesa_initialize_context( struct gl_context *ctx, 104 gl_api api, 105 const struct gl_config *visual, 106 struct gl_context *share_list, 107 const struct dd_function_table *driverFunctions, 108 void *driverContext ); 109 110extern struct gl_context * 111_mesa_create_context(gl_api api, 112 const struct gl_config *visual, 113 struct gl_context *share_list, 114 const struct dd_function_table *driverFunctions, 115 void *driverContext); 116 117extern void 118_mesa_free_context_data( struct gl_context *ctx ); 119 120extern void 121_mesa_destroy_context( struct gl_context *ctx ); 122 123 124extern void 125_mesa_copy_context(const struct gl_context *src, struct gl_context *dst, GLuint mask); 126 127 128extern void 129_mesa_check_init_viewport(struct gl_context *ctx, GLuint width, GLuint height); 130 131extern GLboolean 132_mesa_make_current( struct gl_context *ctx, struct gl_framebuffer *drawBuffer, 133 struct gl_framebuffer *readBuffer ); 134 135extern GLboolean 136_mesa_share_state(struct gl_context *ctx, struct gl_context *ctxToShare); 137 138extern struct gl_context * 139_mesa_get_current_context(void); 140 141/*@}*/ 142 143extern void 144_mesa_init_get_hash(struct gl_context *ctx); 145 146extern void 147_mesa_notifySwapBuffers(struct gl_context *gc); 148 149 150extern struct _glapi_table * 151_mesa_get_dispatch(struct gl_context *ctx); 152 153 154void 155_mesa_set_mvp_with_dp4( struct gl_context *ctx, 156 GLboolean flag ); 157 158 159extern GLboolean 160_mesa_valid_to_render(struct gl_context *ctx, const char *where); 161 162 163 164/** \name Miscellaneous */ 165/*@{*/ 166 167extern void 168_mesa_record_error( struct gl_context *ctx, GLenum error ); 169 170 171extern void 172_mesa_finish(struct gl_context *ctx); 173 174extern void 175_mesa_flush(struct gl_context *ctx); 176 177 178extern void GLAPIENTRY 179_mesa_Finish( void ); 180 181extern void GLAPIENTRY 182_mesa_Flush( void ); 183 184/*@}*/ 185 186 187/** 188 * \name Macros for flushing buffered rendering commands before state changes, 189 * checking if inside glBegin/glEnd, etc. 190 */ 191/*@{*/ 192 193/** 194 * Flush vertices. 195 * 196 * \param ctx GL context. 197 * \param newstate new state. 198 * 199 * Checks if dd_function_table::NeedFlush is marked to flush stored vertices, 200 * and calls dd_function_table::FlushVertices if so. Marks 201 * __struct gl_contextRec::NewState with \p newstate. 202 */ 203#define FLUSH_VERTICES(ctx, newstate) \ 204do { \ 205 if (MESA_VERBOSE & VERBOSE_STATE) \ 206 _mesa_debug(ctx, "FLUSH_VERTICES in %s\n", MESA_FUNCTION);\ 207 if (ctx->Driver.NeedFlush & FLUSH_STORED_VERTICES) \ 208 ctx->Driver.FlushVertices(ctx, FLUSH_STORED_VERTICES); \ 209 ctx->NewState |= newstate; \ 210} while (0) 211 212/** 213 * Flush current state. 214 * 215 * \param ctx GL context. 216 * \param newstate new state. 217 * 218 * Checks if dd_function_table::NeedFlush is marked to flush current state, 219 * and calls dd_function_table::FlushVertices if so. Marks 220 * __struct gl_contextRec::NewState with \p newstate. 221 */ 222#define FLUSH_CURRENT(ctx, newstate) \ 223do { \ 224 if (MESA_VERBOSE & VERBOSE_STATE) \ 225 _mesa_debug(ctx, "FLUSH_CURRENT in %s\n", MESA_FUNCTION); \ 226 if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) \ 227 ctx->Driver.FlushVertices(ctx, FLUSH_UPDATE_CURRENT); \ 228 ctx->NewState |= newstate; \ 229} while (0) 230 231/** 232 * Macro to assert that the API call was made outside the 233 * glBegin()/glEnd() pair, with return value. 234 * 235 * \param ctx GL context. 236 * \param retval value to return value in case the assertion fails. 237 */ 238#define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval) \ 239do { \ 240 if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) { \ 241 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \ 242 return retval; \ 243 } \ 244} while (0) 245 246/** 247 * Macro to assert that the API call was made outside the 248 * glBegin()/glEnd() pair. 249 * 250 * \param ctx GL context. 251 */ 252#define ASSERT_OUTSIDE_BEGIN_END(ctx) \ 253do { \ 254 if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) { \ 255 _mesa_error(ctx, GL_INVALID_OPERATION, "Inside glBegin/glEnd"); \ 256 return; \ 257 } \ 258} while (0) 259 260/** 261 * Macro to assert that the API call was made outside the 262 * glBegin()/glEnd() pair and flush the vertices. 263 * 264 * \param ctx GL context. 265 */ 266#define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx) \ 267do { \ 268 ASSERT_OUTSIDE_BEGIN_END(ctx); \ 269 FLUSH_VERTICES(ctx, 0); \ 270} while (0) 271 272/** 273 * Macro to assert that the API call was made outside the 274 * glBegin()/glEnd() pair and flush the vertices, with return value. 275 * 276 * \param ctx GL context. 277 * \param retval value to return value in case the assertion fails. 278 */ 279#define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, retval) \ 280do { \ 281 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, retval); \ 282 FLUSH_VERTICES(ctx, 0); \ 283} while (0) 284 285/*@}*/ 286 287 288 289#endif /* CONTEXT_H */ 290