1 | /* $Id: context.c,v 1.5 2001-10-10 22:34:36 phaller Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Mesa 3-D graphics library
|
---|
5 | * Version: 3.3
|
---|
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 |
|
---|
28 | #ifdef PC_HEADER
|
---|
29 | #include "all.h"
|
---|
30 | #else
|
---|
31 | //#include "glheader.h"
|
---|
32 | #include "accum.h"
|
---|
33 | #include "mem.h"
|
---|
34 | #include "alphabuf.h"
|
---|
35 | #include "glapi.h"
|
---|
36 | #include "glapinoop.h"
|
---|
37 | #include "glthread.h"
|
---|
38 | #include "clip.h"
|
---|
39 | #include "context.h"
|
---|
40 | #include "cva.h"
|
---|
41 | #include "depth.h"
|
---|
42 | #include "dlist.h"
|
---|
43 | #include "eval.h"
|
---|
44 | #include "enums.h"
|
---|
45 | #include "extensions.h"
|
---|
46 | #include "fog.h"
|
---|
47 | #include "get.h"
|
---|
48 | #include "hash.h"
|
---|
49 | #include "light.h"
|
---|
50 | #include "lines.h"
|
---|
51 | #include "dlist.h"
|
---|
52 | #include "macros.h"
|
---|
53 | #include "matrix.h"
|
---|
54 | #include "mmath.h"
|
---|
55 | #include "pb.h"
|
---|
56 | #include "pipeline.h"
|
---|
57 | #include "points.h"
|
---|
58 | #include "quads.h"
|
---|
59 | #include "shade.h"
|
---|
60 | #include "state.h"
|
---|
61 | #include "simple_list.h"
|
---|
62 | #include "stencil.h"
|
---|
63 | #include "stages.h"
|
---|
64 | #include "triangle.h"
|
---|
65 | #include "translate.h"
|
---|
66 | #include "teximage.h"
|
---|
67 | #include "texobj.h"
|
---|
68 | #include "texstate.h"
|
---|
69 | #include "texture.h"
|
---|
70 | #include "types.h"
|
---|
71 | #include "varray.h"
|
---|
72 | #include "vb.h"
|
---|
73 | #include "vbcull.h"
|
---|
74 | #include "vbfill.h"
|
---|
75 | #include "vbrender.h"
|
---|
76 | #include "vbxform.h"
|
---|
77 | #include "vertices.h"
|
---|
78 | #include "xform.h"
|
---|
79 | #include "config.h"
|
---|
80 | #endif
|
---|
81 |
|
---|
82 | #ifdef __WIN32OS2__
|
---|
83 | /* #include <os2win.h> */
|
---|
84 | #ifdef DIVE
|
---|
85 | #include "types.h"
|
---|
86 | #include "wmesadef.h"
|
---|
87 | #include "mesadive.h"
|
---|
88 | #endif
|
---|
89 | #endif
|
---|
90 |
|
---|
91 |
|
---|
92 | /**********************************************************************/
|
---|
93 | /***** Context and Thread management *****/
|
---|
94 | /**********************************************************************/
|
---|
95 |
|
---|
96 |
|
---|
97 | #if !defined(THREADS)
|
---|
98 |
|
---|
99 | struct immediate *_mesa_CurrentInput = NULL;
|
---|
100 |
|
---|
101 | #endif
|
---|
102 |
|
---|
103 |
|
---|
104 |
|
---|
105 |
|
---|
106 | /**********************************************************************/
|
---|
107 | /***** Profiling functions *****/
|
---|
108 | /**********************************************************************/
|
---|
109 |
|
---|
110 | #ifdef PROFILE
|
---|
111 |
|
---|
112 | #ifndef __WIN32OS2__
|
---|
113 | #include <sys/times.h>
|
---|
114 | #include <sys/param.h>
|
---|
115 | #endif
|
---|
116 |
|
---|
117 | /*
|
---|
118 | * Return system time in seconds.
|
---|
119 | * NOTE: this implementation may not be very portable!
|
---|
120 | */
|
---|
121 |
|
---|
122 | GLdouble gl_time( void )
|
---|
123 | {
|
---|
124 | #ifdef __WIN32OS2__
|
---|
125 | return 1; // @@@PH
|
---|
126 | #else
|
---|
127 | static GLdouble prev_time = 0.0;
|
---|
128 | static GLdouble time;
|
---|
129 | struct tms tm;
|
---|
130 | clock_t clk;
|
---|
131 |
|
---|
132 | clk = times(&tm);
|
---|
133 |
|
---|
134 | #ifdef CLK_TCK
|
---|
135 | time = (double)clk / (double)CLK_TCK;
|
---|
136 | #else
|
---|
137 | time = (double)clk / (double)HZ;
|
---|
138 | #endif
|
---|
139 |
|
---|
140 | if (time>prev_time) {
|
---|
141 | prev_time = time;
|
---|
142 | return time;
|
---|
143 | }
|
---|
144 | else {
|
---|
145 | return prev_time;
|
---|
146 | }
|
---|
147 | #endif
|
---|
148 | }
|
---|
149 |
|
---|
150 | /*
|
---|
151 | * Reset the timing/profiling counters
|
---|
152 | */
|
---|
153 | static void init_timings( GLcontext *ctx )
|
---|
154 | {
|
---|
155 | ctx->BeginEndCount = 0;
|
---|
156 | ctx->BeginEndTime = 0.0;
|
---|
157 | ctx->VertexCount = 0;
|
---|
158 | ctx->VertexTime = 0.0;
|
---|
159 | ctx->PointCount = 0;
|
---|
160 | ctx->PointTime = 0.0;
|
---|
161 | ctx->LineCount = 0;
|
---|
162 | ctx->LineTime = 0.0;
|
---|
163 | ctx->PolygonCount = 0;
|
---|
164 | ctx->PolygonTime = 0.0;
|
---|
165 | ctx->ClearCount = 0;
|
---|
166 | ctx->ClearTime = 0.0;
|
---|
167 | ctx->SwapCount = 0;
|
---|
168 | ctx->SwapTime = 0.0;
|
---|
169 | }
|
---|
170 |
|
---|
171 |
|
---|
172 | /*
|
---|
173 | * Print the accumulated timing/profiling data.
|
---|
174 | */
|
---|
175 | static void print_timings( GLcontext *ctx )
|
---|
176 | {
|
---|
177 | GLdouble beginendrate;
|
---|
178 | GLdouble vertexrate;
|
---|
179 | GLdouble pointrate;
|
---|
180 | GLdouble linerate;
|
---|
181 | GLdouble polygonrate;
|
---|
182 | GLdouble overhead;
|
---|
183 | GLdouble clearrate;
|
---|
184 | GLdouble swaprate;
|
---|
185 | GLdouble avgvertices;
|
---|
186 |
|
---|
187 | if (ctx->BeginEndTime>0.0) {
|
---|
188 | beginendrate = ctx->BeginEndCount / ctx->BeginEndTime;
|
---|
189 | }
|
---|
190 | else {
|
---|
191 | beginendrate = 0.0;
|
---|
192 | }
|
---|
193 | if (ctx->VertexTime>0.0) {
|
---|
194 | vertexrate = ctx->VertexCount / ctx->VertexTime;
|
---|
195 | }
|
---|
196 | else {
|
---|
197 | vertexrate = 0.0;
|
---|
198 | }
|
---|
199 | if (ctx->PointTime>0.0) {
|
---|
200 | pointrate = ctx->PointCount / ctx->PointTime;
|
---|
201 | }
|
---|
202 | else {
|
---|
203 | pointrate = 0.0;
|
---|
204 | }
|
---|
205 | if (ctx->LineTime>0.0) {
|
---|
206 | linerate = ctx->LineCount / ctx->LineTime;
|
---|
207 | }
|
---|
208 | else {
|
---|
209 | linerate = 0.0;
|
---|
210 | }
|
---|
211 | if (ctx->PolygonTime>0.0) {
|
---|
212 | polygonrate = ctx->PolygonCount / ctx->PolygonTime;
|
---|
213 | }
|
---|
214 | else {
|
---|
215 | polygonrate = 0.0;
|
---|
216 | }
|
---|
217 | if (ctx->ClearTime>0.0) {
|
---|
218 | clearrate = ctx->ClearCount / ctx->ClearTime;
|
---|
219 | }
|
---|
220 | else {
|
---|
221 | clearrate = 0.0;
|
---|
222 | }
|
---|
223 | if (ctx->SwapTime>0.0) {
|
---|
224 | swaprate = ctx->SwapCount / ctx->SwapTime;
|
---|
225 | }
|
---|
226 | else {
|
---|
227 | swaprate = 0.0;
|
---|
228 | }
|
---|
229 |
|
---|
230 | if (ctx->BeginEndCount>0) {
|
---|
231 | avgvertices = (GLdouble) ctx->VertexCount / (GLdouble) ctx->BeginEndCount;
|
---|
232 | }
|
---|
233 | else {
|
---|
234 | avgvertices = 0.0;
|
---|
235 | }
|
---|
236 |
|
---|
237 | overhead = ctx->BeginEndTime - ctx->VertexTime - ctx->PointTime
|
---|
238 | - ctx->LineTime - ctx->PolygonTime;
|
---|
239 |
|
---|
240 |
|
---|
241 | printf(" Count Time (s) Rate (/s) \n");
|
---|
242 | printf("--------------------------------------------------------\n");
|
---|
243 | printf("glBegin/glEnd %7d %8.3f %10.3f\n",
|
---|
244 | ctx->BeginEndCount, ctx->BeginEndTime, beginendrate);
|
---|
245 | printf(" vertexes transformed %7d %8.3f %10.3f\n",
|
---|
246 | ctx->VertexCount, ctx->VertexTime, vertexrate );
|
---|
247 | printf(" points rasterized %7d %8.3f %10.3f\n",
|
---|
248 | ctx->PointCount, ctx->PointTime, pointrate );
|
---|
249 | printf(" lines rasterized %7d %8.3f %10.3f\n",
|
---|
250 | ctx->LineCount, ctx->LineTime, linerate );
|
---|
251 | printf(" polygons rasterized %7d %8.3f %10.3f\n",
|
---|
252 | ctx->PolygonCount, ctx->PolygonTime, polygonrate );
|
---|
253 | printf(" overhead %8.3f\n", overhead );
|
---|
254 | printf("glClear %7d %8.3f %10.3f\n",
|
---|
255 | ctx->ClearCount, ctx->ClearTime, clearrate );
|
---|
256 | printf("SwapBuffers %7d %8.3f %10.3f\n",
|
---|
257 | ctx->SwapCount, ctx->SwapTime, swaprate );
|
---|
258 | printf("\n");
|
---|
259 |
|
---|
260 | printf("Average number of vertices per begin/end: %8.3f\n", avgvertices );
|
---|
261 | }
|
---|
262 | #endif
|
---|
263 |
|
---|
264 |
|
---|
265 |
|
---|
266 |
|
---|
267 | /**********************************************************************/
|
---|
268 | /***** GL Visual allocation/destruction *****/
|
---|
269 | /**********************************************************************/
|
---|
270 |
|
---|
271 |
|
---|
272 | /*
|
---|
273 | * Allocate a new GLvisual object.
|
---|
274 | * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
|
---|
275 | * alphaFlag - alloc software alpha buffers?
|
---|
276 | * dbFlag - double buffering?
|
---|
277 | * stereoFlag - stereo buffer?
|
---|
278 | * depthBits - requested bits per depth buffer value
|
---|
279 | * Any value in [0, 32] is acceptable but the actual
|
---|
280 | * depth type will be GLushort or GLuint as needed.
|
---|
281 | * stencilBits - requested minimum bits per stencil buffer value
|
---|
282 | * accumBits - requested minimum bits per accum buffer component
|
---|
283 | * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
|
---|
284 | * red/green/blue/alphaBits - number of bits per color component
|
---|
285 | * in frame buffer for RGB(A) mode.
|
---|
286 | * We always use 8 in core Mesa though.
|
---|
287 | * Return: pointer to new GLvisual or NULL if requested parameters can't
|
---|
288 | * be met.
|
---|
289 | */
|
---|
290 | GLvisual *gl_create_visual( GLboolean rgbFlag,
|
---|
291 | GLboolean alphaFlag,
|
---|
292 | GLboolean dbFlag,
|
---|
293 | GLboolean stereoFlag,
|
---|
294 | GLint depthBits,
|
---|
295 | GLint stencilBits,
|
---|
296 | GLint accumBits,
|
---|
297 | GLint indexBits,
|
---|
298 | GLint redBits,
|
---|
299 | GLint greenBits,
|
---|
300 | GLint blueBits,
|
---|
301 | GLint alphaBits )
|
---|
302 | {
|
---|
303 | GLvisual *vis;
|
---|
304 |
|
---|
305 | /* This is to catch bad values from device drivers not updated for
|
---|
306 | * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
|
---|
307 | * bad value now (a 1-bit depth buffer!?!).
|
---|
308 | */
|
---|
309 | ASSERT(depthBits == 0 || depthBits > 1);
|
---|
310 |
|
---|
311 | if (depthBits < 0 || depthBits > 32) {
|
---|
312 | return NULL;
|
---|
313 | }
|
---|
314 | if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) {
|
---|
315 | return NULL;
|
---|
316 | }
|
---|
317 | if (accumBits < 0 || accumBits > (GLint) (8 * sizeof(GLaccum))) {
|
---|
318 | return NULL;
|
---|
319 | }
|
---|
320 |
|
---|
321 | vis = (GLvisual *) CALLOC( sizeof(GLvisual) );
|
---|
322 | if (!vis) {
|
---|
323 | return NULL;
|
---|
324 | }
|
---|
325 |
|
---|
326 | vis->RGBAflag = rgbFlag;
|
---|
327 | vis->DBflag = dbFlag;
|
---|
328 | vis->StereoFlag = stereoFlag;
|
---|
329 | vis->RedBits = redBits;
|
---|
330 | vis->GreenBits = greenBits;
|
---|
331 | vis->BlueBits = blueBits;
|
---|
332 | vis->AlphaBits = alphaFlag ? (8 * sizeof(GLubyte)) : alphaBits;
|
---|
333 |
|
---|
334 | vis->IndexBits = indexBits;
|
---|
335 | vis->DepthBits = depthBits;
|
---|
336 | vis->AccumBits = (accumBits > 0) ? (8 * sizeof(GLaccum)) : 0;
|
---|
337 | vis->StencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0;
|
---|
338 |
|
---|
339 | vis->SoftwareAlpha = alphaFlag;
|
---|
340 |
|
---|
341 | if (depthBits == 0) {
|
---|
342 | /* Special case. Even if we don't have a depth buffer we need
|
---|
343 | * good values for DepthMax for Z vertex transformation purposes.
|
---|
344 | */
|
---|
345 | vis->DepthMax = 1;
|
---|
346 | vis->DepthMaxF = 1.0F;
|
---|
347 | }
|
---|
348 | else {
|
---|
349 | vis->DepthMax = (1 << depthBits) - 1;
|
---|
350 | vis->DepthMaxF = (GLfloat) vis->DepthMax;
|
---|
351 | }
|
---|
352 |
|
---|
353 | return vis;
|
---|
354 | }
|
---|
355 |
|
---|
356 |
|
---|
357 |
|
---|
358 | void gl_destroy_visual( GLvisual *vis )
|
---|
359 | {
|
---|
360 | FREE( vis );
|
---|
361 | }
|
---|
362 |
|
---|
363 |
|
---|
364 |
|
---|
365 | /**********************************************************************/
|
---|
366 | /***** GL Framebuffer allocation/destruction *****/
|
---|
367 | /**********************************************************************/
|
---|
368 |
|
---|
369 |
|
---|
370 | /*
|
---|
371 | * Create a new framebuffer. A GLframebuffer is a struct which
|
---|
372 | * encapsulates the depth, stencil and accum buffers and related
|
---|
373 | * parameters.
|
---|
374 | * Input: visual - a GLvisual pointer
|
---|
375 | * softwareDepth - create/use a software depth buffer?
|
---|
376 | * softwareStencil - create/use a software stencil buffer?
|
---|
377 | * softwareAccum - create/use a software accum buffer?
|
---|
378 | * softwareAlpha - create/use a software alpha buffer?
|
---|
379 | *
|
---|
380 | * Return: pointer to new GLframebuffer struct or NULL if error.
|
---|
381 | */
|
---|
382 | GLframebuffer *gl_create_framebuffer( GLvisual *visual,
|
---|
383 | GLboolean softwareDepth,
|
---|
384 | GLboolean softwareStencil,
|
---|
385 | GLboolean softwareAccum,
|
---|
386 | GLboolean softwareAlpha )
|
---|
387 | {
|
---|
388 | GLframebuffer *buffer;
|
---|
389 |
|
---|
390 | buffer = CALLOC_STRUCT(gl_frame_buffer);
|
---|
391 | if (!buffer) {
|
---|
392 | return NULL;
|
---|
393 | }
|
---|
394 |
|
---|
395 | /* sanity checks */
|
---|
396 | if (softwareDepth ) {
|
---|
397 | ASSERT(visual->DepthBits > 0);
|
---|
398 | }
|
---|
399 | if (softwareStencil) {
|
---|
400 | ASSERT(visual->StencilBits > 0);
|
---|
401 | }
|
---|
402 | if (softwareAccum) {
|
---|
403 | ASSERT(visual->RGBAflag);
|
---|
404 | ASSERT(visual->AccumBits > 0);
|
---|
405 | }
|
---|
406 | if (softwareAlpha) {
|
---|
407 | ASSERT(visual->RGBAflag);
|
---|
408 | ASSERT(visual->AlphaBits > 0);
|
---|
409 | }
|
---|
410 |
|
---|
411 | buffer->Visual = visual;
|
---|
412 | buffer->UseSoftwareDepthBuffer = softwareDepth;
|
---|
413 | buffer->UseSoftwareStencilBuffer = softwareStencil;
|
---|
414 | buffer->UseSoftwareAccumBuffer = softwareAccum;
|
---|
415 | buffer->UseSoftwareAlphaBuffers = softwareAlpha;
|
---|
416 |
|
---|
417 | return buffer;
|
---|
418 | }
|
---|
419 |
|
---|
420 |
|
---|
421 |
|
---|
422 | /*
|
---|
423 | * Free a framebuffer struct and its buffers.
|
---|
424 | */
|
---|
425 | void gl_destroy_framebuffer( GLframebuffer *buffer )
|
---|
426 | {
|
---|
427 | if (buffer) {
|
---|
428 | if (buffer->DepthBuffer) {
|
---|
429 | FREE( buffer->DepthBuffer );
|
---|
430 | }
|
---|
431 | if (buffer->Accum) {
|
---|
432 | FREE( buffer->Accum );
|
---|
433 | }
|
---|
434 | if (buffer->Stencil) {
|
---|
435 | FREE( buffer->Stencil );
|
---|
436 | }
|
---|
437 | if (buffer->FrontLeftAlpha) {
|
---|
438 | FREE( buffer->FrontLeftAlpha );
|
---|
439 | }
|
---|
440 | if (buffer->BackLeftAlpha) {
|
---|
441 | FREE( buffer->BackLeftAlpha );
|
---|
442 | }
|
---|
443 | if (buffer->FrontRightAlpha) {
|
---|
444 | FREE( buffer->FrontRightAlpha );
|
---|
445 | }
|
---|
446 | if (buffer->BackRightAlpha) {
|
---|
447 | FREE( buffer->BackRightAlpha );
|
---|
448 | }
|
---|
449 | FREE(buffer);
|
---|
450 | }
|
---|
451 | }
|
---|
452 |
|
---|
453 |
|
---|
454 |
|
---|
455 | /**********************************************************************/
|
---|
456 | /***** Context allocation, initialization, destroying *****/
|
---|
457 | /**********************************************************************/
|
---|
458 |
|
---|
459 |
|
---|
460 | _glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
|
---|
461 |
|
---|
462 |
|
---|
463 | /*
|
---|
464 | * This function just calls all the various one-time-init functions in Mesa.
|
---|
465 | */
|
---|
466 | static void one_time_init( void )
|
---|
467 | {
|
---|
468 | static GLboolean alreadyCalled = GL_FALSE;
|
---|
469 | _glthread_LOCK_MUTEX(OneTimeLock);
|
---|
470 | if (!alreadyCalled) {
|
---|
471 | /* do some implementation tests */
|
---|
472 | ASSERT( sizeof(GLbyte) == 1 );
|
---|
473 | ASSERT( sizeof(GLshort) >= 2 );
|
---|
474 | ASSERT( sizeof(GLint) >= 4 );
|
---|
475 | ASSERT( sizeof(GLubyte) == 1 );
|
---|
476 | ASSERT( sizeof(GLushort) >= 2 );
|
---|
477 | ASSERT( sizeof(GLuint) >= 4 );
|
---|
478 |
|
---|
479 | gl_init_clip();
|
---|
480 | gl_init_eval();
|
---|
481 | _mesa_init_fog();
|
---|
482 | _mesa_init_math();
|
---|
483 | gl_init_lists();
|
---|
484 | gl_init_shade();
|
---|
485 | gl_init_texture();
|
---|
486 | gl_init_transformation();
|
---|
487 | gl_init_translate();
|
---|
488 | gl_init_vbrender();
|
---|
489 | gl_init_vbxform();
|
---|
490 | gl_init_vertices();
|
---|
491 |
|
---|
492 | if (getenv("MESA_DEBUG")) {
|
---|
493 | _glapi_noop_enable_warnings(GL_TRUE);
|
---|
494 | }
|
---|
495 | else {
|
---|
496 | _glapi_noop_enable_warnings(GL_FALSE);
|
---|
497 | }
|
---|
498 |
|
---|
499 | #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
|
---|
500 | fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
|
---|
501 | #endif
|
---|
502 |
|
---|
503 | alreadyCalled = GL_TRUE;
|
---|
504 | }
|
---|
505 | _glthread_UNLOCK_MUTEX(OneTimeLock);
|
---|
506 | }
|
---|
507 |
|
---|
508 |
|
---|
509 |
|
---|
510 | /*
|
---|
511 | * Allocate and initialize a shared context state structure.
|
---|
512 | */
|
---|
513 | static struct gl_shared_state *alloc_shared_state( void )
|
---|
514 | {
|
---|
515 | GLuint d;
|
---|
516 | struct gl_shared_state *ss;
|
---|
517 | GLboolean outOfMemory;
|
---|
518 |
|
---|
519 | ss = CALLOC_STRUCT(gl_shared_state);
|
---|
520 | if (!ss)
|
---|
521 | return NULL;
|
---|
522 |
|
---|
523 | ss->DisplayList = _mesa_NewHashTable();
|
---|
524 |
|
---|
525 | ss->TexObjects = _mesa_NewHashTable();
|
---|
526 |
|
---|
527 | /* Default Texture objects */
|
---|
528 | outOfMemory = GL_FALSE;
|
---|
529 | for (d = 1 ; d <= 3 ; d++) {
|
---|
530 | ss->DefaultD[d] = gl_alloc_texture_object(ss, 0, d);
|
---|
531 | if (!ss->DefaultD[d]) {
|
---|
532 | outOfMemory = GL_TRUE;
|
---|
533 | break;
|
---|
534 | }
|
---|
535 | ss->DefaultD[d]->RefCount++; /* don't free if not in use */
|
---|
536 | }
|
---|
537 |
|
---|
538 | if (!ss->DisplayList || !ss->TexObjects || outOfMemory) {
|
---|
539 | /* Ran out of memory at some point. Free everything and return NULL */
|
---|
540 | if (ss->DisplayList)
|
---|
541 | _mesa_DeleteHashTable(ss->DisplayList);
|
---|
542 | if (ss->TexObjects)
|
---|
543 | _mesa_DeleteHashTable(ss->TexObjects);
|
---|
544 | if (ss->DefaultD[1])
|
---|
545 | gl_free_texture_object(ss, ss->DefaultD[1]);
|
---|
546 | if (ss->DefaultD[2])
|
---|
547 | gl_free_texture_object(ss, ss->DefaultD[2]);
|
---|
548 | if (ss->DefaultD[3])
|
---|
549 | gl_free_texture_object(ss, ss->DefaultD[3]);
|
---|
550 | FREE(ss);
|
---|
551 | return NULL;
|
---|
552 | }
|
---|
553 | else {
|
---|
554 | return ss;
|
---|
555 | }
|
---|
556 | }
|
---|
557 |
|
---|
558 |
|
---|
559 | /*
|
---|
560 | * Deallocate a shared state context and all children structures.
|
---|
561 | */
|
---|
562 | static void free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
|
---|
563 | {
|
---|
564 | /* Free display lists */
|
---|
565 | while (1) {
|
---|
566 | GLuint list = _mesa_HashFirstEntry(ss->DisplayList);
|
---|
567 | if (list) {
|
---|
568 | gl_destroy_list(ctx, list);
|
---|
569 | }
|
---|
570 | else {
|
---|
571 | break;
|
---|
572 | }
|
---|
573 | }
|
---|
574 | _mesa_DeleteHashTable(ss->DisplayList);
|
---|
575 |
|
---|
576 | /* Free texture objects */
|
---|
577 | while (ss->TexObjectList)
|
---|
578 | {
|
---|
579 | if (ctx->Driver.DeleteTexture)
|
---|
580 | (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList );
|
---|
581 | /* this function removes from linked list too! */
|
---|
582 | gl_free_texture_object(ss, ss->TexObjectList);
|
---|
583 | }
|
---|
584 | _mesa_DeleteHashTable(ss->TexObjects);
|
---|
585 |
|
---|
586 | FREE(ss);
|
---|
587 | }
|
---|
588 |
|
---|
589 |
|
---|
590 |
|
---|
591 | /*
|
---|
592 | * Initialize the nth light. Note that the defaults for light 0 are
|
---|
593 | * different than the other lights.
|
---|
594 | */
|
---|
595 | static void init_light( struct gl_light *l, GLuint n )
|
---|
596 | {
|
---|
597 | make_empty_list( l );
|
---|
598 |
|
---|
599 | ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
|
---|
600 | if (n==0) {
|
---|
601 | ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
|
---|
602 | ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
|
---|
603 | }
|
---|
604 | else {
|
---|
605 | ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
|
---|
606 | ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
|
---|
607 | }
|
---|
608 | ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
|
---|
609 | ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
|
---|
610 | l->SpotExponent = 0.0;
|
---|
611 | gl_compute_spot_exp_table( l );
|
---|
612 | l->SpotCutoff = 180.0;
|
---|
613 | l->CosCutoff = 0.0; /* KW: -ve values not admitted */
|
---|
614 | l->ConstantAttenuation = 1.0;
|
---|
615 | l->LinearAttenuation = 0.0;
|
---|
616 | l->QuadraticAttenuation = 0.0;
|
---|
617 | l->Enabled = GL_FALSE;
|
---|
618 | }
|
---|
619 |
|
---|
620 |
|
---|
621 |
|
---|
622 | static void init_lightmodel( struct gl_lightmodel *lm )
|
---|
623 | {
|
---|
624 | ASSIGN_4V( lm->Ambient, 0.2, 0.2, 0.2, 1.0 );
|
---|
625 | lm->LocalViewer = GL_FALSE;
|
---|
626 | lm->TwoSide = GL_FALSE;
|
---|
627 | lm->ColorControl = GL_SINGLE_COLOR;
|
---|
628 | }
|
---|
629 |
|
---|
630 |
|
---|
631 | static void init_material( struct gl_material *m )
|
---|
632 | {
|
---|
633 | ASSIGN_4V( m->Ambient, 0.2, 0.2, 0.2, 1.0 );
|
---|
634 | ASSIGN_4V( m->Diffuse, 0.8, 0.8, 0.8, 1.0 );
|
---|
635 | ASSIGN_4V( m->Specular, 0.0, 0.0, 0.0, 1.0 );
|
---|
636 | ASSIGN_4V( m->Emission, 0.0, 0.0, 0.0, 1.0 );
|
---|
637 | m->Shininess = 0.0;
|
---|
638 | m->AmbientIndex = 0;
|
---|
639 | m->DiffuseIndex = 1;
|
---|
640 | m->SpecularIndex = 1;
|
---|
641 | }
|
---|
642 |
|
---|
643 |
|
---|
644 |
|
---|
645 | static void init_texture_unit( GLcontext *ctx, GLuint unit )
|
---|
646 | {
|
---|
647 | struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
|
---|
648 |
|
---|
649 | texUnit->EnvMode = GL_MODULATE;
|
---|
650 | ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
|
---|
651 | texUnit->TexGenEnabled = 0;
|
---|
652 | texUnit->GenModeS = GL_EYE_LINEAR;
|
---|
653 | texUnit->GenModeT = GL_EYE_LINEAR;
|
---|
654 | texUnit->GenModeR = GL_EYE_LINEAR;
|
---|
655 | texUnit->GenModeQ = GL_EYE_LINEAR;
|
---|
656 | /* Yes, these plane coefficients are correct! */
|
---|
657 | ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
|
---|
658 | ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
|
---|
659 | ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
|
---|
660 | ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
|
---|
661 | ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
|
---|
662 | ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
|
---|
663 | ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
|
---|
664 | ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
|
---|
665 |
|
---|
666 | texUnit->CurrentD[1] = ctx->Shared->DefaultD[1];
|
---|
667 | texUnit->CurrentD[2] = ctx->Shared->DefaultD[2];
|
---|
668 | texUnit->CurrentD[3] = ctx->Shared->DefaultD[3];
|
---|
669 | }
|
---|
670 |
|
---|
671 |
|
---|
672 | static void init_fallback_arrays( GLcontext *ctx )
|
---|
673 | {
|
---|
674 | struct gl_client_array *cl;
|
---|
675 | GLuint i;
|
---|
676 |
|
---|
677 | cl = &ctx->Fallback.Normal;
|
---|
678 | cl->Size = 3;
|
---|
679 | cl->Type = GL_FLOAT;
|
---|
680 | cl->Stride = 0;
|
---|
681 | cl->StrideB = 0;
|
---|
682 | cl->Ptr = (void *) ctx->Current.Normal;
|
---|
683 | cl->Enabled = 1;
|
---|
684 |
|
---|
685 | cl = &ctx->Fallback.Color;
|
---|
686 | cl->Size = 4;
|
---|
687 | cl->Type = GL_UNSIGNED_BYTE;
|
---|
688 | cl->Stride = 0;
|
---|
689 | cl->StrideB = 0;
|
---|
690 | cl->Ptr = (void *) ctx->Current.ByteColor;
|
---|
691 | cl->Enabled = 1;
|
---|
692 |
|
---|
693 | cl = &ctx->Fallback.Index;
|
---|
694 | cl->Size = 1;
|
---|
695 | cl->Type = GL_UNSIGNED_INT;
|
---|
696 | cl->Stride = 0;
|
---|
697 | cl->StrideB = 0;
|
---|
698 | cl->Ptr = (void *) &ctx->Current.Index;
|
---|
699 | cl->Enabled = 1;
|
---|
700 |
|
---|
701 | for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) {
|
---|
702 | cl = &ctx->Fallback.TexCoord[i];
|
---|
703 | cl->Size = 4;
|
---|
704 | cl->Type = GL_FLOAT;
|
---|
705 | cl->Stride = 0;
|
---|
706 | cl->StrideB = 0;
|
---|
707 | cl->Ptr = (void *) ctx->Current.Texcoord[i];
|
---|
708 | cl->Enabled = 1;
|
---|
709 | }
|
---|
710 |
|
---|
711 | cl = &ctx->Fallback.EdgeFlag;
|
---|
712 | cl->Size = 1;
|
---|
713 | cl->Type = GL_UNSIGNED_BYTE;
|
---|
714 | cl->Stride = 0;
|
---|
715 | cl->StrideB = 0;
|
---|
716 | cl->Ptr = (void *) &ctx->Current.EdgeFlag;
|
---|
717 | cl->Enabled = 1;
|
---|
718 | }
|
---|
719 |
|
---|
720 |
|
---|
721 | /* Initialize a 1-D evaluator map */
|
---|
722 | static void init_1d_map( struct gl_1d_map *map, int n, const float *initial )
|
---|
723 | {
|
---|
724 | map->Order = 1;
|
---|
725 | map->u1 = 0.0;
|
---|
726 | map->u2 = 1.0;
|
---|
727 | map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
|
---|
728 | if (map->Points) {
|
---|
729 | GLint i;
|
---|
730 | for (i=0;i<n;i++)
|
---|
731 | map->Points[i] = initial[i];
|
---|
732 | }
|
---|
733 | }
|
---|
734 |
|
---|
735 |
|
---|
736 | /* Initialize a 2-D evaluator map */
|
---|
737 | static void init_2d_map( struct gl_2d_map *map, int n, const float *initial )
|
---|
738 | {
|
---|
739 | map->Uorder = 1;
|
---|
740 | map->Vorder = 1;
|
---|
741 | map->u1 = 0.0;
|
---|
742 | map->u2 = 1.0;
|
---|
743 | map->v1 = 0.0;
|
---|
744 | map->v2 = 1.0;
|
---|
745 | map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
|
---|
746 | if (map->Points) {
|
---|
747 | GLint i;
|
---|
748 | for (i=0;i<n;i++)
|
---|
749 | map->Points[i] = initial[i];
|
---|
750 | }
|
---|
751 | }
|
---|
752 |
|
---|
753 |
|
---|
754 | static void init_color_table( struct gl_color_table *p )
|
---|
755 | {
|
---|
756 | p->Table[0] = 255;
|
---|
757 | p->Table[1] = 255;
|
---|
758 | p->Table[2] = 255;
|
---|
759 | p->Table[3] = 255;
|
---|
760 | p->Size = 1;
|
---|
761 | p->IntFormat = GL_RGBA;
|
---|
762 | p->Format = GL_RGBA;
|
---|
763 | }
|
---|
764 |
|
---|
765 |
|
---|
766 | /*
|
---|
767 | * Initialize the attribute groups in a GLcontext.
|
---|
768 | */
|
---|
769 | static void init_attrib_groups( GLcontext *ctx )
|
---|
770 | {
|
---|
771 | GLuint i, j;
|
---|
772 |
|
---|
773 | ASSERT(ctx);
|
---|
774 |
|
---|
775 | /* Constants, may be overriden by device drivers */
|
---|
776 | ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
|
---|
777 | ctx->Const.MaxTextureSize = 1 << (MAX_TEXTURE_LEVELS - 1);
|
---|
778 | ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
|
---|
779 | ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
|
---|
780 | ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
|
---|
781 | ctx->Const.MinPointSize = MIN_POINT_SIZE;
|
---|
782 | ctx->Const.MaxPointSize = MAX_POINT_SIZE;
|
---|
783 | ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
|
---|
784 | ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
|
---|
785 | ctx->Const.PointSizeGranularity = POINT_SIZE_GRANULARITY;
|
---|
786 | ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
|
---|
787 | ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
|
---|
788 | ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
|
---|
789 | ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
|
---|
790 | ctx->Const.LineWidthGranularity = LINE_WIDTH_GRANULARITY;
|
---|
791 | ctx->Const.NumAuxBuffers = NUM_AUX_BUFFERS;
|
---|
792 |
|
---|
793 | /* Modelview matrix */
|
---|
794 | gl_matrix_ctr( &ctx->ModelView );
|
---|
795 | gl_matrix_alloc_inv( &ctx->ModelView );
|
---|
796 |
|
---|
797 | ctx->ModelViewStackDepth = 0;
|
---|
798 | for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
|
---|
799 | gl_matrix_ctr( &ctx->ModelViewStack[i] );
|
---|
800 | gl_matrix_alloc_inv( &ctx->ModelViewStack[i] );
|
---|
801 | }
|
---|
802 |
|
---|
803 | /* Projection matrix - need inv for user clipping in clip space*/
|
---|
804 | gl_matrix_ctr( &ctx->ProjectionMatrix );
|
---|
805 | gl_matrix_alloc_inv( &ctx->ProjectionMatrix );
|
---|
806 |
|
---|
807 | gl_matrix_ctr( &ctx->ModelProjectMatrix );
|
---|
808 | gl_matrix_ctr( &ctx->ModelProjectWinMatrix );
|
---|
809 | ctx->ModelProjectWinMatrixUptodate = GL_FALSE;
|
---|
810 |
|
---|
811 | ctx->ProjectionStackDepth = 0;
|
---|
812 | ctx->NearFarStack[0][0] = 1.0; /* These values seem weird by make */
|
---|
813 | ctx->NearFarStack[0][1] = 0.0; /* sense mathematically. */
|
---|
814 |
|
---|
815 | for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
|
---|
816 | gl_matrix_ctr( &ctx->ProjectionStack[i] );
|
---|
817 | gl_matrix_alloc_inv( &ctx->ProjectionStack[i] );
|
---|
818 | }
|
---|
819 |
|
---|
820 | /* Texture matrix */
|
---|
821 | for (i=0; i<MAX_TEXTURE_UNITS; i++) {
|
---|
822 | gl_matrix_ctr( &ctx->TextureMatrix[i] );
|
---|
823 | ctx->TextureStackDepth[i] = 0;
|
---|
824 | for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
|
---|
825 | ctx->TextureStack[i][j].inv = 0;
|
---|
826 | }
|
---|
827 | }
|
---|
828 |
|
---|
829 | /* Accumulate buffer group */
|
---|
830 | ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
|
---|
831 |
|
---|
832 | /* Color buffer group */
|
---|
833 | ctx->Color.IndexMask = 0xffffffff;
|
---|
834 | ctx->Color.ColorMask[0] = 0xff;
|
---|
835 | ctx->Color.ColorMask[1] = 0xff;
|
---|
836 | ctx->Color.ColorMask[2] = 0xff;
|
---|
837 | ctx->Color.ColorMask[3] = 0xff;
|
---|
838 | ctx->Color.SWmasking = GL_FALSE;
|
---|
839 | ctx->Color.ClearIndex = 0;
|
---|
840 | ASSIGN_4V( ctx->Color.ClearColor, 0.0, 0.0, 0.0, 0.0 );
|
---|
841 | ctx->Color.DrawBuffer = GL_FRONT;
|
---|
842 | ctx->Color.AlphaEnabled = GL_FALSE;
|
---|
843 | ctx->Color.AlphaFunc = GL_ALWAYS;
|
---|
844 | ctx->Color.AlphaRef = 0;
|
---|
845 | ctx->Color.BlendEnabled = GL_FALSE;
|
---|
846 | ctx->Color.BlendSrcRGB = GL_ONE;
|
---|
847 | ctx->Color.BlendDstRGB = GL_ZERO;
|
---|
848 | ctx->Color.BlendSrcA = GL_ONE;
|
---|
849 | ctx->Color.BlendDstA = GL_ZERO;
|
---|
850 | ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
|
---|
851 | ctx->Color.BlendFunc = NULL; /* this pointer set only when needed */
|
---|
852 | ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
|
---|
853 | ctx->Color.IndexLogicOpEnabled = GL_FALSE;
|
---|
854 | ctx->Color.ColorLogicOpEnabled = GL_FALSE;
|
---|
855 | ctx->Color.SWLogicOpEnabled = GL_FALSE;
|
---|
856 | ctx->Color.LogicOp = GL_COPY;
|
---|
857 | ctx->Color.DitherFlag = GL_TRUE;
|
---|
858 | ctx->Color.MultiDrawBuffer = GL_FALSE;
|
---|
859 |
|
---|
860 | /* Current group */
|
---|
861 | ASSIGN_4V( ctx->Current.ByteColor, 255, 255, 255, 255);
|
---|
862 | ctx->Current.Index = 1;
|
---|
863 | for (i=0; i<MAX_TEXTURE_UNITS; i++)
|
---|
864 | ASSIGN_4V( ctx->Current.Texcoord[i], 0.0, 0.0, 0.0, 1.0 );
|
---|
865 | ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
|
---|
866 | ctx->Current.RasterDistance = 0.0;
|
---|
867 | ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
|
---|
868 | ctx->Current.RasterIndex = 1;
|
---|
869 | for (i=0; i<MAX_TEXTURE_UNITS; i++)
|
---|
870 | ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
|
---|
871 | ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0];
|
---|
872 | ctx->Current.RasterPosValid = GL_TRUE;
|
---|
873 | ctx->Current.EdgeFlag = GL_TRUE;
|
---|
874 | ASSIGN_3V( ctx->Current.Normal, 0.0, 0.0, 1.0 );
|
---|
875 | ctx->Current.Primitive = (GLenum) (GL_POLYGON + 1);
|
---|
876 |
|
---|
877 | ctx->Current.Flag = (VERT_NORM|VERT_INDEX|VERT_RGBA|VERT_EDGE|
|
---|
878 | VERT_TEX0_1|VERT_TEX1_1|VERT_MATERIAL);
|
---|
879 |
|
---|
880 | init_fallback_arrays( ctx );
|
---|
881 |
|
---|
882 | /* Depth buffer group */
|
---|
883 | ctx->Depth.Test = GL_FALSE;
|
---|
884 | ctx->Depth.Clear = 1.0;
|
---|
885 | ctx->Depth.Func = GL_LESS;
|
---|
886 | ctx->Depth.Mask = GL_TRUE;
|
---|
887 | ctx->Depth.OcclusionTest = GL_FALSE;
|
---|
888 |
|
---|
889 | /* Evaluators group */
|
---|
890 | ctx->Eval.Map1Color4 = GL_FALSE;
|
---|
891 | ctx->Eval.Map1Index = GL_FALSE;
|
---|
892 | ctx->Eval.Map1Normal = GL_FALSE;
|
---|
893 | ctx->Eval.Map1TextureCoord1 = GL_FALSE;
|
---|
894 | ctx->Eval.Map1TextureCoord2 = GL_FALSE;
|
---|
895 | ctx->Eval.Map1TextureCoord3 = GL_FALSE;
|
---|
896 | ctx->Eval.Map1TextureCoord4 = GL_FALSE;
|
---|
897 | ctx->Eval.Map1Vertex3 = GL_FALSE;
|
---|
898 | ctx->Eval.Map1Vertex4 = GL_FALSE;
|
---|
899 | ctx->Eval.Map2Color4 = GL_FALSE;
|
---|
900 | ctx->Eval.Map2Index = GL_FALSE;
|
---|
901 | ctx->Eval.Map2Normal = GL_FALSE;
|
---|
902 | ctx->Eval.Map2TextureCoord1 = GL_FALSE;
|
---|
903 | ctx->Eval.Map2TextureCoord2 = GL_FALSE;
|
---|
904 | ctx->Eval.Map2TextureCoord3 = GL_FALSE;
|
---|
905 | ctx->Eval.Map2TextureCoord4 = GL_FALSE;
|
---|
906 | ctx->Eval.Map2Vertex3 = GL_FALSE;
|
---|
907 | ctx->Eval.Map2Vertex4 = GL_FALSE;
|
---|
908 | ctx->Eval.AutoNormal = GL_FALSE;
|
---|
909 | ctx->Eval.MapGrid1un = 1;
|
---|
910 | ctx->Eval.MapGrid1u1 = 0.0;
|
---|
911 | ctx->Eval.MapGrid1u2 = 1.0;
|
---|
912 | ctx->Eval.MapGrid2un = 1;
|
---|
913 | ctx->Eval.MapGrid2vn = 1;
|
---|
914 | ctx->Eval.MapGrid2u1 = 0.0;
|
---|
915 | ctx->Eval.MapGrid2u2 = 1.0;
|
---|
916 | ctx->Eval.MapGrid2v1 = 0.0;
|
---|
917 | ctx->Eval.MapGrid2v2 = 1.0;
|
---|
918 |
|
---|
919 | /* Evaluator data */
|
---|
920 | {
|
---|
921 | static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
|
---|
922 | static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
|
---|
923 | static GLfloat index[1] = { 1.0 };
|
---|
924 | static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
|
---|
925 | static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
|
---|
926 |
|
---|
927 | init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
|
---|
928 | init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
|
---|
929 | init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
|
---|
930 | init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
|
---|
931 | init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
|
---|
932 | init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
|
---|
933 | init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
|
---|
934 | init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
|
---|
935 | init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
|
---|
936 |
|
---|
937 | init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
|
---|
938 | init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
|
---|
939 | init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
|
---|
940 | init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
|
---|
941 | init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
|
---|
942 | init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
|
---|
943 | init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
|
---|
944 | init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
|
---|
945 | init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
|
---|
946 | }
|
---|
947 |
|
---|
948 | /* Fog group */
|
---|
949 | ctx->Fog.Enabled = GL_FALSE;
|
---|
950 | ctx->Fog.Mode = GL_EXP;
|
---|
951 | ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
|
---|
952 | ctx->Fog.Index = 0.0;
|
---|
953 | ctx->Fog.Density = 1.0;
|
---|
954 | ctx->Fog.Start = 0.0;
|
---|
955 | ctx->Fog.End = 1.0;
|
---|
956 |
|
---|
957 | /* Hint group */
|
---|
958 | ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
|
---|
959 | ctx->Hint.PointSmooth = GL_DONT_CARE;
|
---|
960 | ctx->Hint.LineSmooth = GL_DONT_CARE;
|
---|
961 | ctx->Hint.PolygonSmooth = GL_DONT_CARE;
|
---|
962 | ctx->Hint.Fog = GL_DONT_CARE;
|
---|
963 |
|
---|
964 | ctx->Hint.AllowDrawWin = GL_TRUE;
|
---|
965 | ctx->Hint.AllowDrawSpn = GL_TRUE;
|
---|
966 | ctx->Hint.AllowDrawMem = GL_TRUE;
|
---|
967 | ctx->Hint.StrictLighting = GL_TRUE;
|
---|
968 |
|
---|
969 | /* Pipeline */
|
---|
970 | gl_pipeline_init( ctx );
|
---|
971 | gl_cva_init( ctx );
|
---|
972 |
|
---|
973 | /* Extensions */
|
---|
974 | gl_extensions_ctr( ctx );
|
---|
975 |
|
---|
976 | ctx->AllowVertexCull = CLIP_CULLED_BIT;
|
---|
977 |
|
---|
978 | /* Lighting group */
|
---|
979 | for (i=0;i<MAX_LIGHTS;i++) {
|
---|
980 | init_light( &ctx->Light.Light[i], i );
|
---|
981 | }
|
---|
982 | make_empty_list( &ctx->Light.EnabledList );
|
---|
983 |
|
---|
984 | init_lightmodel( &ctx->Light.Model );
|
---|
985 | init_material( &ctx->Light.Material[0] );
|
---|
986 | init_material( &ctx->Light.Material[1] );
|
---|
987 | ctx->Light.ShadeModel = GL_SMOOTH;
|
---|
988 | ctx->Light.Enabled = GL_FALSE;
|
---|
989 | ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
|
---|
990 | ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
|
---|
991 | ctx->Light.ColorMaterialBitmask
|
---|
992 | = gl_material_bitmask( ctx,
|
---|
993 | GL_FRONT_AND_BACK,
|
---|
994 | GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
|
---|
995 |
|
---|
996 | ctx->Light.ColorMaterialEnabled = GL_FALSE;
|
---|
997 |
|
---|
998 | /* Lighting miscellaneous */
|
---|
999 | ctx->ShineTabList = MALLOC_STRUCT( gl_shine_tab );
|
---|
1000 | make_empty_list( ctx->ShineTabList );
|
---|
1001 | for (i = 0 ; i < 10 ; i++) {
|
---|
1002 | struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
|
---|
1003 | s->shininess = -1;
|
---|
1004 | s->refcount = 0;
|
---|
1005 | insert_at_tail( ctx->ShineTabList, s );
|
---|
1006 | }
|
---|
1007 | for (i = 0 ; i < 4 ; i++) {
|
---|
1008 | ctx->ShineTable[i] = ctx->ShineTabList->prev;
|
---|
1009 | ctx->ShineTable[i]->refcount++;
|
---|
1010 | }
|
---|
1011 |
|
---|
1012 |
|
---|
1013 | /* Line group */
|
---|
1014 | ctx->Line.SmoothFlag = GL_FALSE;
|
---|
1015 | ctx->Line.StippleFlag = GL_FALSE;
|
---|
1016 | ctx->Line.Width = 1.0;
|
---|
1017 | ctx->Line.StipplePattern = 0xffff;
|
---|
1018 | ctx->Line.StippleFactor = 1;
|
---|
1019 |
|
---|
1020 | /* Display List group */
|
---|
1021 | ctx->List.ListBase = 0;
|
---|
1022 |
|
---|
1023 | /* Pixel group */
|
---|
1024 | ctx->Pixel.RedBias = 0.0;
|
---|
1025 | ctx->Pixel.RedScale = 1.0;
|
---|
1026 | ctx->Pixel.GreenBias = 0.0;
|
---|
1027 | ctx->Pixel.GreenScale = 1.0;
|
---|
1028 | ctx->Pixel.BlueBias = 0.0;
|
---|
1029 | ctx->Pixel.BlueScale = 1.0;
|
---|
1030 | ctx->Pixel.AlphaBias = 0.0;
|
---|
1031 | ctx->Pixel.AlphaScale = 1.0;
|
---|
1032 | ctx->Pixel.ScaleOrBiasRGBA = GL_FALSE;
|
---|
1033 | ctx->Pixel.DepthBias = 0.0;
|
---|
1034 | ctx->Pixel.DepthScale = 1.0;
|
---|
1035 | ctx->Pixel.IndexOffset = 0;
|
---|
1036 | ctx->Pixel.IndexShift = 0;
|
---|
1037 | ctx->Pixel.ZoomX = 1.0;
|
---|
1038 | ctx->Pixel.ZoomY = 1.0;
|
---|
1039 | ctx->Pixel.MapColorFlag = GL_FALSE;
|
---|
1040 | ctx->Pixel.MapStencilFlag = GL_FALSE;
|
---|
1041 | ctx->Pixel.MapStoSsize = 1;
|
---|
1042 | ctx->Pixel.MapItoIsize = 1;
|
---|
1043 | ctx->Pixel.MapItoRsize = 1;
|
---|
1044 | ctx->Pixel.MapItoGsize = 1;
|
---|
1045 | ctx->Pixel.MapItoBsize = 1;
|
---|
1046 | ctx->Pixel.MapItoAsize = 1;
|
---|
1047 | ctx->Pixel.MapRtoRsize = 1;
|
---|
1048 | ctx->Pixel.MapGtoGsize = 1;
|
---|
1049 | ctx->Pixel.MapBtoBsize = 1;
|
---|
1050 | ctx->Pixel.MapAtoAsize = 1;
|
---|
1051 | ctx->Pixel.MapStoS[0] = 0;
|
---|
1052 | ctx->Pixel.MapItoI[0] = 0;
|
---|
1053 | ctx->Pixel.MapItoR[0] = 0.0;
|
---|
1054 | ctx->Pixel.MapItoG[0] = 0.0;
|
---|
1055 | ctx->Pixel.MapItoB[0] = 0.0;
|
---|
1056 | ctx->Pixel.MapItoA[0] = 0.0;
|
---|
1057 | ctx->Pixel.MapItoR8[0] = 0;
|
---|
1058 | ctx->Pixel.MapItoG8[0] = 0;
|
---|
1059 | ctx->Pixel.MapItoB8[0] = 0;
|
---|
1060 | ctx->Pixel.MapItoA8[0] = 0;
|
---|
1061 | ctx->Pixel.MapRtoR[0] = 0.0;
|
---|
1062 | ctx->Pixel.MapGtoG[0] = 0.0;
|
---|
1063 | ctx->Pixel.MapBtoB[0] = 0.0;
|
---|
1064 | ctx->Pixel.MapAtoA[0] = 0.0;
|
---|
1065 |
|
---|
1066 | /* Point group */
|
---|
1067 | ctx->Point.SmoothFlag = GL_FALSE;
|
---|
1068 | ctx->Point.Size = 1.0;
|
---|
1069 | ctx->Point.Params[0] = 1.0;
|
---|
1070 | ctx->Point.Params[1] = 0.0;
|
---|
1071 | ctx->Point.Params[2] = 0.0;
|
---|
1072 | ctx->Point.Attenuated = GL_FALSE;
|
---|
1073 | ctx->Point.MinSize = 0.0;
|
---|
1074 | ctx->Point.MaxSize = (GLfloat) MAX_POINT_SIZE;
|
---|
1075 | ctx->Point.Threshold = 1.0;
|
---|
1076 |
|
---|
1077 | /* Polygon group */
|
---|
1078 | ctx->Polygon.CullFlag = GL_FALSE;
|
---|
1079 | ctx->Polygon.CullFaceMode = GL_BACK;
|
---|
1080 | ctx->Polygon.FrontFace = GL_CCW;
|
---|
1081 | ctx->Polygon.FrontBit = 0;
|
---|
1082 | ctx->Polygon.FrontMode = GL_FILL;
|
---|
1083 | ctx->Polygon.BackMode = GL_FILL;
|
---|
1084 | ctx->Polygon.Unfilled = GL_FALSE;
|
---|
1085 | ctx->Polygon.SmoothFlag = GL_FALSE;
|
---|
1086 | ctx->Polygon.StippleFlag = GL_FALSE;
|
---|
1087 | ctx->Polygon.OffsetFactor = 0.0F;
|
---|
1088 | ctx->Polygon.OffsetUnits = 0.0F;
|
---|
1089 | ctx->Polygon.OffsetPoint = GL_FALSE;
|
---|
1090 | ctx->Polygon.OffsetLine = GL_FALSE;
|
---|
1091 | ctx->Polygon.OffsetFill = GL_FALSE;
|
---|
1092 |
|
---|
1093 | /* Polygon Stipple group */
|
---|
1094 | MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
|
---|
1095 |
|
---|
1096 | /* Scissor group */
|
---|
1097 | ctx->Scissor.Enabled = GL_FALSE;
|
---|
1098 | ctx->Scissor.X = 0;
|
---|
1099 | ctx->Scissor.Y = 0;
|
---|
1100 | ctx->Scissor.Width = 0;
|
---|
1101 | ctx->Scissor.Height = 0;
|
---|
1102 |
|
---|
1103 | /* Stencil group */
|
---|
1104 | ctx->Stencil.Enabled = GL_FALSE;
|
---|
1105 | ctx->Stencil.Function = GL_ALWAYS;
|
---|
1106 | ctx->Stencil.FailFunc = GL_KEEP;
|
---|
1107 | ctx->Stencil.ZPassFunc = GL_KEEP;
|
---|
1108 | ctx->Stencil.ZFailFunc = GL_KEEP;
|
---|
1109 | ctx->Stencil.Ref = 0;
|
---|
1110 | ctx->Stencil.ValueMask = STENCIL_MAX;
|
---|
1111 | ctx->Stencil.Clear = 0;
|
---|
1112 | ctx->Stencil.WriteMask = STENCIL_MAX;
|
---|
1113 |
|
---|
1114 | /* Texture group */
|
---|
1115 | ctx->Texture.CurrentUnit = 0; /* multitexture */
|
---|
1116 | ctx->Texture.CurrentTransformUnit = 0; /* multitexture */
|
---|
1117 | ctx->Texture.Enabled = 0;
|
---|
1118 | for (i=0; i<MAX_TEXTURE_UNITS; i++)
|
---|
1119 | init_texture_unit( ctx, i );
|
---|
1120 | init_color_table(&ctx->Texture.Palette);
|
---|
1121 |
|
---|
1122 | /* Transformation group */
|
---|
1123 | ctx->Transform.MatrixMode = GL_MODELVIEW;
|
---|
1124 | ctx->Transform.Normalize = GL_FALSE;
|
---|
1125 | ctx->Transform.RescaleNormals = GL_FALSE;
|
---|
1126 | for (i=0;i<MAX_CLIP_PLANES;i++) {
|
---|
1127 | ctx->Transform.ClipEnabled[i] = GL_FALSE;
|
---|
1128 | ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
|
---|
1129 | }
|
---|
1130 | ctx->Transform.AnyClip = GL_FALSE;
|
---|
1131 |
|
---|
1132 | /* Viewport group */
|
---|
1133 | ctx->Viewport.X = 0;
|
---|
1134 | ctx->Viewport.Y = 0;
|
---|
1135 | ctx->Viewport.Width = 0;
|
---|
1136 | ctx->Viewport.Height = 0;
|
---|
1137 | ctx->Viewport.Near = 0.0;
|
---|
1138 | ctx->Viewport.Far = 1.0;
|
---|
1139 | gl_matrix_ctr(&ctx->Viewport.WindowMap);
|
---|
1140 |
|
---|
1141 | #define Sz 10
|
---|
1142 | #define Tz 14
|
---|
1143 | ctx->Viewport.WindowMap.m[Sz] = 0.5 * ctx->Visual->DepthMaxF;
|
---|
1144 | ctx->Viewport.WindowMap.m[Tz] = 0.5 * ctx->Visual->DepthMaxF;
|
---|
1145 | #undef Sz
|
---|
1146 | #undef Tz
|
---|
1147 |
|
---|
1148 | ctx->Viewport.WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
|
---|
1149 | ctx->Viewport.WindowMap.type = MATRIX_3D_NO_ROT;
|
---|
1150 |
|
---|
1151 | /* Vertex arrays */
|
---|
1152 | ctx->Array.Vertex.Size = 4;
|
---|
1153 | ctx->Array.Vertex.Type = GL_FLOAT;
|
---|
1154 | ctx->Array.Vertex.Stride = 0;
|
---|
1155 | ctx->Array.Vertex.StrideB = 0;
|
---|
1156 | ctx->Array.Vertex.Ptr = NULL;
|
---|
1157 | ctx->Array.Vertex.Enabled = GL_FALSE;
|
---|
1158 | ctx->Array.Normal.Type = GL_FLOAT;
|
---|
1159 | ctx->Array.Normal.Stride = 0;
|
---|
1160 | ctx->Array.Normal.StrideB = 0;
|
---|
1161 | ctx->Array.Normal.Ptr = NULL;
|
---|
1162 | ctx->Array.Normal.Enabled = GL_FALSE;
|
---|
1163 | ctx->Array.Color.Size = 4;
|
---|
1164 | ctx->Array.Color.Type = GL_FLOAT;
|
---|
1165 | ctx->Array.Color.Stride = 0;
|
---|
1166 | ctx->Array.Color.StrideB = 0;
|
---|
1167 | ctx->Array.Color.Ptr = NULL;
|
---|
1168 | ctx->Array.Color.Enabled = GL_FALSE;
|
---|
1169 | ctx->Array.Index.Type = GL_FLOAT;
|
---|
1170 | ctx->Array.Index.Stride = 0;
|
---|
1171 | ctx->Array.Index.StrideB = 0;
|
---|
1172 | ctx->Array.Index.Ptr = NULL;
|
---|
1173 | ctx->Array.Index.Enabled = GL_FALSE;
|
---|
1174 | for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
|
---|
1175 | ctx->Array.TexCoord[i].Size = 4;
|
---|
1176 | ctx->Array.TexCoord[i].Type = GL_FLOAT;
|
---|
1177 | ctx->Array.TexCoord[i].Stride = 0;
|
---|
1178 | ctx->Array.TexCoord[i].StrideB = 0;
|
---|
1179 | ctx->Array.TexCoord[i].Ptr = NULL;
|
---|
1180 | ctx->Array.TexCoord[i].Enabled = GL_FALSE;
|
---|
1181 | }
|
---|
1182 | ctx->Array.TexCoordInterleaveFactor = 1;
|
---|
1183 | ctx->Array.EdgeFlag.Stride = 0;
|
---|
1184 | ctx->Array.EdgeFlag.StrideB = 0;
|
---|
1185 | ctx->Array.EdgeFlag.Ptr = NULL;
|
---|
1186 | ctx->Array.EdgeFlag.Enabled = GL_FALSE;
|
---|
1187 | ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
|
---|
1188 |
|
---|
1189 | /* Pixel transfer */
|
---|
1190 | ctx->Pack.Alignment = 4;
|
---|
1191 | ctx->Pack.RowLength = 0;
|
---|
1192 | ctx->Pack.ImageHeight = 0;
|
---|
1193 | ctx->Pack.SkipPixels = 0;
|
---|
1194 | ctx->Pack.SkipRows = 0;
|
---|
1195 | ctx->Pack.SkipImages = 0;
|
---|
1196 | ctx->Pack.SwapBytes = GL_FALSE;
|
---|
1197 | ctx->Pack.LsbFirst = GL_FALSE;
|
---|
1198 | ctx->Unpack.Alignment = 4;
|
---|
1199 | ctx->Unpack.RowLength = 0;
|
---|
1200 | ctx->Unpack.ImageHeight = 0;
|
---|
1201 | ctx->Unpack.SkipPixels = 0;
|
---|
1202 | ctx->Unpack.SkipRows = 0;
|
---|
1203 | ctx->Unpack.SkipImages = 0;
|
---|
1204 | ctx->Unpack.SwapBytes = GL_FALSE;
|
---|
1205 | ctx->Unpack.LsbFirst = GL_FALSE;
|
---|
1206 |
|
---|
1207 | /* Feedback */
|
---|
1208 | ctx->Feedback.Type = GL_2D; /* TODO: verify */
|
---|
1209 | ctx->Feedback.Buffer = NULL;
|
---|
1210 | ctx->Feedback.BufferSize = 0;
|
---|
1211 | ctx->Feedback.Count = 0;
|
---|
1212 |
|
---|
1213 | /* Selection/picking */
|
---|
1214 | ctx->Select.Buffer = NULL;
|
---|
1215 | ctx->Select.BufferSize = 0;
|
---|
1216 | ctx->Select.BufferCount = 0;
|
---|
1217 | ctx->Select.Hits = 0;
|
---|
1218 | ctx->Select.NameStackDepth = 0;
|
---|
1219 |
|
---|
1220 | /* Optimized Accum buffer */
|
---|
1221 | ctx->IntegerAccumMode = GL_TRUE;
|
---|
1222 | ctx->IntegerAccumScaler = 0.0;
|
---|
1223 |
|
---|
1224 | /* Renderer and client attribute stacks */
|
---|
1225 | ctx->AttribStackDepth = 0;
|
---|
1226 | ctx->ClientAttribStackDepth = 0;
|
---|
1227 |
|
---|
1228 | /* Miscellaneous */
|
---|
1229 | ctx->NewState = NEW_ALL;
|
---|
1230 | ctx->RenderMode = GL_RENDER;
|
---|
1231 | ctx->StippleCounter = 0;
|
---|
1232 | ctx->NeedNormals = GL_FALSE;
|
---|
1233 | ctx->DoViewportMapping = GL_TRUE;
|
---|
1234 |
|
---|
1235 | ctx->NeedEyeCoords = GL_FALSE;
|
---|
1236 | ctx->NeedEyeNormals = GL_FALSE;
|
---|
1237 | ctx->vb_proj_matrix = &ctx->ModelProjectMatrix;
|
---|
1238 |
|
---|
1239 | /* Display list */
|
---|
1240 | ctx->CallDepth = 0;
|
---|
1241 | ctx->ExecuteFlag = GL_TRUE;
|
---|
1242 | ctx->CompileFlag = GL_FALSE;
|
---|
1243 | ctx->CurrentListPtr = NULL;
|
---|
1244 | ctx->CurrentBlock = NULL;
|
---|
1245 | ctx->CurrentListNum = 0;
|
---|
1246 | ctx->CurrentPos = 0;
|
---|
1247 |
|
---|
1248 | ctx->ErrorValue = (GLenum) GL_NO_ERROR;
|
---|
1249 |
|
---|
1250 | ctx->CatchSignals = GL_TRUE;
|
---|
1251 | ctx->OcclusionResult = GL_FALSE;
|
---|
1252 |
|
---|
1253 | /* For debug/development only */
|
---|
1254 | ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
|
---|
1255 | ctx->FirstTimeCurrent = GL_TRUE;
|
---|
1256 |
|
---|
1257 | /* Dither disable */
|
---|
1258 | ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
|
---|
1259 | if (ctx->NoDither) {
|
---|
1260 | if (getenv("MESA_DEBUG")) {
|
---|
1261 | fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
|
---|
1262 | }
|
---|
1263 | ctx->Color.DitherFlag = GL_FALSE;
|
---|
1264 | }
|
---|
1265 | }
|
---|
1266 |
|
---|
1267 |
|
---|
1268 |
|
---|
1269 |
|
---|
1270 | /*
|
---|
1271 | * Allocate the proxy textures. If we run out of memory part way through
|
---|
1272 | * the allocations clean up and return GL_FALSE.
|
---|
1273 | * Return: GL_TRUE=success, GL_FALSE=failure
|
---|
1274 | */
|
---|
1275 | static GLboolean alloc_proxy_textures( GLcontext *ctx )
|
---|
1276 | {
|
---|
1277 | GLboolean out_of_memory;
|
---|
1278 | GLint i;
|
---|
1279 |
|
---|
1280 | ctx->Texture.Proxy1D = gl_alloc_texture_object(NULL, 0, 1);
|
---|
1281 | if (!ctx->Texture.Proxy1D) {
|
---|
1282 | return GL_FALSE;
|
---|
1283 | }
|
---|
1284 |
|
---|
1285 | ctx->Texture.Proxy2D = gl_alloc_texture_object(NULL, 0, 2);
|
---|
1286 | if (!ctx->Texture.Proxy2D) {
|
---|
1287 | gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
|
---|
1288 | return GL_FALSE;
|
---|
1289 | }
|
---|
1290 |
|
---|
1291 | ctx->Texture.Proxy3D = gl_alloc_texture_object(NULL, 0, 3);
|
---|
1292 | if (!ctx->Texture.Proxy3D) {
|
---|
1293 | gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
|
---|
1294 | gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
|
---|
1295 | return GL_FALSE;
|
---|
1296 | }
|
---|
1297 |
|
---|
1298 | out_of_memory = GL_FALSE;
|
---|
1299 | for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
|
---|
1300 | ctx->Texture.Proxy1D->Image[i] = gl_alloc_texture_image();
|
---|
1301 | ctx->Texture.Proxy2D->Image[i] = gl_alloc_texture_image();
|
---|
1302 | ctx->Texture.Proxy3D->Image[i] = gl_alloc_texture_image();
|
---|
1303 | if (!ctx->Texture.Proxy1D->Image[i]
|
---|
1304 | || !ctx->Texture.Proxy2D->Image[i]
|
---|
1305 | || !ctx->Texture.Proxy3D->Image[i]) {
|
---|
1306 | out_of_memory = GL_TRUE;
|
---|
1307 | }
|
---|
1308 | }
|
---|
1309 | if (out_of_memory) {
|
---|
1310 | for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
|
---|
1311 | if (ctx->Texture.Proxy1D->Image[i]) {
|
---|
1312 | gl_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
|
---|
1313 | }
|
---|
1314 | if (ctx->Texture.Proxy2D->Image[i]) {
|
---|
1315 | gl_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
|
---|
1316 | }
|
---|
1317 | if (ctx->Texture.Proxy3D->Image[i]) {
|
---|
1318 | gl_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
|
---|
1319 | }
|
---|
1320 | }
|
---|
1321 | gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
|
---|
1322 | gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
|
---|
1323 | gl_free_texture_object(NULL, ctx->Texture.Proxy3D);
|
---|
1324 | return GL_FALSE;
|
---|
1325 | }
|
---|
1326 | else {
|
---|
1327 | return GL_TRUE;
|
---|
1328 | }
|
---|
1329 | }
|
---|
1330 |
|
---|
1331 |
|
---|
1332 |
|
---|
1333 | /*
|
---|
1334 | * Initialize a GLcontext struct.
|
---|
1335 | */
|
---|
1336 | GLboolean gl_initialize_context_data( GLcontext *ctx,
|
---|
1337 | GLvisual *visual,
|
---|
1338 | GLcontext *share_list,
|
---|
1339 | void *driver_ctx,
|
---|
1340 | GLboolean direct )
|
---|
1341 | {
|
---|
1342 | (void) direct; /* not used */
|
---|
1343 |
|
---|
1344 | /* misc one-time initializations */
|
---|
1345 | one_time_init();
|
---|
1346 |
|
---|
1347 | ctx->DriverCtx = driver_ctx;
|
---|
1348 | ctx->Visual = visual;
|
---|
1349 | ctx->DrawBuffer = NULL;
|
---|
1350 | ctx->ReadBuffer = NULL;
|
---|
1351 |
|
---|
1352 | ctx->VB = gl_vb_create_for_immediate( ctx );
|
---|
1353 | if (!ctx->VB) {
|
---|
1354 | FREE( ctx );
|
---|
1355 | return GL_FALSE;
|
---|
1356 | }
|
---|
1357 | ctx->input = ctx->VB->IM;
|
---|
1358 |
|
---|
1359 | ctx->PB = gl_alloc_pb();
|
---|
1360 | if (!ctx->PB) {
|
---|
1361 | FREE( ctx->VB );
|
---|
1362 | FREE( ctx );
|
---|
1363 | return GL_FALSE;
|
---|
1364 | }
|
---|
1365 |
|
---|
1366 | if (share_list) {
|
---|
1367 | /* share the group of display lists of another context */
|
---|
1368 | ctx->Shared = share_list->Shared;
|
---|
1369 | }
|
---|
1370 | else {
|
---|
1371 | /* allocate new group of display lists */
|
---|
1372 | ctx->Shared = alloc_shared_state();
|
---|
1373 | if (!ctx->Shared) {
|
---|
1374 | FREE(ctx->VB);
|
---|
1375 | FREE(ctx->PB);
|
---|
1376 | FREE(ctx);
|
---|
1377 | return GL_FALSE;
|
---|
1378 | }
|
---|
1379 | }
|
---|
1380 | _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
|
---|
1381 | ctx->Shared->RefCount++;
|
---|
1382 | _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
|
---|
1383 |
|
---|
1384 | init_attrib_groups( ctx );
|
---|
1385 |
|
---|
1386 | gl_reset_vb( ctx->VB );
|
---|
1387 | gl_reset_input( ctx );
|
---|
1388 |
|
---|
1389 | if (visual->DBflag) {
|
---|
1390 | ctx->Color.DrawBuffer = GL_BACK;
|
---|
1391 | ctx->Color.DriverDrawBuffer = GL_BACK_LEFT;
|
---|
1392 | ctx->Color.DrawDestMask = BACK_LEFT_BIT;
|
---|
1393 | ctx->Pixel.ReadBuffer = GL_BACK;
|
---|
1394 | ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT;
|
---|
1395 | }
|
---|
1396 | else {
|
---|
1397 | ctx->Color.DrawBuffer = GL_FRONT;
|
---|
1398 | ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT;
|
---|
1399 | ctx->Color.DrawDestMask = FRONT_LEFT_BIT;
|
---|
1400 | ctx->Pixel.ReadBuffer = GL_FRONT;
|
---|
1401 | ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT;
|
---|
1402 | }
|
---|
1403 |
|
---|
1404 | #ifdef PROFILE
|
---|
1405 | init_timings( ctx );
|
---|
1406 | #endif
|
---|
1407 |
|
---|
1408 | if (!alloc_proxy_textures(ctx)) {
|
---|
1409 | free_shared_state(ctx, ctx->Shared);
|
---|
1410 | FREE(ctx->VB);
|
---|
1411 | FREE(ctx->PB);
|
---|
1412 | FREE(ctx);
|
---|
1413 | return GL_FALSE;
|
---|
1414 | }
|
---|
1415 |
|
---|
1416 | /* setup API dispatch tables */
|
---|
1417 | ctx->Exec = (struct _glapi_table *) CALLOC(_glapi_get_dispatch_table_size() * sizeof(void *));
|
---|
1418 | ctx->Save = (struct _glapi_table *) CALLOC(_glapi_get_dispatch_table_size() * sizeof(void *));
|
---|
1419 | if (!ctx->Exec || !ctx->Save) {
|
---|
1420 | free_shared_state(ctx, ctx->Shared);
|
---|
1421 | FREE(ctx->VB);
|
---|
1422 | FREE(ctx->PB);
|
---|
1423 | if (ctx->Exec)
|
---|
1424 | FREE(ctx->Exec);
|
---|
1425 | FREE(ctx);
|
---|
1426 | }
|
---|
1427 | _mesa_init_exec_table( ctx->Exec );
|
---|
1428 | _mesa_init_dlist_table( ctx->Save );
|
---|
1429 | ctx->CurrentDispatch = ctx->Exec;
|
---|
1430 |
|
---|
1431 | return GL_TRUE;
|
---|
1432 | }
|
---|
1433 |
|
---|
1434 |
|
---|
1435 |
|
---|
1436 | /*
|
---|
1437 | * Allocate and initialize a GLcontext structure.
|
---|
1438 | * Input: visual - a GLvisual pointer
|
---|
1439 | * sharelist - another context to share display lists with or NULL
|
---|
1440 | * driver_ctx - pointer to device driver's context state struct
|
---|
1441 | * Return: pointer to a new gl_context struct or NULL if error.
|
---|
1442 | */
|
---|
1443 | GLcontext *gl_create_context( GLvisual *visual,
|
---|
1444 | GLcontext *share_list,
|
---|
1445 | void *driver_ctx,
|
---|
1446 | GLboolean direct )
|
---|
1447 | {
|
---|
1448 | GLcontext *ctx = (GLcontext *) CALLOC( sizeof(GLcontext) );
|
---|
1449 | if (!ctx) {
|
---|
1450 | return NULL;
|
---|
1451 | }
|
---|
1452 |
|
---|
1453 | if (gl_initialize_context_data(ctx, visual, share_list,
|
---|
1454 | driver_ctx, direct)) {
|
---|
1455 | return ctx;
|
---|
1456 | }
|
---|
1457 | else {
|
---|
1458 | FREE(ctx);
|
---|
1459 | return NULL;
|
---|
1460 | }
|
---|
1461 | }
|
---|
1462 |
|
---|
1463 |
|
---|
1464 |
|
---|
1465 | /*
|
---|
1466 | * Free the data associated with the given context.
|
---|
1467 | * But don't free() the GLcontext struct itself!
|
---|
1468 | */
|
---|
1469 | void gl_free_context_data( GLcontext *ctx )
|
---|
1470 | {
|
---|
1471 | struct gl_shine_tab *s, *tmps;
|
---|
1472 | GLuint i, j;
|
---|
1473 |
|
---|
1474 | /* if we're destroying the current context, unbind it first */
|
---|
1475 | if (ctx == gl_get_current_context()) {
|
---|
1476 | gl_make_current(NULL, NULL);
|
---|
1477 | }
|
---|
1478 |
|
---|
1479 | #ifdef PROFILE
|
---|
1480 | if (getenv("MESA_PROFILE")) {
|
---|
1481 | print_timings( ctx );
|
---|
1482 | }
|
---|
1483 | #endif
|
---|
1484 |
|
---|
1485 | gl_matrix_dtr( &ctx->ModelView );
|
---|
1486 | for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
|
---|
1487 | gl_matrix_dtr( &ctx->ModelViewStack[i] );
|
---|
1488 | }
|
---|
1489 | gl_matrix_dtr( &ctx->ProjectionMatrix );
|
---|
1490 | for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
|
---|
1491 | gl_matrix_dtr( &ctx->ProjectionStack[i] );
|
---|
1492 | }
|
---|
1493 | for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
|
---|
1494 | gl_matrix_dtr( &ctx->TextureMatrix[i] );
|
---|
1495 | for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
|
---|
1496 | gl_matrix_dtr( &ctx->TextureStack[i][j] );
|
---|
1497 | }
|
---|
1498 | }
|
---|
1499 |
|
---|
1500 | FREE( ctx->PB );
|
---|
1501 |
|
---|
1502 | if(ctx->input != ctx->VB->IM)
|
---|
1503 | gl_immediate_free( ctx->input );
|
---|
1504 |
|
---|
1505 | gl_vb_free( ctx->VB );
|
---|
1506 |
|
---|
1507 | _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
|
---|
1508 | ctx->Shared->RefCount--;
|
---|
1509 | ASSERT(ctx->Shared->RefCount >= 0);
|
---|
1510 | _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
|
---|
1511 | if (ctx->Shared->RefCount == 0) {
|
---|
1512 | /* free shared state */
|
---|
1513 | free_shared_state( ctx, ctx->Shared );
|
---|
1514 | }
|
---|
1515 |
|
---|
1516 | foreach_s( s, tmps, ctx->ShineTabList ) {
|
---|
1517 | FREE( s );
|
---|
1518 | }
|
---|
1519 | FREE( ctx->ShineTabList );
|
---|
1520 |
|
---|
1521 | /* Free proxy texture objects */
|
---|
1522 | gl_free_texture_object( NULL, ctx->Texture.Proxy1D );
|
---|
1523 | gl_free_texture_object( NULL, ctx->Texture.Proxy2D );
|
---|
1524 | gl_free_texture_object( NULL, ctx->Texture.Proxy3D );
|
---|
1525 |
|
---|
1526 | /* Free evaluator data */
|
---|
1527 | if (ctx->EvalMap.Map1Vertex3.Points)
|
---|
1528 | FREE( ctx->EvalMap.Map1Vertex3.Points );
|
---|
1529 | if (ctx->EvalMap.Map1Vertex4.Points)
|
---|
1530 | FREE( ctx->EvalMap.Map1Vertex4.Points );
|
---|
1531 | if (ctx->EvalMap.Map1Index.Points)
|
---|
1532 | FREE( ctx->EvalMap.Map1Index.Points );
|
---|
1533 | if (ctx->EvalMap.Map1Color4.Points)
|
---|
1534 | FREE( ctx->EvalMap.Map1Color4.Points );
|
---|
1535 | if (ctx->EvalMap.Map1Normal.Points)
|
---|
1536 | FREE( ctx->EvalMap.Map1Normal.Points );
|
---|
1537 | if (ctx->EvalMap.Map1Texture1.Points)
|
---|
1538 | FREE( ctx->EvalMap.Map1Texture1.Points );
|
---|
1539 | if (ctx->EvalMap.Map1Texture2.Points)
|
---|
1540 | FREE( ctx->EvalMap.Map1Texture2.Points );
|
---|
1541 | if (ctx->EvalMap.Map1Texture3.Points)
|
---|
1542 | FREE( ctx->EvalMap.Map1Texture3.Points );
|
---|
1543 | if (ctx->EvalMap.Map1Texture4.Points)
|
---|
1544 | FREE( ctx->EvalMap.Map1Texture4.Points );
|
---|
1545 |
|
---|
1546 | if (ctx->EvalMap.Map2Vertex3.Points)
|
---|
1547 | FREE( ctx->EvalMap.Map2Vertex3.Points );
|
---|
1548 | if (ctx->EvalMap.Map2Vertex4.Points)
|
---|
1549 | FREE( ctx->EvalMap.Map2Vertex4.Points );
|
---|
1550 | if (ctx->EvalMap.Map2Index.Points)
|
---|
1551 | FREE( ctx->EvalMap.Map2Index.Points );
|
---|
1552 | if (ctx->EvalMap.Map2Color4.Points)
|
---|
1553 | FREE( ctx->EvalMap.Map2Color4.Points );
|
---|
1554 | if (ctx->EvalMap.Map2Normal.Points)
|
---|
1555 | FREE( ctx->EvalMap.Map2Normal.Points );
|
---|
1556 | if (ctx->EvalMap.Map2Texture1.Points)
|
---|
1557 | FREE( ctx->EvalMap.Map2Texture1.Points );
|
---|
1558 | if (ctx->EvalMap.Map2Texture2.Points)
|
---|
1559 | FREE( ctx->EvalMap.Map2Texture2.Points );
|
---|
1560 | if (ctx->EvalMap.Map2Texture3.Points)
|
---|
1561 | FREE( ctx->EvalMap.Map2Texture3.Points );
|
---|
1562 | if (ctx->EvalMap.Map2Texture4.Points)
|
---|
1563 | FREE( ctx->EvalMap.Map2Texture4.Points );
|
---|
1564 |
|
---|
1565 | /* Free cache of immediate buffers. */
|
---|
1566 | while (ctx->nr_im_queued-- > 0) {
|
---|
1567 | struct immediate * next = ctx->freed_im_queue->next;
|
---|
1568 | FREE( ctx->freed_im_queue );
|
---|
1569 | ctx->freed_im_queue = next;
|
---|
1570 | }
|
---|
1571 | gl_extensions_dtr(ctx);
|
---|
1572 |
|
---|
1573 | FREE(ctx->Exec);
|
---|
1574 | FREE(ctx->Save);
|
---|
1575 | }
|
---|
1576 |
|
---|
1577 |
|
---|
1578 |
|
---|
1579 | /*
|
---|
1580 | * Destroy a GLcontext structure.
|
---|
1581 | */
|
---|
1582 | void gl_destroy_context( GLcontext *ctx )
|
---|
1583 | {
|
---|
1584 | if (ctx) {
|
---|
1585 | gl_free_context_data(ctx);
|
---|
1586 | FREE( (void *) ctx );
|
---|
1587 | }
|
---|
1588 | }
|
---|
1589 |
|
---|
1590 |
|
---|
1591 |
|
---|
1592 | /*
|
---|
1593 | * Called by the driver after both the context and driver are fully
|
---|
1594 | * initialized. Currently just reads the config file.
|
---|
1595 | */
|
---|
1596 | void gl_context_initialize( GLcontext *ctx )
|
---|
1597 | {
|
---|
1598 | gl_read_config_file( ctx );
|
---|
1599 | }
|
---|
1600 |
|
---|
1601 |
|
---|
1602 |
|
---|
1603 | /*
|
---|
1604 | * Copy attribute groups from one context to another.
|
---|
1605 | * Input: src - source context
|
---|
1606 | * dst - destination context
|
---|
1607 | * mask - bitwise OR of GL_*_BIT flags
|
---|
1608 | */
|
---|
1609 | void gl_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
|
---|
1610 | {
|
---|
1611 | if (mask & GL_ACCUM_BUFFER_BIT) {
|
---|
1612 | MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
|
---|
1613 | }
|
---|
1614 | if (mask & GL_COLOR_BUFFER_BIT) {
|
---|
1615 | MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
|
---|
1616 | }
|
---|
1617 | if (mask & GL_CURRENT_BIT) {
|
---|
1618 | MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
|
---|
1619 | }
|
---|
1620 | if (mask & GL_DEPTH_BUFFER_BIT) {
|
---|
1621 | MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
|
---|
1622 | }
|
---|
1623 | if (mask & GL_ENABLE_BIT) {
|
---|
1624 | /* no op */
|
---|
1625 | }
|
---|
1626 | if (mask & GL_EVAL_BIT) {
|
---|
1627 | MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
|
---|
1628 | }
|
---|
1629 | if (mask & GL_FOG_BIT) {
|
---|
1630 | MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
|
---|
1631 | }
|
---|
1632 | if (mask & GL_HINT_BIT) {
|
---|
1633 | MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
|
---|
1634 | }
|
---|
1635 | if (mask & GL_LIGHTING_BIT) {
|
---|
1636 | MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
|
---|
1637 | /* gl_reinit_light_attrib( &dst->Light ); */
|
---|
1638 | }
|
---|
1639 | if (mask & GL_LINE_BIT) {
|
---|
1640 | MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
|
---|
1641 | }
|
---|
1642 | if (mask & GL_LIST_BIT) {
|
---|
1643 | MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
|
---|
1644 | }
|
---|
1645 | if (mask & GL_PIXEL_MODE_BIT) {
|
---|
1646 | MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
|
---|
1647 | }
|
---|
1648 | if (mask & GL_POINT_BIT) {
|
---|
1649 | MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
|
---|
1650 | }
|
---|
1651 | if (mask & GL_POLYGON_BIT) {
|
---|
1652 | MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
|
---|
1653 | }
|
---|
1654 | if (mask & GL_POLYGON_STIPPLE_BIT) {
|
---|
1655 | #ifdef __WIN32OS2__
|
---|
1656 | MEMCPY( &dst->PolygonStipple, &src->PolygonStipple, 32*sizeof(GLint) );
|
---|
1657 | #else
|
---|
1658 | /* Use loop instead of MEMCPY due to problem with Portland Group's
|
---|
1659 | * C compiler. Reported by John Stone.
|
---|
1660 | */
|
---|
1661 | int i;
|
---|
1662 | for (i=0;i<32;i++) {
|
---|
1663 | dst->PolygonStipple[i] = src->PolygonStipple[i];
|
---|
1664 | }
|
---|
1665 | #endif
|
---|
1666 | }
|
---|
1667 | if (mask & GL_SCISSOR_BIT) {
|
---|
1668 | MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
|
---|
1669 | }
|
---|
1670 | if (mask & GL_STENCIL_BUFFER_BIT) {
|
---|
1671 | MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
|
---|
1672 | }
|
---|
1673 | if (mask & GL_TEXTURE_BIT) {
|
---|
1674 | MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
|
---|
1675 | }
|
---|
1676 | if (mask & GL_TRANSFORM_BIT) {
|
---|
1677 | MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
|
---|
1678 | }
|
---|
1679 | if (mask & GL_VIEWPORT_BIT) {
|
---|
1680 | MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
|
---|
1681 | }
|
---|
1682 | }
|
---|
1683 |
|
---|
1684 |
|
---|
1685 | /*
|
---|
1686 | * Set the current context, binding the given frame buffer to the context.
|
---|
1687 | */
|
---|
1688 | void gl_make_current( GLcontext *newCtx, GLframebuffer *buffer )
|
---|
1689 | {
|
---|
1690 | gl_make_current2( newCtx, buffer, buffer );
|
---|
1691 | }
|
---|
1692 |
|
---|
1693 |
|
---|
1694 | /*
|
---|
1695 | * Bind the given context to the given draw-buffer and read-buffer
|
---|
1696 | * and make it the current context for this thread.
|
---|
1697 | */
|
---|
1698 | void gl_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer,
|
---|
1699 | GLframebuffer *readBuffer )
|
---|
1700 | {
|
---|
1701 | #if 0
|
---|
1702 | GLcontext *oldCtx = gl_get_context();
|
---|
1703 |
|
---|
1704 | /* Flush the old context
|
---|
1705 | */
|
---|
1706 | if (oldCtx) {
|
---|
1707 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(oldCtx, "gl_make_current");
|
---|
1708 |
|
---|
1709 | /* unbind frame buffers from context */
|
---|
1710 | if (oldCtx->DrawBuffer) {
|
---|
1711 | oldCtx->DrawBuffer = NULL;
|
---|
1712 | }
|
---|
1713 | if (oldCtx->ReadBuffer) {
|
---|
1714 | oldCtx->ReadBuffer = NULL;
|
---|
1715 | }
|
---|
1716 | }
|
---|
1717 | #endif
|
---|
1718 |
|
---|
1719 | /* We call this function periodically (just here for now) in
|
---|
1720 | * order to detect when multithreading has begun.
|
---|
1721 | */
|
---|
1722 | _glapi_check_multithread();
|
---|
1723 |
|
---|
1724 | _glapi_set_context((void *) newCtx);
|
---|
1725 | ASSERT(gl_get_current_context() == newCtx);
|
---|
1726 | if (newCtx) {
|
---|
1727 | SET_IMMEDIATE(newCtx, newCtx->input);
|
---|
1728 | _glapi_set_dispatch(newCtx->CurrentDispatch);
|
---|
1729 | }
|
---|
1730 | else {
|
---|
1731 | _glapi_set_dispatch(NULL); /* none current */
|
---|
1732 | }
|
---|
1733 |
|
---|
1734 | if (MESA_VERBOSE) fprintf(stderr, "gl_make_current()\n");
|
---|
1735 |
|
---|
1736 | if (newCtx && drawBuffer && readBuffer) {
|
---|
1737 | /* TODO: check if newCtx and buffer's visual match??? */
|
---|
1738 | newCtx->DrawBuffer = drawBuffer;
|
---|
1739 | newCtx->ReadBuffer = readBuffer;
|
---|
1740 | newCtx->NewState = NEW_ALL; /* just to be safe */
|
---|
1741 | gl_update_state( newCtx );
|
---|
1742 | }
|
---|
1743 |
|
---|
1744 | /* We can use this to help debug user's problems. Tell the to set
|
---|
1745 | * the MESA_INFO env variable before running their app. Then the
|
---|
1746 | * first time each context is made current we'll print some useful
|
---|
1747 | * information.
|
---|
1748 | */
|
---|
1749 | if (newCtx && newCtx->FirstTimeCurrent) {
|
---|
1750 | if (getenv("MESA_INFO")) {
|
---|
1751 | fprintf(stderr, "Mesa GL_VERSION = %s\n", (char *) _mesa_GetString(GL_VERSION));
|
---|
1752 | fprintf(stderr, "Mesa GL_RENDERER = %s\n", (char *) _mesa_GetString(GL_RENDERER));
|
---|
1753 | fprintf(stderr, "Mesa GL_VENDOR = %s\n", (char *) _mesa_GetString(GL_VENDOR));
|
---|
1754 | fprintf(stderr, "Mesa GL_EXTENSIONS = %s\n", (char *) _mesa_GetString(GL_EXTENSIONS));
|
---|
1755 | #if defined(THREADS)
|
---|
1756 | fprintf(stderr, "Mesa thread-safe: YES\n");
|
---|
1757 | #else
|
---|
1758 | fprintf(stderr, "Mesa thread-safe: NO\n");
|
---|
1759 | #endif
|
---|
1760 | #if defined(USE_X86_ASM)
|
---|
1761 | fprintf(stderr, "Mesa x86-optimized: YES\n");
|
---|
1762 | #else
|
---|
1763 | fprintf(stderr, "Mesa x86-optimized: NO\n");
|
---|
1764 | #endif
|
---|
1765 | }
|
---|
1766 | newCtx->FirstTimeCurrent = GL_FALSE;
|
---|
1767 | }
|
---|
1768 | }
|
---|
1769 |
|
---|
1770 |
|
---|
1771 |
|
---|
1772 | /*
|
---|
1773 | * Return current context handle for the calling thread.
|
---|
1774 | * This isn't the fastest way to get the current context.
|
---|
1775 | * If you need speed, see the GET_CURRENT_CONTEXT() macro in context.h
|
---|
1776 | */
|
---|
1777 | GLcontext *gl_get_current_context( void )
|
---|
1778 | {
|
---|
1779 | return (GLcontext *) _glapi_get_context();
|
---|
1780 | }
|
---|
1781 |
|
---|
1782 |
|
---|
1783 |
|
---|
1784 | /*
|
---|
1785 | * This should be called by device drivers just before they do a
|
---|
1786 | * swapbuffers. Any pending rendering commands will be executed.
|
---|
1787 | */
|
---|
1788 | void
|
---|
1789 | _mesa_swapbuffers(GLcontext *ctx)
|
---|
1790 | {
|
---|
1791 | FLUSH_VB( ctx, "swap buffers" );
|
---|
1792 | }
|
---|
1793 |
|
---|
1794 |
|
---|
1795 |
|
---|
1796 | /*
|
---|
1797 | * Return pointer to this context's current API dispatch table.
|
---|
1798 | * It'll either be the immediate-mode execute dispatcher or the
|
---|
1799 | * display list compile dispatcher.
|
---|
1800 | */
|
---|
1801 | struct _glapi_table *
|
---|
1802 | _mesa_get_dispatch(GLcontext *ctx)
|
---|
1803 | {
|
---|
1804 | return ctx->CurrentDispatch;
|
---|
1805 | }
|
---|
1806 |
|
---|
1807 |
|
---|
1808 |
|
---|
1809 | /**********************************************************************/
|
---|
1810 | /***** Miscellaneous functions *****/
|
---|
1811 | /**********************************************************************/
|
---|
1812 |
|
---|
1813 |
|
---|
1814 | /*
|
---|
1815 | * This function is called when the Mesa user has stumbled into a code
|
---|
1816 | * path which may not be implemented fully or correctly.
|
---|
1817 | */
|
---|
1818 | void gl_problem( const GLcontext *ctx, const char *s )
|
---|
1819 | {
|
---|
1820 | #ifdef __WIN32OS2__
|
---|
1821 | fprintf( stderr,"OPENGL32: Mesa implementation error: %s\n", s );
|
---|
1822 | fprintf( stderr,"OPENGL32: Report to J.vandenHorn@fibre.a2000.nl\n" );
|
---|
1823 | #else
|
---|
1824 | fprintf( stderr, "Mesa implementation error: %s\n", s );
|
---|
1825 | fprintf( stderr, "Report to mesa-bugs@mesa3d.org\n" );
|
---|
1826 | (void) ctx;
|
---|
1827 | #endif
|
---|
1828 | }
|
---|
1829 |
|
---|
1830 |
|
---|
1831 |
|
---|
1832 | /*
|
---|
1833 | * This is called to inform the user that he or she has tried to do
|
---|
1834 | * something illogical or if there's likely a bug in their program
|
---|
1835 | * (like enabled depth testing without a depth buffer).
|
---|
1836 | */
|
---|
1837 | void gl_warning( const GLcontext *ctx, const char *s )
|
---|
1838 | {
|
---|
1839 | GLboolean debug;
|
---|
1840 | #ifdef DEBUG
|
---|
1841 | debug = GL_TRUE;
|
---|
1842 | #else
|
---|
1843 | if (getenv("MESA_DEBUG")) {
|
---|
1844 | debug = GL_TRUE;
|
---|
1845 | }
|
---|
1846 | else {
|
---|
1847 | debug = GL_FALSE;
|
---|
1848 | }
|
---|
1849 | #endif
|
---|
1850 | #ifdef __WIN32OS2__
|
---|
1851 | fprintf( stderr,"OPENGL32: Mesa warning: %s\n", s );
|
---|
1852 | #else
|
---|
1853 | if (debug) {
|
---|
1854 | fprintf( stderr, "Mesa warning: %s\n", s );
|
---|
1855 | }
|
---|
1856 | #endif
|
---|
1857 | (void) ctx;
|
---|
1858 | }
|
---|
1859 |
|
---|
1860 |
|
---|
1861 |
|
---|
1862 | /*
|
---|
1863 | * Compile an error into current display list.
|
---|
1864 | */
|
---|
1865 | void gl_compile_error( GLcontext *ctx, GLenum error, const char *s )
|
---|
1866 | {
|
---|
1867 | if (ctx->CompileFlag)
|
---|
1868 | gl_save_error( ctx, error, s );
|
---|
1869 |
|
---|
1870 | if (ctx->ExecuteFlag)
|
---|
1871 | gl_error( ctx, error, s );
|
---|
1872 | }
|
---|
1873 |
|
---|
1874 |
|
---|
1875 |
|
---|
1876 | /*
|
---|
1877 | * This is Mesa's error handler. Normally, all that's done is the updating
|
---|
1878 | * of the current error value. If Mesa is compiled with -DDEBUG or if the
|
---|
1879 | * environment variable "MESA_DEBUG" is defined then a real error message
|
---|
1880 | * is printed to stderr.
|
---|
1881 | * Input: error - the error value
|
---|
1882 | * s - a diagnostic string
|
---|
1883 | */
|
---|
1884 | void gl_error( GLcontext *ctx, GLenum error, const char *s )
|
---|
1885 | {
|
---|
1886 | GLboolean debug;
|
---|
1887 |
|
---|
1888 | #ifdef DEBUG
|
---|
1889 | debug = GL_TRUE;
|
---|
1890 | #else
|
---|
1891 | if (getenv("MESA_DEBUG")) {
|
---|
1892 | debug = GL_TRUE;
|
---|
1893 | }
|
---|
1894 | else {
|
---|
1895 | debug = GL_FALSE;
|
---|
1896 | }
|
---|
1897 | #endif
|
---|
1898 | #ifdef __WIN32OS2__
|
---|
1899 | {
|
---|
1900 | #else
|
---|
1901 | if (debug) {
|
---|
1902 | #endif
|
---|
1903 | char errstr[1000];
|
---|
1904 |
|
---|
1905 | switch (error) {
|
---|
1906 | case GL_NO_ERROR:
|
---|
1907 | strcpy( errstr, "GL_NO_ERROR" );
|
---|
1908 | break;
|
---|
1909 | case GL_INVALID_VALUE:
|
---|
1910 | strcpy( errstr, "GL_INVALID_VALUE" );
|
---|
1911 | break;
|
---|
1912 | case GL_INVALID_ENUM:
|
---|
1913 | strcpy( errstr, "GL_INVALID_ENUM" );
|
---|
1914 | break;
|
---|
1915 | case GL_INVALID_OPERATION:
|
---|
1916 | strcpy( errstr, "GL_INVALID_OPERATION" );
|
---|
1917 | break;
|
---|
1918 | case GL_STACK_OVERFLOW:
|
---|
1919 | strcpy( errstr, "GL_STACK_OVERFLOW" );
|
---|
1920 | break;
|
---|
1921 | case GL_STACK_UNDERFLOW:
|
---|
1922 | strcpy( errstr, "GL_STACK_UNDERFLOW" );
|
---|
1923 | break;
|
---|
1924 | case GL_OUT_OF_MEMORY:
|
---|
1925 | strcpy( errstr, "GL_OUT_OF_MEMORY" );
|
---|
1926 | break;
|
---|
1927 | default:
|
---|
1928 | strcpy( errstr, "unknown" );
|
---|
1929 | break;
|
---|
1930 | }
|
---|
1931 | #ifdef __WIN32OS2__
|
---|
1932 | fprintf( stderr, "OPENGL32: Mesa user error: %s in %s\n", errstr, s );
|
---|
1933 | #else
|
---|
1934 | fprintf( stderr, "Mesa user error: %s in %s\n", errstr, s );
|
---|
1935 | #endif
|
---|
1936 | }
|
---|
1937 |
|
---|
1938 | if (ctx->ErrorValue==GL_NO_ERROR) {
|
---|
1939 | ctx->ErrorValue = error;
|
---|
1940 | }
|
---|
1941 |
|
---|
1942 | /* Call device driver's error handler, if any. This is used on the Mac. */
|
---|
1943 | if (ctx->Driver.Error) {
|
---|
1944 | (*ctx->Driver.Error)( ctx );
|
---|
1945 | }
|
---|
1946 | }
|
---|
1947 |
|
---|
1948 |
|
---|
1949 |
|
---|
1950 | void
|
---|
1951 | _mesa_Finish( void )
|
---|
1952 | {
|
---|
1953 | GET_CURRENT_CONTEXT(ctx);
|
---|
1954 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFinish");
|
---|
1955 | if (ctx->Driver.Finish) {
|
---|
1956 | (*ctx->Driver.Finish)( ctx );
|
---|
1957 | }
|
---|
1958 | }
|
---|
1959 |
|
---|
1960 |
|
---|
1961 |
|
---|
1962 | void
|
---|
1963 | _mesa_Flush( void )
|
---|
1964 | {
|
---|
1965 | GET_CURRENT_CONTEXT(ctx);
|
---|
1966 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFlush");
|
---|
1967 | if (ctx->Driver.Flush) {
|
---|
1968 | (*ctx->Driver.Flush)( ctx );
|
---|
1969 | }
|
---|
1970 | }
|
---|