| Brian Paul | 26e14d2 | 2000-01-05 04:36:17 +0000 | [diff] [blame^] | 1 | /* $Id: context.h,v 1.9 2000/01/05 04:36:17 brianp Exp $ */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * Mesa 3-D graphics library |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 5 | * Version: 3.3 |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 6 | * |
| 7 | * Copyright (C) 1999 Brian Paul All Rights Reserved. |
| 8 | * |
| 9 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 10 | * copy of this software and associated documentation files (the "Software"), |
| 11 | * to deal in the Software without restriction, including without limitation |
| 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 13 | * and/or sell copies of the Software, and to permit persons to whom the |
| 14 | * Software is furnished to do so, subject to the following conditions: |
| 15 | * |
| 16 | * The above copyright notice and this permission notice shall be included |
| 17 | * in all copies or substantial portions of the Software. |
| 18 | * |
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 22 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 23 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | */ |
| 26 | |
| 27 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 28 | #ifndef CONTEXT_H |
| 29 | #define CONTEXT_H |
| 30 | |
| 31 | |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 32 | #include "glapi.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 33 | #include "types.h" |
| 34 | |
| 35 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 36 | /* |
| 37 | * There are three Mesa datatypes which are meant to be used by device |
| 38 | * drivers: |
| 39 | * GLcontext: this contains the Mesa rendering state |
| 40 | * GLvisual: this describes the color buffer (rgb vs. ci), whether |
| 41 | * or not there's a depth buffer, stencil buffer, etc. |
| 42 | * GLframebuffer: contains pointers to the depth buffer, stencil |
| 43 | * buffer, accum buffer and alpha buffers. |
| 44 | * |
| 45 | * These types should be encapsulated by corresponding device driver |
| 46 | * datatypes. See xmesa.h and xmesaP.h for an example. |
| 47 | * |
| 48 | * In OOP terms, GLcontext, GLvisual, and GLframebuffer are base classes |
| 49 | * which the device driver must derive from. |
| 50 | * |
| 51 | * The following functions create and destroy these datatypes. |
| 52 | */ |
| 53 | |
| 54 | |
| 55 | /* |
| 56 | * Create/destroy a GLvisual. A GLvisual is like a GLX visual. It describes |
| 57 | * the colorbuffer, depth buffer, stencil buffer and accum buffer which will |
| 58 | * be used by the GL context and framebuffer. |
| 59 | */ |
| 60 | extern GLvisual *gl_create_visual( GLboolean rgbFlag, |
| 61 | GLboolean alphaFlag, |
| 62 | GLboolean dbFlag, |
| 63 | GLboolean stereoFlag, |
| 64 | GLint depthBits, |
| 65 | GLint stencilBits, |
| 66 | GLint accumBits, |
| 67 | GLint indexBits, |
| 68 | GLint redBits, |
| 69 | GLint greenBits, |
| 70 | GLint blueBits, |
| 71 | GLint alphaBits ); |
| 72 | |
| 73 | extern void gl_destroy_visual( GLvisual *vis ); |
| 74 | |
| 75 | |
| 76 | /* |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 77 | * Create/destroy a GLframebuffer. A GLframebuffer is like a GLX drawable. |
| 78 | * It bundles up the depth buffer, stencil buffer and accum buffers into a |
| 79 | * single entity. |
| 80 | */ |
| 81 | extern GLframebuffer *gl_create_framebuffer( GLvisual *visual, |
| 82 | GLboolean softwareDepth, |
| 83 | GLboolean softwareStencil, |
| 84 | GLboolean softwareAccum, |
| 85 | GLboolean softwareAlpha ); |
| 86 | |
| 87 | extern void gl_destroy_framebuffer( GLframebuffer *buffer ); |
| 88 | |
| 89 | |
| 90 | |
| 91 | /* |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 92 | * Create/destroy a GLcontext. A GLcontext is like a GLX context. It |
| 93 | * contains the rendering state. |
| 94 | */ |
| 95 | extern GLcontext *gl_create_context( GLvisual *visual, |
| 96 | GLcontext *share_list, |
| 97 | void *driver_ctx, |
| 98 | GLboolean direct); |
| 99 | |
| 100 | extern void gl_destroy_context( GLcontext *ctx ); |
| 101 | |
| 102 | /* Called by the driver after both the context and driver are fully |
| 103 | * initialized. Currently just reads the config file. |
| 104 | */ |
| 105 | extern void gl_context_initialize( GLcontext *ctx ); |
| 106 | |
| Brian Paul | 0498682 | 1999-11-19 22:26:52 +0000 | [diff] [blame] | 107 | |
| 108 | extern void gl_copy_context(const GLcontext *src, GLcontext *dst, GLuint mask); |
| 109 | |
| 110 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 111 | extern void gl_make_current( GLcontext *ctx, GLframebuffer *buffer ); |
| 112 | |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 113 | |
| Brian Paul | 3f02f90 | 1999-11-24 18:48:30 +0000 | [diff] [blame] | 114 | extern void gl_make_current2( GLcontext *ctx, GLframebuffer *drawBuffer, |
| 115 | GLframebuffer *readBuffer ); |
| 116 | |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 117 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 118 | extern GLcontext *gl_get_current_context(void); |
| 119 | |
| Brian Paul | 0498682 | 1999-11-19 22:26:52 +0000 | [diff] [blame] | 120 | |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 121 | /* |
| 122 | * Macros for fetching current context, input buffer, etc. |
| 123 | */ |
| Brian Paul | 0498682 | 1999-11-19 22:26:52 +0000 | [diff] [blame] | 124 | #ifdef THREADS |
| Brian Paul | 0498682 | 1999-11-19 22:26:52 +0000 | [diff] [blame] | 125 | |
| Brian Paul | 26e14d2 | 2000-01-05 04:36:17 +0000 | [diff] [blame^] | 126 | #define GET_CURRENT_CONTEXT(C) GLcontext *C = (GLcontext *) (_glapi_CurrentContext ? _glapi_CurrentContext : _glapi_get_current_context()) |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 127 | |
| Brian Paul | 26e14d2 | 2000-01-05 04:36:17 +0000 | [diff] [blame^] | 128 | #define GET_IMMEDIATE struct immediate *IM = ((GLcontext *) (_glapi_CurrentContext ? _glapi_CurrentContext : _glapi_get_current_context()))->input |
| 129 | |
| Brian Paul | 0498682 | 1999-11-19 22:26:52 +0000 | [diff] [blame] | 130 | #define SET_IMMEDIATE(ctx, im) \ |
| 131 | do { \ |
| 132 | ctx->input = im; \ |
| 133 | } while (0) |
| 134 | |
| Brian Paul | 0498682 | 1999-11-19 22:26:52 +0000 | [diff] [blame] | 135 | #else |
| Brian Paul | 0498682 | 1999-11-19 22:26:52 +0000 | [diff] [blame] | 136 | |
| Brian Paul | c633693 | 1999-12-17 12:21:38 +0000 | [diff] [blame] | 137 | extern struct immediate *CURRENT_INPUT; |
| Brian Paul | 26e14d2 | 2000-01-05 04:36:17 +0000 | [diff] [blame^] | 138 | |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 139 | #define GET_CURRENT_CONTEXT(C) GLcontext *C = _glapi_CurrentContext |
| Brian Paul | 26e14d2 | 2000-01-05 04:36:17 +0000 | [diff] [blame^] | 140 | |
| Brian Paul | 0498682 | 1999-11-19 22:26:52 +0000 | [diff] [blame] | 141 | #define GET_IMMEDIATE struct immediate *IM = CURRENT_INPUT |
| Brian Paul | 26e14d2 | 2000-01-05 04:36:17 +0000 | [diff] [blame^] | 142 | |
| Brian Paul | 0498682 | 1999-11-19 22:26:52 +0000 | [diff] [blame] | 143 | #define SET_IMMEDIATE(ctx, im) \ |
| 144 | do { \ |
| 145 | ctx->input = im; \ |
| 146 | CURRENT_INPUT = im; \ |
| 147 | } while (0) |
| 148 | |
| Brian Paul | 0498682 | 1999-11-19 22:26:52 +0000 | [diff] [blame] | 149 | #endif |
| 150 | |
| 151 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 152 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 153 | extern void |
| 154 | _mesa_swapbuffers(GLcontext *ctx); |
| 155 | |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 156 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 157 | extern struct _glapi_table * |
| 158 | _mesa_get_dispatch(GLcontext *ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 159 | |
| 160 | |
| 161 | |
| 162 | /* |
| 163 | * GL_MESA_resize_buffers extension |
| 164 | */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 165 | extern void _mesa_ResizeBuffersMESA( void ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 166 | |
| 167 | |
| 168 | |
| 169 | /* |
| 170 | * Miscellaneous |
| 171 | */ |
| 172 | |
| 173 | extern void gl_problem( const GLcontext *ctx, const char *s ); |
| 174 | |
| 175 | extern void gl_warning( const GLcontext *ctx, const char *s ); |
| 176 | |
| 177 | extern void gl_error( GLcontext *ctx, GLenum error, const char *s ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 178 | |
| Brian Paul | 0003778 | 1999-12-17 14:52:35 +0000 | [diff] [blame] | 179 | extern void gl_compile_error( GLcontext *ctx, GLenum error, const char *s ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 180 | |
| 181 | extern void gl_update_state( GLcontext *ctx ); |
| 182 | |
| 183 | |
| 184 | /* for debugging */ |
| 185 | extern void gl_print_state( const char *msg, GLuint state ); |
| 186 | |
| 187 | /* for debugging */ |
| 188 | extern void gl_print_enable_flags( const char *msg, GLuint flags ); |
| 189 | |
| 190 | |
| 191 | #ifdef PROFILE |
| 192 | extern GLdouble gl_time( void ); |
| 193 | #endif |
| 194 | |
| 195 | |
| 196 | #endif |