| Brian Paul | 0498682 | 1999-11-19 22:26:52 +0000 | [diff] [blame^] | 1 | /* $Id: context.h,v 1.3 1999/11/19 22:26:53 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 | |
| 32 | #include "types.h" |
| 33 | |
| 34 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 35 | /* |
| 36 | * There are three Mesa datatypes which are meant to be used by device |
| 37 | * drivers: |
| 38 | * GLcontext: this contains the Mesa rendering state |
| 39 | * GLvisual: this describes the color buffer (rgb vs. ci), whether |
| 40 | * or not there's a depth buffer, stencil buffer, etc. |
| 41 | * GLframebuffer: contains pointers to the depth buffer, stencil |
| 42 | * buffer, accum buffer and alpha buffers. |
| 43 | * |
| 44 | * These types should be encapsulated by corresponding device driver |
| 45 | * datatypes. See xmesa.h and xmesaP.h for an example. |
| 46 | * |
| 47 | * In OOP terms, GLcontext, GLvisual, and GLframebuffer are base classes |
| 48 | * which the device driver must derive from. |
| 49 | * |
| 50 | * The following functions create and destroy these datatypes. |
| 51 | */ |
| 52 | |
| 53 | |
| 54 | /* |
| 55 | * Create/destroy a GLvisual. A GLvisual is like a GLX visual. It describes |
| 56 | * the colorbuffer, depth buffer, stencil buffer and accum buffer which will |
| 57 | * be used by the GL context and framebuffer. |
| 58 | */ |
| 59 | extern GLvisual *gl_create_visual( GLboolean rgbFlag, |
| 60 | GLboolean alphaFlag, |
| 61 | GLboolean dbFlag, |
| 62 | GLboolean stereoFlag, |
| 63 | GLint depthBits, |
| 64 | GLint stencilBits, |
| 65 | GLint accumBits, |
| 66 | GLint indexBits, |
| 67 | GLint redBits, |
| 68 | GLint greenBits, |
| 69 | GLint blueBits, |
| 70 | GLint alphaBits ); |
| 71 | |
| 72 | extern void gl_destroy_visual( GLvisual *vis ); |
| 73 | |
| 74 | |
| 75 | /* |
| 76 | * Create/destroy a GLcontext. A GLcontext is like a GLX context. It |
| 77 | * contains the rendering state. |
| 78 | */ |
| 79 | extern GLcontext *gl_create_context( GLvisual *visual, |
| 80 | GLcontext *share_list, |
| 81 | void *driver_ctx, |
| 82 | GLboolean direct); |
| 83 | |
| 84 | extern void gl_destroy_context( GLcontext *ctx ); |
| 85 | |
| 86 | /* Called by the driver after both the context and driver are fully |
| 87 | * initialized. Currently just reads the config file. |
| 88 | */ |
| 89 | extern void gl_context_initialize( GLcontext *ctx ); |
| 90 | |
| Brian Paul | 0498682 | 1999-11-19 22:26:52 +0000 | [diff] [blame^] | 91 | |
| 92 | extern void gl_copy_context(const GLcontext *src, GLcontext *dst, GLuint mask); |
| 93 | |
| 94 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 95 | /* |
| 96 | * Create/destroy a GLframebuffer. A GLframebuffer is like a GLX drawable. |
| 97 | * It bundles up the depth buffer, stencil buffer and accum buffers into a |
| 98 | * single entity. |
| 99 | */ |
| 100 | extern GLframebuffer *gl_create_framebuffer( GLvisual *visual ); |
| 101 | |
| 102 | extern void gl_destroy_framebuffer( GLframebuffer *buffer ); |
| 103 | |
| 104 | |
| 105 | |
| 106 | extern void gl_make_current( GLcontext *ctx, GLframebuffer *buffer ); |
| 107 | |
| 108 | extern GLcontext *gl_get_current_context(void); |
| 109 | |
| Brian Paul | 0498682 | 1999-11-19 22:26:52 +0000 | [diff] [blame^] | 110 | |
| 111 | #ifdef THREADS |
| 112 | /* |
| 113 | * A seperate GLcontext for each thread |
| 114 | */ |
| 115 | |
| 116 | #define GET_CURRENT_CONTEXT(C) GLcontext *C = gl_get_current_context() |
| 117 | |
| 118 | #define GET_IMMEDIATE struct immediate *IM = (gl_get_current_context())->input; |
| 119 | #define SET_IMMEDIATE(ctx, im) \ |
| 120 | do { \ |
| 121 | ctx->input = im; \ |
| 122 | } while (0) |
| 123 | |
| 124 | |
| 125 | #else |
| 126 | /* |
| 127 | * All threads use same pointer to current context. |
| 128 | */ |
| 129 | extern GLcontext *_mesa_current_context; |
| 130 | extern struct immediate *CURRENT_INPUT; |
| 131 | #define GET_CURRENT_CONTEXT(C) GLcontext *C = _mesa_current_context |
| 132 | |
| 133 | #define GET_IMMEDIATE struct immediate *IM = CURRENT_INPUT |
| 134 | #define SET_IMMEDIATE(ctx, im) \ |
| 135 | do { \ |
| 136 | ctx->input = im; \ |
| 137 | CURRENT_INPUT = im; \ |
| 138 | } while (0) |
| 139 | |
| 140 | |
| 141 | #endif |
| 142 | |
| 143 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 144 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 145 | extern void |
| 146 | _mesa_swapbuffers(GLcontext *ctx); |
| 147 | |
| 148 | extern struct _glapi_table * |
| 149 | _mesa_get_dispatch(GLcontext *ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 150 | |
| 151 | |
| 152 | |
| 153 | /* |
| 154 | * GL_MESA_resize_buffers extension |
| 155 | */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 156 | extern void _mesa_ResizeBuffersMESA( void ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 157 | |
| 158 | |
| 159 | |
| 160 | /* |
| 161 | * Miscellaneous |
| 162 | */ |
| 163 | |
| 164 | extern void gl_problem( const GLcontext *ctx, const char *s ); |
| 165 | |
| 166 | extern void gl_warning( const GLcontext *ctx, const char *s ); |
| 167 | |
| 168 | extern void gl_error( GLcontext *ctx, GLenum error, const char *s ); |
| 169 | extern void gl_compile_error( GLcontext *ctx, GLenum error, const char *s ); |
| 170 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 171 | |
| 172 | extern void gl_update_state( GLcontext *ctx ); |
| 173 | |
| 174 | |
| 175 | /* for debugging */ |
| 176 | extern void gl_print_state( const char *msg, GLuint state ); |
| 177 | |
| 178 | /* for debugging */ |
| 179 | extern void gl_print_enable_flags( const char *msg, GLuint flags ); |
| 180 | |
| 181 | |
| 182 | #ifdef PROFILE |
| 183 | extern GLdouble gl_time( void ); |
| 184 | #endif |
| 185 | |
| 186 | |
| 187 | #endif |