blob: c31f524fccde62d75b83196fc6953106dd21f75a [file] [log] [blame]
Brian Paul26e14d22000-01-05 04:36:17 +00001/* $Id: context.h,v 1.9 2000/01/05 04:36:17 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
Brian Paul00037781999-12-17 14:52:35 +000032#include "glapi.h"
jtgafb833d1999-08-19 00:55:39 +000033#include "types.h"
34
35
jtgafb833d1999-08-19 00:55:39 +000036/*
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 */
60extern 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
73extern void gl_destroy_visual( GLvisual *vis );
74
75
76/*
Brian Paul00037781999-12-17 14:52:35 +000077 * 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 */
81extern GLframebuffer *gl_create_framebuffer( GLvisual *visual,
82 GLboolean softwareDepth,
83 GLboolean softwareStencil,
84 GLboolean softwareAccum,
85 GLboolean softwareAlpha );
86
87extern void gl_destroy_framebuffer( GLframebuffer *buffer );
88
89
90
91/*
jtgafb833d1999-08-19 00:55:39 +000092 * Create/destroy a GLcontext. A GLcontext is like a GLX context. It
93 * contains the rendering state.
94 */
95extern GLcontext *gl_create_context( GLvisual *visual,
96 GLcontext *share_list,
97 void *driver_ctx,
98 GLboolean direct);
99
100extern 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 */
105extern void gl_context_initialize( GLcontext *ctx );
106
Brian Paul04986821999-11-19 22:26:52 +0000107
108extern void gl_copy_context(const GLcontext *src, GLcontext *dst, GLuint mask);
109
110
jtgafb833d1999-08-19 00:55:39 +0000111extern void gl_make_current( GLcontext *ctx, GLframebuffer *buffer );
112
Brian Paul00037781999-12-17 14:52:35 +0000113
Brian Paul3f02f901999-11-24 18:48:30 +0000114extern void gl_make_current2( GLcontext *ctx, GLframebuffer *drawBuffer,
115 GLframebuffer *readBuffer );
116
Brian Paul00037781999-12-17 14:52:35 +0000117
jtgafb833d1999-08-19 00:55:39 +0000118extern GLcontext *gl_get_current_context(void);
119
Brian Paul04986821999-11-19 22:26:52 +0000120
Brian Paul00037781999-12-17 14:52:35 +0000121/*
122 * Macros for fetching current context, input buffer, etc.
123 */
Brian Paul04986821999-11-19 22:26:52 +0000124#ifdef THREADS
Brian Paul04986821999-11-19 22:26:52 +0000125
Brian Paul26e14d22000-01-05 04:36:17 +0000126#define GET_CURRENT_CONTEXT(C) GLcontext *C = (GLcontext *) (_glapi_CurrentContext ? _glapi_CurrentContext : _glapi_get_current_context())
Brian Paul00037781999-12-17 14:52:35 +0000127
Brian Paul26e14d22000-01-05 04:36:17 +0000128#define GET_IMMEDIATE struct immediate *IM = ((GLcontext *) (_glapi_CurrentContext ? _glapi_CurrentContext : _glapi_get_current_context()))->input
129
Brian Paul04986821999-11-19 22:26:52 +0000130#define SET_IMMEDIATE(ctx, im) \
131do { \
132 ctx->input = im; \
133} while (0)
134
Brian Paul04986821999-11-19 22:26:52 +0000135#else
Brian Paul04986821999-11-19 22:26:52 +0000136
Brian Paulc6336931999-12-17 12:21:38 +0000137extern struct immediate *CURRENT_INPUT;
Brian Paul26e14d22000-01-05 04:36:17 +0000138
Brian Paul00037781999-12-17 14:52:35 +0000139#define GET_CURRENT_CONTEXT(C) GLcontext *C = _glapi_CurrentContext
Brian Paul26e14d22000-01-05 04:36:17 +0000140
Brian Paul04986821999-11-19 22:26:52 +0000141#define GET_IMMEDIATE struct immediate *IM = CURRENT_INPUT
Brian Paul26e14d22000-01-05 04:36:17 +0000142
Brian Paul04986821999-11-19 22:26:52 +0000143#define SET_IMMEDIATE(ctx, im) \
144do { \
145 ctx->input = im; \
146 CURRENT_INPUT = im; \
147} while (0)
148
Brian Paul04986821999-11-19 22:26:52 +0000149#endif
150
151
jtgafb833d1999-08-19 00:55:39 +0000152
Brian Paulfbd8f211999-11-11 01:22:25 +0000153extern void
154_mesa_swapbuffers(GLcontext *ctx);
155
Brian Paul00037781999-12-17 14:52:35 +0000156
Brian Paulfbd8f211999-11-11 01:22:25 +0000157extern struct _glapi_table *
158_mesa_get_dispatch(GLcontext *ctx);
jtgafb833d1999-08-19 00:55:39 +0000159
160
161
162/*
163 * GL_MESA_resize_buffers extension
164 */
Brian Paulfbd8f211999-11-11 01:22:25 +0000165extern void _mesa_ResizeBuffersMESA( void );
jtgafb833d1999-08-19 00:55:39 +0000166
167
168
169/*
170 * Miscellaneous
171 */
172
173extern void gl_problem( const GLcontext *ctx, const char *s );
174
175extern void gl_warning( const GLcontext *ctx, const char *s );
176
177extern void gl_error( GLcontext *ctx, GLenum error, const char *s );
jtgafb833d1999-08-19 00:55:39 +0000178
Brian Paul00037781999-12-17 14:52:35 +0000179extern void gl_compile_error( GLcontext *ctx, GLenum error, const char *s );
jtgafb833d1999-08-19 00:55:39 +0000180
181extern void gl_update_state( GLcontext *ctx );
182
183
184/* for debugging */
185extern void gl_print_state( const char *msg, GLuint state );
186
187/* for debugging */
188extern void gl_print_enable_flags( const char *msg, GLuint flags );
189
190
191#ifdef PROFILE
192extern GLdouble gl_time( void );
193#endif
194
195
196#endif