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