1 | /* $Id: context.c,v 1.2 2000-03-01 18:49:25 jeroen Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Mesa 3-D graphics library
|
---|
5 | * Version: 3.1
|
---|
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 | /* $XFree86: xc/lib/GL/mesa/src/context.c,v 1.4 1999/04/04 00:20:21 dawes Exp $ */
|
---|
29 |
|
---|
30 | /*
|
---|
31 | * If multi-threading is enabled (-DTHREADS) then each thread has it's
|
---|
32 | * own rendering context. A thread obtains the pointer to its GLcontext
|
---|
33 | * with the gl_get_thread_context() function. Otherwise, the global
|
---|
34 | * pointer, CC, points to the current context used by all threads in
|
---|
35 | * the address space.
|
---|
36 | */
|
---|
37 |
|
---|
38 | #ifdef __WIN32OS2__
|
---|
39 | #include <os2win.h>
|
---|
40 | #ifdef DIVE
|
---|
41 | #include "types.h"
|
---|
42 | #include "wmesadef.h"
|
---|
43 | #include "mesadive.h"
|
---|
44 | #endif
|
---|
45 | #endif
|
---|
46 |
|
---|
47 | #ifdef PC_HEADER
|
---|
48 | #include "all.h"
|
---|
49 | #else
|
---|
50 | #ifndef XFree86Server
|
---|
51 | #include <assert.h>
|
---|
52 | #include <math.h>
|
---|
53 | #include <stdio.h>
|
---|
54 | #include <stdlib.h>
|
---|
55 | #include <string.h>
|
---|
56 | #else
|
---|
57 | #include "GL/xf86glx.h"
|
---|
58 | #endif
|
---|
59 | #include "accum.h"
|
---|
60 | #include "alphabuf.h"
|
---|
61 | #include "api.h"
|
---|
62 | #include "clip.h"
|
---|
63 | #include "context.h"
|
---|
64 | #include "cva.h"
|
---|
65 | #include "depth.h"
|
---|
66 | #include "dlist.h"
|
---|
67 | #include "eval.h"
|
---|
68 | #include "enums.h"
|
---|
69 | #include "extensions.h"
|
---|
70 | #include "fog.h"
|
---|
71 | #include "get.h"
|
---|
72 | #include "hash.h"
|
---|
73 | #include "light.h"
|
---|
74 | #include "lines.h"
|
---|
75 | #include "dlist.h"
|
---|
76 | #include "macros.h"
|
---|
77 | #include "matrix.h"
|
---|
78 | #include "mmath.h"
|
---|
79 | #include "pb.h"
|
---|
80 | #include "pipeline.h"
|
---|
81 | #include "points.h"
|
---|
82 | #include "pointers.h"
|
---|
83 | #include "quads.h"
|
---|
84 | #include "shade.h"
|
---|
85 | #include "simple_list.h"
|
---|
86 | #include "stencil.h"
|
---|
87 | #include "stages.h"
|
---|
88 | #include "triangle.h"
|
---|
89 | #include "translate.h"
|
---|
90 | #include "teximage.h"
|
---|
91 | #include "texobj.h"
|
---|
92 | #include "texstate.h"
|
---|
93 | #include "texture.h"
|
---|
94 | #include "types.h"
|
---|
95 | #include "varray.h"
|
---|
96 | #include "vb.h"
|
---|
97 | #include "vbcull.h"
|
---|
98 | #include "vbfill.h"
|
---|
99 | #include "vbrender.h"
|
---|
100 | #include "vbxform.h"
|
---|
101 | #include "vertices.h"
|
---|
102 | #include "xform.h"
|
---|
103 | #include "config.h"
|
---|
104 | #endif
|
---|
105 |
|
---|
106 |
|
---|
107 | /*
|
---|
108 | * Memory allocation functions. Called via the MALLOC, CALLOC and
|
---|
109 | * FREE macros when DEBUG symbol is defined.
|
---|
110 | * You might want to set breakpoints on these functions or plug in
|
---|
111 | * other memory allocation functions. The Mesa sources should only
|
---|
112 | * use the MALLOC and FREE macros (which could also be overriden).
|
---|
113 | *
|
---|
114 | * XXX these functions should probably go into a new glmemory.c file.
|
---|
115 | */
|
---|
116 |
|
---|
117 | /*
|
---|
118 | * Allocate memory (uninitialized)
|
---|
119 | */
|
---|
120 | void *gl_malloc(size_t bytes)
|
---|
121 | {
|
---|
122 | return malloc(bytes);
|
---|
123 | }
|
---|
124 |
|
---|
125 | /*
|
---|
126 | * Allocate memory and initialize to zero.
|
---|
127 | */
|
---|
128 | void *gl_calloc(size_t bytes)
|
---|
129 | {
|
---|
130 | return calloc(1, bytes);
|
---|
131 | }
|
---|
132 |
|
---|
133 | /*
|
---|
134 | * Free memory
|
---|
135 | */
|
---|
136 | void gl_free(void *ptr)
|
---|
137 | {
|
---|
138 | free(ptr);
|
---|
139 | }
|
---|
140 |
|
---|
141 |
|
---|
142 | /**********************************************************************/
|
---|
143 | /***** Context and Thread management *****/
|
---|
144 | /**********************************************************************/
|
---|
145 |
|
---|
146 |
|
---|
147 | #ifdef THREADS
|
---|
148 |
|
---|
149 | #include "mthreads.h" /* Mesa platform independent threads interface*/
|
---|
150 |
|
---|
151 | static MesaTSD mesa_ctx_tsd;
|
---|
152 |
|
---|
153 | static void mesa_ctx_thread_init() {
|
---|
154 | MesaInitTSD(&mesa_ctx_tsd);
|
---|
155 | }
|
---|
156 |
|
---|
157 | GLcontext *gl_get_thread_context( void ) {
|
---|
158 | return (GLcontext *) MesaGetTSD(&mesa_ctx_tsd);
|
---|
159 | }
|
---|
160 |
|
---|
161 | static void set_thread_context( GLcontext *ctx ) {
|
---|
162 | MesaSetTSD(&mesa_ctx_tsd, ctx, mesa_ctx_thread_init);
|
---|
163 | }
|
---|
164 |
|
---|
165 |
|
---|
166 | #else
|
---|
167 |
|
---|
168 | /* One Current Context pointer for all threads in the address space */
|
---|
169 | GLcontext *CC = NULL;
|
---|
170 | struct immediate *CURRENT_INPUT = NULL;
|
---|
171 |
|
---|
172 | #endif /*THREADS*/
|
---|
173 |
|
---|
174 |
|
---|
175 |
|
---|
176 |
|
---|
177 | /**********************************************************************/
|
---|
178 | /***** Profiling functions *****/
|
---|
179 | /**********************************************************************/
|
---|
180 |
|
---|
181 | #ifdef PROFILE
|
---|
182 |
|
---|
183 | #include <sys/times.h>
|
---|
184 | #include <sys/param.h>
|
---|
185 |
|
---|
186 |
|
---|
187 | /*
|
---|
188 | * Return system time in seconds.
|
---|
189 | * NOTE: this implementation may not be very portable!
|
---|
190 | */
|
---|
191 | GLdouble gl_time( void )
|
---|
192 | {
|
---|
193 | static GLdouble prev_time = 0.0;
|
---|
194 | static GLdouble time;
|
---|
195 | struct tms tm;
|
---|
196 | clock_t clk;
|
---|
197 |
|
---|
198 | clk = times(&tm);
|
---|
199 |
|
---|
200 | #ifdef CLK_TCK
|
---|
201 | time = (double)clk / (double)CLK_TCK;
|
---|
202 | #else
|
---|
203 | time = (double)clk / (double)HZ;
|
---|
204 | #endif
|
---|
205 |
|
---|
206 | if (time>prev_time) {
|
---|
207 | prev_time = time;
|
---|
208 | return time;
|
---|
209 | }
|
---|
210 | else {
|
---|
211 | return prev_time;
|
---|
212 | }
|
---|
213 | }
|
---|
214 |
|
---|
215 | /*
|
---|
216 | * Reset the timing/profiling counters
|
---|
217 | */
|
---|
218 | static void init_timings( GLcontext *ctx )
|
---|
219 | {
|
---|
220 | ctx->BeginEndCount = 0;
|
---|
221 | ctx->BeginEndTime = 0.0;
|
---|
222 | ctx->VertexCount = 0;
|
---|
223 | ctx->VertexTime = 0.0;
|
---|
224 | ctx->PointCount = 0;
|
---|
225 | ctx->PointTime = 0.0;
|
---|
226 | ctx->LineCount = 0;
|
---|
227 | ctx->LineTime = 0.0;
|
---|
228 | ctx->PolygonCount = 0;
|
---|
229 | ctx->PolygonTime = 0.0;
|
---|
230 | ctx->ClearCount = 0;
|
---|
231 | ctx->ClearTime = 0.0;
|
---|
232 | ctx->SwapCount = 0;
|
---|
233 | ctx->SwapTime = 0.0;
|
---|
234 | }
|
---|
235 |
|
---|
236 |
|
---|
237 | /*
|
---|
238 | * Print the accumulated timing/profiling data.
|
---|
239 | */
|
---|
240 | static void print_timings( GLcontext *ctx )
|
---|
241 | {
|
---|
242 | GLdouble beginendrate;
|
---|
243 | GLdouble vertexrate;
|
---|
244 | GLdouble pointrate;
|
---|
245 | GLdouble linerate;
|
---|
246 | GLdouble polygonrate;
|
---|
247 | GLdouble overhead;
|
---|
248 | GLdouble clearrate;
|
---|
249 | GLdouble swaprate;
|
---|
250 | GLdouble avgvertices;
|
---|
251 |
|
---|
252 | if (ctx->BeginEndTime>0.0) {
|
---|
253 | beginendrate = ctx->BeginEndCount / ctx->BeginEndTime;
|
---|
254 | }
|
---|
255 | else {
|
---|
256 | beginendrate = 0.0;
|
---|
257 | }
|
---|
258 | if (ctx->VertexTime>0.0) {
|
---|
259 | vertexrate = ctx->VertexCount / ctx->VertexTime;
|
---|
260 | }
|
---|
261 | else {
|
---|
262 | vertexrate = 0.0;
|
---|
263 | }
|
---|
264 | if (ctx->PointTime>0.0) {
|
---|
265 | pointrate = ctx->PointCount / ctx->PointTime;
|
---|
266 | }
|
---|
267 | else {
|
---|
268 | pointrate = 0.0;
|
---|
269 | }
|
---|
270 | if (ctx->LineTime>0.0) {
|
---|
271 | linerate = ctx->LineCount / ctx->LineTime;
|
---|
272 | }
|
---|
273 | else {
|
---|
274 | linerate = 0.0;
|
---|
275 | }
|
---|
276 | if (ctx->PolygonTime>0.0) {
|
---|
277 | polygonrate = ctx->PolygonCount / ctx->PolygonTime;
|
---|
278 | }
|
---|
279 | else {
|
---|
280 | polygonrate = 0.0;
|
---|
281 | }
|
---|
282 | if (ctx->ClearTime>0.0) {
|
---|
283 | clearrate = ctx->ClearCount / ctx->ClearTime;
|
---|
284 | }
|
---|
285 | else {
|
---|
286 | clearrate = 0.0;
|
---|
287 | }
|
---|
288 | if (ctx->SwapTime>0.0) {
|
---|
289 | swaprate = ctx->SwapCount / ctx->SwapTime;
|
---|
290 | }
|
---|
291 | else {
|
---|
292 | swaprate = 0.0;
|
---|
293 | }
|
---|
294 |
|
---|
295 | if (ctx->BeginEndCount>0) {
|
---|
296 | avgvertices = (GLdouble) ctx->VertexCount / (GLdouble) ctx->BeginEndCount;
|
---|
297 | }
|
---|
298 | else {
|
---|
299 | avgvertices = 0.0;
|
---|
300 | }
|
---|
301 |
|
---|
302 | overhead = ctx->BeginEndTime - ctx->VertexTime - ctx->PointTime
|
---|
303 | - ctx->LineTime - ctx->PolygonTime;
|
---|
304 |
|
---|
305 |
|
---|
306 | printf(" Count Time (s) Rate (/s) \n");
|
---|
307 | printf("--------------------------------------------------------\n");
|
---|
308 | printf("glBegin/glEnd %7d %8.3f %10.3f\n",
|
---|
309 | ctx->BeginEndCount, ctx->BeginEndTime, beginendrate);
|
---|
310 | printf(" vertexes transformed %7d %8.3f %10.3f\n",
|
---|
311 | ctx->VertexCount, ctx->VertexTime, vertexrate );
|
---|
312 | printf(" points rasterized %7d %8.3f %10.3f\n",
|
---|
313 | ctx->PointCount, ctx->PointTime, pointrate );
|
---|
314 | printf(" lines rasterized %7d %8.3f %10.3f\n",
|
---|
315 | ctx->LineCount, ctx->LineTime, linerate );
|
---|
316 | printf(" polygons rasterized %7d %8.3f %10.3f\n",
|
---|
317 | ctx->PolygonCount, ctx->PolygonTime, polygonrate );
|
---|
318 | printf(" overhead %8.3f\n", overhead );
|
---|
319 | printf("glClear %7d %8.3f %10.3f\n",
|
---|
320 | ctx->ClearCount, ctx->ClearTime, clearrate );
|
---|
321 | printf("SwapBuffers %7d %8.3f %10.3f\n",
|
---|
322 | ctx->SwapCount, ctx->SwapTime, swaprate );
|
---|
323 | printf("\n");
|
---|
324 |
|
---|
325 | printf("Average number of vertices per begin/end: %8.3f\n", avgvertices );
|
---|
326 | }
|
---|
327 | #endif
|
---|
328 |
|
---|
329 |
|
---|
330 |
|
---|
331 |
|
---|
332 |
|
---|
333 | /**********************************************************************/
|
---|
334 | /***** Context allocation, initialization, destroying *****/
|
---|
335 | /**********************************************************************/
|
---|
336 |
|
---|
337 |
|
---|
338 | /*
|
---|
339 | * This function just calls all the various one-time-init functions in Mesa.
|
---|
340 | */
|
---|
341 | static void one_time_init( void )
|
---|
342 | {
|
---|
343 | static GLboolean alreadyCalled = GL_FALSE;
|
---|
344 |
|
---|
345 | if (!alreadyCalled) {
|
---|
346 | gl_init_clip();
|
---|
347 | gl_init_eval();
|
---|
348 | gl_init_fog();
|
---|
349 | gl_init_math();
|
---|
350 | gl_init_lists();
|
---|
351 | gl_init_shade();
|
---|
352 | gl_init_texture();
|
---|
353 | gl_init_transformation();
|
---|
354 | gl_init_translate();
|
---|
355 | gl_init_vbrender();
|
---|
356 | gl_init_vbxform();
|
---|
357 | gl_init_vertices();
|
---|
358 | #ifdef THREADS
|
---|
359 | mesa_ctx_thread_init();
|
---|
360 | #endif
|
---|
361 | alreadyCalled = GL_TRUE;
|
---|
362 | }
|
---|
363 | #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
|
---|
364 | fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
|
---|
365 | #endif
|
---|
366 | }
|
---|
367 |
|
---|
368 |
|
---|
369 | /*
|
---|
370 | * Allocate and initialize a shared context state structure.
|
---|
371 | */
|
---|
372 | static struct gl_shared_state *alloc_shared_state( void )
|
---|
373 | {
|
---|
374 | GLuint d;
|
---|
375 | struct gl_shared_state *ss;
|
---|
376 | GLboolean outOfMemory;
|
---|
377 |
|
---|
378 | ss = CALLOC_STRUCT(gl_shared_state);
|
---|
379 | if (!ss)
|
---|
380 | return NULL;
|
---|
381 |
|
---|
382 | ss->DisplayList = NewHashTable();
|
---|
383 |
|
---|
384 | ss->TexObjects = NewHashTable();
|
---|
385 |
|
---|
386 | /* Default Texture objects */
|
---|
387 | outOfMemory = GL_FALSE;
|
---|
388 | for (d = 1 ; d <= 3 ; d++) {
|
---|
389 | ss->DefaultD[d] = gl_alloc_texture_object(ss, 0, d);
|
---|
390 | if (!ss->DefaultD[d]) {
|
---|
391 | outOfMemory = GL_TRUE;
|
---|
392 | break;
|
---|
393 | }
|
---|
394 | ss->DefaultD[d]->RefCount++; /* don't free if not in use */
|
---|
395 | }
|
---|
396 |
|
---|
397 | if (!ss->DisplayList || !ss->TexObjects || outOfMemory) {
|
---|
398 | /* Ran out of memory at some point. Free everything and return NULL */
|
---|
399 | if (ss->DisplayList)
|
---|
400 | DeleteHashTable(ss->DisplayList);
|
---|
401 | if (ss->TexObjects)
|
---|
402 | DeleteHashTable(ss->TexObjects);
|
---|
403 | if (ss->DefaultD[1])
|
---|
404 | gl_free_texture_object(ss, ss->DefaultD[1]);
|
---|
405 | if (ss->DefaultD[2])
|
---|
406 | gl_free_texture_object(ss, ss->DefaultD[2]);
|
---|
407 | if (ss->DefaultD[3])
|
---|
408 | gl_free_texture_object(ss, ss->DefaultD[3]);
|
---|
409 | FREE(ss);
|
---|
410 | return NULL;
|
---|
411 | }
|
---|
412 | else {
|
---|
413 | return ss;
|
---|
414 | }
|
---|
415 | }
|
---|
416 |
|
---|
417 |
|
---|
418 | /*
|
---|
419 | * Deallocate a shared state context and all children structures.
|
---|
420 | */
|
---|
421 | static void free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
|
---|
422 | {
|
---|
423 | /* Free display lists */
|
---|
424 | while (1) {
|
---|
425 | GLuint list = HashFirstEntry(ss->DisplayList);
|
---|
426 | if (list) {
|
---|
427 | gl_destroy_list(ctx, list);
|
---|
428 | }
|
---|
429 | else {
|
---|
430 | break;
|
---|
431 | }
|
---|
432 | }
|
---|
433 | DeleteHashTable(ss->DisplayList);
|
---|
434 |
|
---|
435 | /* Free texture objects */
|
---|
436 | while (ss->TexObjectList)
|
---|
437 | {
|
---|
438 | if (ctx->Driver.DeleteTexture)
|
---|
439 | (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList );
|
---|
440 | /* this function removes from linked list too! */
|
---|
441 | gl_free_texture_object(ss, ss->TexObjectList);
|
---|
442 | }
|
---|
443 | DeleteHashTable(ss->TexObjects);
|
---|
444 |
|
---|
445 | FREE(ss);
|
---|
446 | }
|
---|
447 |
|
---|
448 |
|
---|
449 |
|
---|
450 |
|
---|
451 |
|
---|
452 |
|
---|
453 | /*
|
---|
454 | * Initialize the nth light. Note that the defaults for light 0 are
|
---|
455 | * different than the other lights.
|
---|
456 | */
|
---|
457 | static void init_light( struct gl_light *l, GLuint n )
|
---|
458 | {
|
---|
459 | make_empty_list( l );
|
---|
460 |
|
---|
461 | ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
|
---|
462 | if (n==0) {
|
---|
463 | ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
|
---|
464 | ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
|
---|
465 | }
|
---|
466 | else {
|
---|
467 | ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
|
---|
468 | ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
|
---|
469 | }
|
---|
470 | ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
|
---|
471 | ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
|
---|
472 | l->SpotExponent = 0.0;
|
---|
473 | gl_compute_spot_exp_table( l );
|
---|
474 | l->SpotCutoff = 180.0;
|
---|
475 | l->CosCutoff = 0.0; /* KW: -ve values not admitted */
|
---|
476 | l->ConstantAttenuation = 1.0;
|
---|
477 | l->LinearAttenuation = 0.0;
|
---|
478 | l->QuadraticAttenuation = 0.0;
|
---|
479 | l->Enabled = GL_FALSE;
|
---|
480 | }
|
---|
481 |
|
---|
482 |
|
---|
483 |
|
---|
484 | static void init_lightmodel( struct gl_lightmodel *lm )
|
---|
485 | {
|
---|
486 | ASSIGN_4V( lm->Ambient, 0.2, 0.2, 0.2, 1.0 );
|
---|
487 | lm->LocalViewer = GL_FALSE;
|
---|
488 | lm->TwoSide = GL_FALSE;
|
---|
489 | lm->ColorControl = GL_SINGLE_COLOR;
|
---|
490 | }
|
---|
491 |
|
---|
492 |
|
---|
493 | static void init_material( struct gl_material *m )
|
---|
494 | {
|
---|
495 | ASSIGN_4V( m->Ambient, 0.2, 0.2, 0.2, 1.0 );
|
---|
496 | ASSIGN_4V( m->Diffuse, 0.8, 0.8, 0.8, 1.0 );
|
---|
497 | ASSIGN_4V( m->Specular, 0.0, 0.0, 0.0, 1.0 );
|
---|
498 | ASSIGN_4V( m->Emission, 0.0, 0.0, 0.0, 1.0 );
|
---|
499 | m->Shininess = 0.0;
|
---|
500 | m->AmbientIndex = 0;
|
---|
501 | m->DiffuseIndex = 1;
|
---|
502 | m->SpecularIndex = 1;
|
---|
503 | }
|
---|
504 |
|
---|
505 |
|
---|
506 |
|
---|
507 | static void init_texture_unit( GLcontext *ctx, GLuint unit )
|
---|
508 | {
|
---|
509 | struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
|
---|
510 |
|
---|
511 | texUnit->EnvMode = GL_MODULATE;
|
---|
512 | ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
|
---|
513 | texUnit->TexGenEnabled = 0;
|
---|
514 | texUnit->GenModeS = GL_EYE_LINEAR;
|
---|
515 | texUnit->GenModeT = GL_EYE_LINEAR;
|
---|
516 | texUnit->GenModeR = GL_EYE_LINEAR;
|
---|
517 | texUnit->GenModeQ = GL_EYE_LINEAR;
|
---|
518 | /* Yes, these plane coefficients are correct! */
|
---|
519 | ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
|
---|
520 | ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
|
---|
521 | ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
|
---|
522 | ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
|
---|
523 | ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
|
---|
524 | ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
|
---|
525 | ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
|
---|
526 | ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
|
---|
527 |
|
---|
528 | texUnit->CurrentD[1] = ctx->Shared->DefaultD[1];
|
---|
529 | texUnit->CurrentD[2] = ctx->Shared->DefaultD[2];
|
---|
530 | texUnit->CurrentD[3] = ctx->Shared->DefaultD[3];
|
---|
531 | }
|
---|
532 |
|
---|
533 |
|
---|
534 | static void init_fallback_arrays( GLcontext *ctx )
|
---|
535 | {
|
---|
536 | struct gl_client_array *cl;
|
---|
537 | GLuint i;
|
---|
538 |
|
---|
539 | cl = &ctx->Fallback.Normal;
|
---|
540 | cl->Size = 3;
|
---|
541 | cl->Type = GL_FLOAT;
|
---|
542 | cl->Stride = 0;
|
---|
543 | cl->StrideB = 0;
|
---|
544 | cl->Ptr = (void *) ctx->Current.Normal;
|
---|
545 | cl->Enabled = 1;
|
---|
546 |
|
---|
547 | cl = &ctx->Fallback.Color;
|
---|
548 | cl->Size = 4;
|
---|
549 | cl->Type = GL_UNSIGNED_BYTE;
|
---|
550 | cl->Stride = 0;
|
---|
551 | cl->StrideB = 0;
|
---|
552 | cl->Ptr = (void *) ctx->Current.ByteColor;
|
---|
553 | cl->Enabled = 1;
|
---|
554 |
|
---|
555 | cl = &ctx->Fallback.Index;
|
---|
556 | cl->Size = 1;
|
---|
557 | cl->Type = GL_UNSIGNED_INT;
|
---|
558 | cl->Stride = 0;
|
---|
559 | cl->StrideB = 0;
|
---|
560 | cl->Ptr = (void *) &ctx->Current.Index;
|
---|
561 | cl->Enabled = 1;
|
---|
562 |
|
---|
563 | for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) {
|
---|
564 | cl = &ctx->Fallback.TexCoord[i];
|
---|
565 | cl->Size = 4;
|
---|
566 | cl->Type = GL_FLOAT;
|
---|
567 | cl->Stride = 0;
|
---|
568 | cl->StrideB = 0;
|
---|
569 | cl->Ptr = (void *) ctx->Current.Texcoord[i];
|
---|
570 | cl->Enabled = 1;
|
---|
571 | }
|
---|
572 |
|
---|
573 | cl = &ctx->Fallback.EdgeFlag;
|
---|
574 | cl->Size = 1;
|
---|
575 | cl->Type = GL_UNSIGNED_BYTE;
|
---|
576 | cl->Stride = 0;
|
---|
577 | cl->StrideB = 0;
|
---|
578 | cl->Ptr = (void *) &ctx->Current.EdgeFlag;
|
---|
579 | cl->Enabled = 1;
|
---|
580 | }
|
---|
581 |
|
---|
582 | /* Initialize a 1-D evaluator map */
|
---|
583 | static void init_1d_map( struct gl_1d_map *map, int n, const float *initial )
|
---|
584 | {
|
---|
585 | map->Order = 1;
|
---|
586 | map->u1 = 0.0;
|
---|
587 | map->u2 = 1.0;
|
---|
588 | map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
|
---|
589 | if (map->Points) {
|
---|
590 | GLint i;
|
---|
591 | for (i=0;i<n;i++)
|
---|
592 | map->Points[i] = initial[i];
|
---|
593 | }
|
---|
594 | map->Retain = GL_FALSE;
|
---|
595 | }
|
---|
596 |
|
---|
597 |
|
---|
598 | /* Initialize a 2-D evaluator map */
|
---|
599 | static void init_2d_map( struct gl_2d_map *map, int n, const float *initial )
|
---|
600 | {
|
---|
601 | map->Uorder = 1;
|
---|
602 | map->Vorder = 1;
|
---|
603 | map->u1 = 0.0;
|
---|
604 | map->u2 = 1.0;
|
---|
605 | map->v1 = 0.0;
|
---|
606 | map->v2 = 1.0;
|
---|
607 | map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
|
---|
608 | if (map->Points) {
|
---|
609 | GLint i;
|
---|
610 | for (i=0;i<n;i++)
|
---|
611 | map->Points[i] = initial[i];
|
---|
612 | }
|
---|
613 | map->Retain = GL_FALSE;
|
---|
614 | }
|
---|
615 |
|
---|
616 |
|
---|
617 |
|
---|
618 | /*
|
---|
619 | * Initialize a gl_context structure to default values.
|
---|
620 | */
|
---|
621 | static void initialize_context( GLcontext *ctx )
|
---|
622 | {
|
---|
623 | GLuint i, j;
|
---|
624 |
|
---|
625 | if (ctx) {
|
---|
626 | /* Constants, may be overriden by device driver */
|
---|
627 | ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
|
---|
628 | ctx->Const.MaxTextureSize = 1 << (MAX_TEXTURE_LEVELS - 1);
|
---|
629 | ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
|
---|
630 | ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
|
---|
631 |
|
---|
632 | /* Modelview matrix */
|
---|
633 | gl_matrix_ctr( &ctx->ModelView );
|
---|
634 | gl_matrix_alloc_inv( &ctx->ModelView );
|
---|
635 |
|
---|
636 | ctx->ModelViewStackDepth = 0;
|
---|
637 | for (i = 0 ; i < MAX_MODELVIEW_STACK_DEPTH ; i++) {
|
---|
638 | gl_matrix_ctr( &ctx->ModelViewStack[i] );
|
---|
639 | gl_matrix_alloc_inv( &ctx->ModelViewStack[i] );
|
---|
640 | }
|
---|
641 |
|
---|
642 | /* Projection matrix - need inv for user clipping in clip space*/
|
---|
643 | gl_matrix_ctr( &ctx->ProjectionMatrix );
|
---|
644 | gl_matrix_alloc_inv( &ctx->ProjectionMatrix );
|
---|
645 |
|
---|
646 | gl_matrix_ctr( &ctx->ModelProjectMatrix );
|
---|
647 | gl_matrix_ctr( &ctx->ModelProjectWinMatrix );
|
---|
648 | ctx->ModelProjectWinMatrixUptodate = GL_FALSE;
|
---|
649 |
|
---|
650 | ctx->ProjectionStackDepth = 0;
|
---|
651 | ctx->NearFarStack[0][0] = 1.0; /* These values seem weird by make */
|
---|
652 | ctx->NearFarStack[0][1] = 0.0; /* sense mathematically. */
|
---|
653 |
|
---|
654 | for (i = 0 ; i < MAX_PROJECTION_STACK_DEPTH ; i++) {
|
---|
655 | gl_matrix_ctr( &ctx->ProjectionStack[i] );
|
---|
656 | gl_matrix_alloc_inv( &ctx->ProjectionStack[i] );
|
---|
657 | }
|
---|
658 |
|
---|
659 | /* Texture matrix */
|
---|
660 | for (i=0; i<MAX_TEXTURE_UNITS; i++) {
|
---|
661 | gl_matrix_ctr( &ctx->TextureMatrix[i] );
|
---|
662 | ctx->TextureStackDepth[i] = 0;
|
---|
663 | for (j = 0 ; j < MAX_TEXTURE_STACK_DEPTH ; j++) {
|
---|
664 | ctx->TextureStack[i][j].inv = 0;
|
---|
665 | }
|
---|
666 | }
|
---|
667 |
|
---|
668 | /* Accumulate buffer group */
|
---|
669 | ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
|
---|
670 |
|
---|
671 | /* Color buffer group */
|
---|
672 | ctx->Color.IndexMask = 0xffffffff;
|
---|
673 | ctx->Color.ColorMask[0] = 0xff;
|
---|
674 | ctx->Color.ColorMask[1] = 0xff;
|
---|
675 | ctx->Color.ColorMask[2] = 0xff;
|
---|
676 | ctx->Color.ColorMask[3] = 0xff;
|
---|
677 | ctx->Color.SWmasking = GL_FALSE;
|
---|
678 | ctx->Color.ClearIndex = 0;
|
---|
679 | ASSIGN_4V( ctx->Color.ClearColor, 0.0, 0.0, 0.0, 0.0 );
|
---|
680 | ctx->Color.DrawBuffer = GL_FRONT;
|
---|
681 | ctx->Color.AlphaEnabled = GL_FALSE;
|
---|
682 | ctx->Color.AlphaFunc = GL_ALWAYS;
|
---|
683 | ctx->Color.AlphaRef = 0;
|
---|
684 | ctx->Color.BlendEnabled = GL_FALSE;
|
---|
685 | ctx->Color.BlendSrcRGB = GL_ONE;
|
---|
686 | ctx->Color.BlendDstRGB = GL_ZERO;
|
---|
687 | ctx->Color.BlendSrcA = GL_ONE;
|
---|
688 | ctx->Color.BlendDstA = GL_ZERO;
|
---|
689 | ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
|
---|
690 | ctx->Color.BlendFunc = NULL; /* this pointer set only when needed */
|
---|
691 | ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
|
---|
692 | ctx->Color.IndexLogicOpEnabled = GL_FALSE;
|
---|
693 | ctx->Color.ColorLogicOpEnabled = GL_FALSE;
|
---|
694 | ctx->Color.SWLogicOpEnabled = GL_FALSE;
|
---|
695 | ctx->Color.LogicOp = GL_COPY;
|
---|
696 | ctx->Color.DitherFlag = GL_TRUE;
|
---|
697 | ctx->Color.MultiDrawBuffer = GL_FALSE;
|
---|
698 |
|
---|
699 | /* Current group */
|
---|
700 | ASSIGN_4V( ctx->Current.ByteColor, 255, 255, 255, 255);
|
---|
701 | ctx->Current.Index = 1;
|
---|
702 | for (i=0; i<MAX_TEXTURE_UNITS; i++)
|
---|
703 | ASSIGN_4V( ctx->Current.Texcoord[i], 0.0, 0.0, 0.0, 1.0 );
|
---|
704 | ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
|
---|
705 | ctx->Current.RasterDistance = 0.0;
|
---|
706 | ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
|
---|
707 | ctx->Current.RasterIndex = 1;
|
---|
708 | for (i=0; i<MAX_TEXTURE_UNITS; i++)
|
---|
709 | ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
|
---|
710 | ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0];
|
---|
711 | ctx->Current.RasterPosValid = GL_TRUE;
|
---|
712 | ctx->Current.EdgeFlag = GL_TRUE;
|
---|
713 | ASSIGN_3V( ctx->Current.Normal, 0.0, 0.0, 1.0 );
|
---|
714 | ctx->Current.Primitive = (GLenum) (GL_POLYGON + 1);
|
---|
715 |
|
---|
716 | ctx->Current.Flag = (VERT_NORM|VERT_INDEX|VERT_RGBA|VERT_EDGE|
|
---|
717 | VERT_TEX0_1|VERT_TEX1_1|VERT_MATERIAL);
|
---|
718 |
|
---|
719 | init_fallback_arrays( ctx );
|
---|
720 |
|
---|
721 | /* Depth buffer group */
|
---|
722 | ctx->Depth.Test = GL_FALSE;
|
---|
723 | ctx->Depth.Clear = 1.0;
|
---|
724 | ctx->Depth.Func = GL_LESS;
|
---|
725 | ctx->Depth.Mask = GL_TRUE;
|
---|
726 |
|
---|
727 | /* Evaluators group */
|
---|
728 | ctx->Eval.Map1Color4 = GL_FALSE;
|
---|
729 | ctx->Eval.Map1Index = GL_FALSE;
|
---|
730 | ctx->Eval.Map1Normal = GL_FALSE;
|
---|
731 | ctx->Eval.Map1TextureCoord1 = GL_FALSE;
|
---|
732 | ctx->Eval.Map1TextureCoord2 = GL_FALSE;
|
---|
733 | ctx->Eval.Map1TextureCoord3 = GL_FALSE;
|
---|
734 | ctx->Eval.Map1TextureCoord4 = GL_FALSE;
|
---|
735 | ctx->Eval.Map1Vertex3 = GL_FALSE;
|
---|
736 | ctx->Eval.Map1Vertex4 = GL_FALSE;
|
---|
737 | ctx->Eval.Map2Color4 = GL_FALSE;
|
---|
738 | ctx->Eval.Map2Index = GL_FALSE;
|
---|
739 | ctx->Eval.Map2Normal = GL_FALSE;
|
---|
740 | ctx->Eval.Map2TextureCoord1 = GL_FALSE;
|
---|
741 | ctx->Eval.Map2TextureCoord2 = GL_FALSE;
|
---|
742 | ctx->Eval.Map2TextureCoord3 = GL_FALSE;
|
---|
743 | ctx->Eval.Map2TextureCoord4 = GL_FALSE;
|
---|
744 | ctx->Eval.Map2Vertex3 = GL_FALSE;
|
---|
745 | ctx->Eval.Map2Vertex4 = GL_FALSE;
|
---|
746 | ctx->Eval.AutoNormal = GL_FALSE;
|
---|
747 | ctx->Eval.MapGrid1un = 1;
|
---|
748 | ctx->Eval.MapGrid1u1 = 0.0;
|
---|
749 | ctx->Eval.MapGrid1u2 = 1.0;
|
---|
750 | ctx->Eval.MapGrid2un = 1;
|
---|
751 | ctx->Eval.MapGrid2vn = 1;
|
---|
752 | ctx->Eval.MapGrid2u1 = 0.0;
|
---|
753 | ctx->Eval.MapGrid2u2 = 1.0;
|
---|
754 | ctx->Eval.MapGrid2v1 = 0.0;
|
---|
755 | ctx->Eval.MapGrid2v2 = 1.0;
|
---|
756 |
|
---|
757 | /* Evaluator data */
|
---|
758 | {
|
---|
759 | static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
|
---|
760 | static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
|
---|
761 | static GLfloat index[1] = { 1.0 };
|
---|
762 | static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
|
---|
763 | static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
|
---|
764 |
|
---|
765 | init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
|
---|
766 | init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
|
---|
767 | init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
|
---|
768 | init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
|
---|
769 | init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
|
---|
770 | init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
|
---|
771 | init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
|
---|
772 | init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
|
---|
773 | init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
|
---|
774 |
|
---|
775 | init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
|
---|
776 | init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
|
---|
777 | init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
|
---|
778 | init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
|
---|
779 | init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
|
---|
780 | init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
|
---|
781 | init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
|
---|
782 | init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
|
---|
783 | init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
|
---|
784 | }
|
---|
785 |
|
---|
786 | /* Fog group */
|
---|
787 | ctx->Fog.Enabled = GL_FALSE;
|
---|
788 | ctx->Fog.Mode = GL_EXP;
|
---|
789 | ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
|
---|
790 | ctx->Fog.Index = 0.0;
|
---|
791 | ctx->Fog.Density = 1.0;
|
---|
792 | ctx->Fog.Start = 0.0;
|
---|
793 | ctx->Fog.End = 1.0;
|
---|
794 |
|
---|
795 | /* Hint group */
|
---|
796 | ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
|
---|
797 | ctx->Hint.PointSmooth = GL_DONT_CARE;
|
---|
798 | ctx->Hint.LineSmooth = GL_DONT_CARE;
|
---|
799 | ctx->Hint.PolygonSmooth = GL_DONT_CARE;
|
---|
800 | ctx->Hint.Fog = GL_DONT_CARE;
|
---|
801 |
|
---|
802 | ctx->Hint.AllowDrawWin = GL_TRUE;
|
---|
803 | ctx->Hint.AllowDrawSpn = GL_TRUE;
|
---|
804 | ctx->Hint.AllowDrawMem = GL_TRUE;
|
---|
805 | ctx->Hint.StrictLighting = GL_TRUE;
|
---|
806 |
|
---|
807 | /* Pipeline */
|
---|
808 | gl_pipeline_init( ctx );
|
---|
809 | gl_cva_init( ctx );
|
---|
810 |
|
---|
811 | /* Extensions */
|
---|
812 | gl_extensions_ctr( ctx );
|
---|
813 |
|
---|
814 | ctx->AllowVertexCull = CLIP_CULLED_BIT;
|
---|
815 |
|
---|
816 | /* Lighting group */
|
---|
817 | for (i=0;i<MAX_LIGHTS;i++) {
|
---|
818 | init_light( &ctx->Light.Light[i], i );
|
---|
819 | }
|
---|
820 | make_empty_list( &ctx->Light.EnabledList );
|
---|
821 |
|
---|
822 | init_lightmodel( &ctx->Light.Model );
|
---|
823 | init_material( &ctx->Light.Material[0] );
|
---|
824 | init_material( &ctx->Light.Material[1] );
|
---|
825 | ctx->Light.ShadeModel = GL_SMOOTH;
|
---|
826 | ctx->Light.Enabled = GL_FALSE;
|
---|
827 | ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
|
---|
828 | ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
|
---|
829 | ctx->Light.ColorMaterialBitmask
|
---|
830 | = gl_material_bitmask( ctx,
|
---|
831 | GL_FRONT_AND_BACK,
|
---|
832 | GL_AMBIENT_AND_DIFFUSE, ~0, 0 );
|
---|
833 |
|
---|
834 | ctx->Light.ColorMaterialEnabled = GL_FALSE;
|
---|
835 |
|
---|
836 | /* Line group */
|
---|
837 | ctx->Line.SmoothFlag = GL_FALSE;
|
---|
838 | ctx->Line.StippleFlag = GL_FALSE;
|
---|
839 | ctx->Line.Width = 1.0;
|
---|
840 | ctx->Line.StipplePattern = 0xffff;
|
---|
841 | ctx->Line.StippleFactor = 1;
|
---|
842 |
|
---|
843 | /* Display List group */
|
---|
844 | ctx->List.ListBase = 0;
|
---|
845 |
|
---|
846 | /* Pixel group */
|
---|
847 | ctx->Pixel.RedBias = 0.0;
|
---|
848 | ctx->Pixel.RedScale = 1.0;
|
---|
849 | ctx->Pixel.GreenBias = 0.0;
|
---|
850 | ctx->Pixel.GreenScale = 1.0;
|
---|
851 | ctx->Pixel.BlueBias = 0.0;
|
---|
852 | ctx->Pixel.BlueScale = 1.0;
|
---|
853 | ctx->Pixel.AlphaBias = 0.0;
|
---|
854 | ctx->Pixel.AlphaScale = 1.0;
|
---|
855 | ctx->Pixel.ScaleOrBiasRGBA = GL_FALSE;
|
---|
856 | ctx->Pixel.DepthBias = 0.0;
|
---|
857 | ctx->Pixel.DepthScale = 1.0;
|
---|
858 | ctx->Pixel.IndexOffset = 0;
|
---|
859 | ctx->Pixel.IndexShift = 0;
|
---|
860 | ctx->Pixel.ZoomX = 1.0;
|
---|
861 | ctx->Pixel.ZoomY = 1.0;
|
---|
862 | ctx->Pixel.MapColorFlag = GL_FALSE;
|
---|
863 | ctx->Pixel.MapStencilFlag = GL_FALSE;
|
---|
864 | ctx->Pixel.MapStoSsize = 1;
|
---|
865 | ctx->Pixel.MapItoIsize = 1;
|
---|
866 | ctx->Pixel.MapItoRsize = 1;
|
---|
867 | ctx->Pixel.MapItoGsize = 1;
|
---|
868 | ctx->Pixel.MapItoBsize = 1;
|
---|
869 | ctx->Pixel.MapItoAsize = 1;
|
---|
870 | ctx->Pixel.MapRtoRsize = 1;
|
---|
871 | ctx->Pixel.MapGtoGsize = 1;
|
---|
872 | ctx->Pixel.MapBtoBsize = 1;
|
---|
873 | ctx->Pixel.MapAtoAsize = 1;
|
---|
874 | ctx->Pixel.MapStoS[0] = 0;
|
---|
875 | ctx->Pixel.MapItoI[0] = 0;
|
---|
876 | ctx->Pixel.MapItoR[0] = 0.0;
|
---|
877 | ctx->Pixel.MapItoG[0] = 0.0;
|
---|
878 | ctx->Pixel.MapItoB[0] = 0.0;
|
---|
879 | ctx->Pixel.MapItoA[0] = 0.0;
|
---|
880 | ctx->Pixel.MapItoR8[0] = 0;
|
---|
881 | ctx->Pixel.MapItoG8[0] = 0;
|
---|
882 | ctx->Pixel.MapItoB8[0] = 0;
|
---|
883 | ctx->Pixel.MapItoA8[0] = 0;
|
---|
884 | ctx->Pixel.MapRtoR[0] = 0.0;
|
---|
885 | ctx->Pixel.MapGtoG[0] = 0.0;
|
---|
886 | ctx->Pixel.MapBtoB[0] = 0.0;
|
---|
887 | ctx->Pixel.MapAtoA[0] = 0.0;
|
---|
888 |
|
---|
889 | /* Point group */
|
---|
890 | ctx->Point.SmoothFlag = GL_FALSE;
|
---|
891 | ctx->Point.Size = 1.0;
|
---|
892 | ctx->Point.Params[0] = 1.0;
|
---|
893 | ctx->Point.Params[1] = 0.0;
|
---|
894 | ctx->Point.Params[2] = 0.0;
|
---|
895 | ctx->Point.Attenuated = GL_FALSE;
|
---|
896 | ctx->Point.MinSize = 0.0;
|
---|
897 | ctx->Point.MaxSize = (GLfloat) MAX_POINT_SIZE;
|
---|
898 | ctx->Point.Threshold = 1.0;
|
---|
899 |
|
---|
900 | /* Polygon group */
|
---|
901 | ctx->Polygon.CullFlag = GL_FALSE;
|
---|
902 | ctx->Polygon.CullFaceMode = GL_BACK;
|
---|
903 | ctx->Polygon.FrontFace = GL_CCW;
|
---|
904 | ctx->Polygon.FrontBit = 0;
|
---|
905 | ctx->Polygon.FrontMode = GL_FILL;
|
---|
906 | ctx->Polygon.BackMode = GL_FILL;
|
---|
907 | ctx->Polygon.Unfilled = GL_FALSE;
|
---|
908 | ctx->Polygon.SmoothFlag = GL_FALSE;
|
---|
909 | ctx->Polygon.StippleFlag = GL_FALSE;
|
---|
910 | ctx->Polygon.OffsetFactor = 0.0F;
|
---|
911 | ctx->Polygon.OffsetUnits = 0.0F;
|
---|
912 | ctx->Polygon.OffsetPoint = GL_FALSE;
|
---|
913 | ctx->Polygon.OffsetLine = GL_FALSE;
|
---|
914 | ctx->Polygon.OffsetFill = GL_FALSE;
|
---|
915 |
|
---|
916 | /* Polygon Stipple group */
|
---|
917 | MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
|
---|
918 |
|
---|
919 | /* Scissor group */
|
---|
920 | ctx->Scissor.Enabled = GL_FALSE;
|
---|
921 | ctx->Scissor.X = 0;
|
---|
922 | ctx->Scissor.Y = 0;
|
---|
923 | ctx->Scissor.Width = 0;
|
---|
924 | ctx->Scissor.Height = 0;
|
---|
925 |
|
---|
926 | /* Stencil group */
|
---|
927 | ctx->Stencil.Enabled = GL_FALSE;
|
---|
928 | ctx->Stencil.Function = GL_ALWAYS;
|
---|
929 | ctx->Stencil.FailFunc = GL_KEEP;
|
---|
930 | ctx->Stencil.ZPassFunc = GL_KEEP;
|
---|
931 | ctx->Stencil.ZFailFunc = GL_KEEP;
|
---|
932 | ctx->Stencil.Ref = 0;
|
---|
933 | ctx->Stencil.ValueMask = STENCIL_MAX;
|
---|
934 | ctx->Stencil.Clear = 0;
|
---|
935 | ctx->Stencil.WriteMask = STENCIL_MAX;
|
---|
936 |
|
---|
937 | /* Texture group */
|
---|
938 | ctx->Texture.CurrentUnit = 0; /* multitexture */
|
---|
939 | ctx->Texture.CurrentTransformUnit = 0; /* multitexture */
|
---|
940 | ctx->Texture.Enabled = 0;
|
---|
941 |
|
---|
942 | for (i=0; i<MAX_TEXTURE_UNITS; i++)
|
---|
943 | init_texture_unit( ctx, i );
|
---|
944 |
|
---|
945 | ctx->Texture.SharedPalette = GL_FALSE;
|
---|
946 | ctx->Texture.Palette[0] = 255;
|
---|
947 | ctx->Texture.Palette[1] = 255;
|
---|
948 | ctx->Texture.Palette[2] = 255;
|
---|
949 | ctx->Texture.Palette[3] = 255;
|
---|
950 | ctx->Texture.PaletteSize = 1;
|
---|
951 | ctx->Texture.PaletteIntFormat = GL_RGBA;
|
---|
952 | ctx->Texture.PaletteFormat = GL_RGBA;
|
---|
953 |
|
---|
954 | /* Transformation group */
|
---|
955 | ctx->Transform.MatrixMode = GL_MODELVIEW;
|
---|
956 | ctx->Transform.Normalize = GL_FALSE;
|
---|
957 | ctx->Transform.RescaleNormals = GL_FALSE;
|
---|
958 | for (i=0;i<MAX_CLIP_PLANES;i++) {
|
---|
959 | ctx->Transform.ClipEnabled[i] = GL_FALSE;
|
---|
960 | ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
|
---|
961 | }
|
---|
962 | ctx->Transform.AnyClip = GL_FALSE;
|
---|
963 |
|
---|
964 | /* Viewport group */
|
---|
965 | ctx->Viewport.X = 0;
|
---|
966 | ctx->Viewport.Y = 0;
|
---|
967 | ctx->Viewport.Width = 0;
|
---|
968 | ctx->Viewport.Height = 0;
|
---|
969 | ctx->Viewport.Near = 0.0;
|
---|
970 | ctx->Viewport.Far = 1.0;
|
---|
971 | gl_matrix_ctr(&ctx->Viewport.WindowMap);
|
---|
972 |
|
---|
973 | #define Sz 10
|
---|
974 | #define Tz 14
|
---|
975 | ctx->Viewport.WindowMap.m[Sz] = 0.5 * DEPTH_SCALE;
|
---|
976 | ctx->Viewport.WindowMap.m[Tz] = 0.5 * DEPTH_SCALE;
|
---|
977 | #undef Sz
|
---|
978 | #undef Tz
|
---|
979 |
|
---|
980 | ctx->Viewport.WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
|
---|
981 | ctx->Viewport.WindowMap.type = MATRIX_3D_NO_ROT;
|
---|
982 |
|
---|
983 | /* Vertex arrays */
|
---|
984 | ctx->Array.Vertex.Size = 4;
|
---|
985 | ctx->Array.Vertex.Type = GL_FLOAT;
|
---|
986 | ctx->Array.Vertex.Stride = 0;
|
---|
987 | ctx->Array.Vertex.StrideB = 0;
|
---|
988 | ctx->Array.Vertex.Ptr = NULL;
|
---|
989 | ctx->Array.Vertex.Enabled = GL_FALSE;
|
---|
990 | ctx->Array.Normal.Type = GL_FLOAT;
|
---|
991 | ctx->Array.Normal.Stride = 0;
|
---|
992 | ctx->Array.Normal.StrideB = 0;
|
---|
993 | ctx->Array.Normal.Ptr = NULL;
|
---|
994 | ctx->Array.Normal.Enabled = GL_FALSE;
|
---|
995 | ctx->Array.Color.Size = 4;
|
---|
996 | ctx->Array.Color.Type = GL_FLOAT;
|
---|
997 | ctx->Array.Color.Stride = 0;
|
---|
998 | ctx->Array.Color.StrideB = 0;
|
---|
999 | ctx->Array.Color.Ptr = NULL;
|
---|
1000 | ctx->Array.Color.Enabled = GL_FALSE;
|
---|
1001 | ctx->Array.Index.Type = GL_FLOAT;
|
---|
1002 | ctx->Array.Index.Stride = 0;
|
---|
1003 | ctx->Array.Index.StrideB = 0;
|
---|
1004 | ctx->Array.Index.Ptr = NULL;
|
---|
1005 | ctx->Array.Index.Enabled = GL_FALSE;
|
---|
1006 | for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
|
---|
1007 | ctx->Array.TexCoord[i].Size = 4;
|
---|
1008 | ctx->Array.TexCoord[i].Type = GL_FLOAT;
|
---|
1009 | ctx->Array.TexCoord[i].Stride = 0;
|
---|
1010 | ctx->Array.TexCoord[i].StrideB = 0;
|
---|
1011 | ctx->Array.TexCoord[i].Ptr = NULL;
|
---|
1012 | ctx->Array.TexCoord[i].Enabled = GL_FALSE;
|
---|
1013 | }
|
---|
1014 | ctx->Array.TexCoordInterleaveFactor = 1;
|
---|
1015 | ctx->Array.EdgeFlag.Stride = 0;
|
---|
1016 | ctx->Array.EdgeFlag.StrideB = 0;
|
---|
1017 | ctx->Array.EdgeFlag.Ptr = NULL;
|
---|
1018 | ctx->Array.EdgeFlag.Enabled = GL_FALSE;
|
---|
1019 | ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
|
---|
1020 |
|
---|
1021 | /* Pixel transfer */
|
---|
1022 | ctx->Pack.Alignment = 4;
|
---|
1023 | ctx->Pack.RowLength = 0;
|
---|
1024 | ctx->Pack.ImageHeight = 0;
|
---|
1025 | ctx->Pack.SkipPixels = 0;
|
---|
1026 | ctx->Pack.SkipRows = 0;
|
---|
1027 | ctx->Pack.SkipImages = 0;
|
---|
1028 | ctx->Pack.SwapBytes = GL_FALSE;
|
---|
1029 | ctx->Pack.LsbFirst = GL_FALSE;
|
---|
1030 | ctx->Unpack.Alignment = 4;
|
---|
1031 | ctx->Unpack.RowLength = 0;
|
---|
1032 | ctx->Unpack.ImageHeight = 0;
|
---|
1033 | ctx->Unpack.SkipPixels = 0;
|
---|
1034 | ctx->Unpack.SkipRows = 0;
|
---|
1035 | ctx->Unpack.SkipImages = 0;
|
---|
1036 | ctx->Unpack.SwapBytes = GL_FALSE;
|
---|
1037 | ctx->Unpack.LsbFirst = GL_FALSE;
|
---|
1038 |
|
---|
1039 | /* Feedback */
|
---|
1040 | ctx->Feedback.Type = GL_2D; /* TODO: verify */
|
---|
1041 | ctx->Feedback.Buffer = NULL;
|
---|
1042 | ctx->Feedback.BufferSize = 0;
|
---|
1043 | ctx->Feedback.Count = 0;
|
---|
1044 |
|
---|
1045 | /* Selection/picking */
|
---|
1046 | ctx->Select.Buffer = NULL;
|
---|
1047 | ctx->Select.BufferSize = 0;
|
---|
1048 | ctx->Select.BufferCount = 0;
|
---|
1049 | ctx->Select.Hits = 0;
|
---|
1050 | ctx->Select.NameStackDepth = 0;
|
---|
1051 |
|
---|
1052 | /* Optimized Accum buffer */
|
---|
1053 | ctx->IntegerAccumMode = GL_TRUE;
|
---|
1054 | ctx->IntegerAccumScaler = 0.0;
|
---|
1055 |
|
---|
1056 | /* Renderer and client attribute stacks */
|
---|
1057 | ctx->AttribStackDepth = 0;
|
---|
1058 | ctx->ClientAttribStackDepth = 0;
|
---|
1059 |
|
---|
1060 | /*** Miscellaneous ***/
|
---|
1061 | ctx->NewState = NEW_ALL;
|
---|
1062 | ctx->RenderMode = GL_RENDER;
|
---|
1063 | ctx->StippleCounter = 0;
|
---|
1064 | ctx->NeedNormals = GL_FALSE;
|
---|
1065 | ctx->DoViewportMapping = GL_TRUE;
|
---|
1066 |
|
---|
1067 | ctx->NeedEyeCoords = GL_FALSE;
|
---|
1068 | ctx->NeedEyeNormals = GL_FALSE;
|
---|
1069 | ctx->vb_proj_matrix = &ctx->ModelProjectMatrix;
|
---|
1070 |
|
---|
1071 | /* Display list */
|
---|
1072 | ctx->CallDepth = 0;
|
---|
1073 | ctx->ExecuteFlag = GL_TRUE;
|
---|
1074 | ctx->CompileFlag = GL_FALSE;
|
---|
1075 | ctx->CurrentListPtr = NULL;
|
---|
1076 | ctx->CurrentBlock = NULL;
|
---|
1077 | ctx->CurrentListNum = 0;
|
---|
1078 | ctx->CurrentPos = 0;
|
---|
1079 |
|
---|
1080 | ctx->ErrorValue = (GLenum) GL_NO_ERROR;
|
---|
1081 |
|
---|
1082 | ctx->CatchSignals = GL_TRUE;
|
---|
1083 |
|
---|
1084 | /* For debug/development only */
|
---|
1085 | ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
|
---|
1086 | ctx->FirstTimeCurrent = GL_TRUE;
|
---|
1087 |
|
---|
1088 | /* Dither disable */
|
---|
1089 | ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
|
---|
1090 | if (ctx->NoDither) {
|
---|
1091 | if (getenv("MESA_DEBUG")) {
|
---|
1092 | fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
|
---|
1093 | }
|
---|
1094 | ctx->Color.DitherFlag = GL_FALSE;
|
---|
1095 | }
|
---|
1096 | }
|
---|
1097 | }
|
---|
1098 |
|
---|
1099 |
|
---|
1100 |
|
---|
1101 | /*
|
---|
1102 | * Allocate a new GLvisual object.
|
---|
1103 | * Input: rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
|
---|
1104 | * alphaFlag - alloc software alpha buffers?
|
---|
1105 | * dbFlag - double buffering?
|
---|
1106 | * stereoFlag - stereo buffer?
|
---|
1107 | * depthFits - requested minimum bits per depth buffer value
|
---|
1108 | * stencilFits - requested minimum bits per stencil buffer value
|
---|
1109 | * accumFits - requested minimum bits per accum buffer component
|
---|
1110 | * indexFits - number of bits per pixel if rgbFlag==GL_FALSE
|
---|
1111 | * red/green/blue/alphaFits - number of bits per color component
|
---|
1112 | * in frame buffer for RGB(A) mode.
|
---|
1113 | * Return: pointer to new GLvisual or NULL if requested parameters can't
|
---|
1114 | * be met.
|
---|
1115 | */
|
---|
1116 | GLvisual *gl_create_visual( GLboolean rgbFlag,
|
---|
1117 | GLboolean alphaFlag,
|
---|
1118 | GLboolean dbFlag,
|
---|
1119 | GLboolean stereoFlag,
|
---|
1120 | GLint depthBits,
|
---|
1121 | GLint stencilBits,
|
---|
1122 | GLint accumBits,
|
---|
1123 | GLint indexBits,
|
---|
1124 | GLint redBits,
|
---|
1125 | GLint greenBits,
|
---|
1126 | GLint blueBits,
|
---|
1127 | GLint alphaBits )
|
---|
1128 | {
|
---|
1129 | GLvisual *vis;
|
---|
1130 |
|
---|
1131 | if (depthBits > (GLint) (8*sizeof(GLdepth))) {
|
---|
1132 | /* can't meet depth buffer requirements */
|
---|
1133 | return NULL;
|
---|
1134 | }
|
---|
1135 | if (stencilBits > (GLint) (8*sizeof(GLstencil))) {
|
---|
1136 | /* can't meet stencil buffer requirements */
|
---|
1137 | return NULL;
|
---|
1138 | }
|
---|
1139 | if (accumBits > (GLint) (8*sizeof(GLaccum))) {
|
---|
1140 | /* can't meet accum buffer requirements */
|
---|
1141 | return NULL;
|
---|
1142 | }
|
---|
1143 |
|
---|
1144 | vis = (GLvisual *) CALLOC( sizeof(GLvisual) );
|
---|
1145 | if (!vis) {
|
---|
1146 | return NULL;
|
---|
1147 | }
|
---|
1148 |
|
---|
1149 | vis->RGBAflag = rgbFlag;
|
---|
1150 | vis->DBflag = dbFlag;
|
---|
1151 | vis->StereoFlag = stereoFlag;
|
---|
1152 | vis->RedBits = redBits;
|
---|
1153 | vis->GreenBits = greenBits;
|
---|
1154 | vis->BlueBits = blueBits;
|
---|
1155 | vis->AlphaBits = alphaFlag ? 8*sizeof(GLubyte) : alphaBits;
|
---|
1156 |
|
---|
1157 | vis->IndexBits = indexBits;
|
---|
1158 | vis->DepthBits = (depthBits>0) ? 8*sizeof(GLdepth) : 0;
|
---|
1159 | vis->AccumBits = (accumBits>0) ? 8*sizeof(GLaccum) : 0;
|
---|
1160 | vis->StencilBits = (stencilBits>0) ? 8*sizeof(GLstencil) : 0;
|
---|
1161 |
|
---|
1162 | vis->SoftwareAlpha = alphaFlag;
|
---|
1163 |
|
---|
1164 | return vis;
|
---|
1165 | }
|
---|
1166 |
|
---|
1167 |
|
---|
1168 |
|
---|
1169 | void gl_destroy_visual( GLvisual *vis )
|
---|
1170 | {
|
---|
1171 | FREE( vis );
|
---|
1172 | }
|
---|
1173 |
|
---|
1174 |
|
---|
1175 |
|
---|
1176 | /*
|
---|
1177 | * Allocate the proxy textures. If we run out of memory part way through
|
---|
1178 | * the allocations clean up and return GL_FALSE.
|
---|
1179 | * Return: GL_TRUE=success, GL_FALSE=failure
|
---|
1180 | */
|
---|
1181 | static GLboolean alloc_proxy_textures( GLcontext *ctx )
|
---|
1182 | {
|
---|
1183 | GLboolean out_of_memory;
|
---|
1184 | GLint i;
|
---|
1185 |
|
---|
1186 | ctx->Texture.Proxy1D = gl_alloc_texture_object(NULL, 0, 1);
|
---|
1187 | if (!ctx->Texture.Proxy1D) {
|
---|
1188 | return GL_FALSE;
|
---|
1189 | }
|
---|
1190 |
|
---|
1191 | ctx->Texture.Proxy2D = gl_alloc_texture_object(NULL, 0, 2);
|
---|
1192 | if (!ctx->Texture.Proxy2D) {
|
---|
1193 | gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
|
---|
1194 | return GL_FALSE;
|
---|
1195 | }
|
---|
1196 |
|
---|
1197 | ctx->Texture.Proxy3D = gl_alloc_texture_object(NULL, 0, 3);
|
---|
1198 | if (!ctx->Texture.Proxy3D) {
|
---|
1199 | gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
|
---|
1200 | gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
|
---|
1201 | return GL_FALSE;
|
---|
1202 | }
|
---|
1203 |
|
---|
1204 | out_of_memory = GL_FALSE;
|
---|
1205 | for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
|
---|
1206 | ctx->Texture.Proxy1D->Image[i] = gl_alloc_texture_image();
|
---|
1207 | ctx->Texture.Proxy2D->Image[i] = gl_alloc_texture_image();
|
---|
1208 | ctx->Texture.Proxy3D->Image[i] = gl_alloc_texture_image();
|
---|
1209 | if (!ctx->Texture.Proxy1D->Image[i]
|
---|
1210 | || !ctx->Texture.Proxy2D->Image[i]
|
---|
1211 | || !ctx->Texture.Proxy3D->Image[i]) {
|
---|
1212 | out_of_memory = GL_TRUE;
|
---|
1213 | }
|
---|
1214 | }
|
---|
1215 | if (out_of_memory) {
|
---|
1216 | for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
|
---|
1217 | if (ctx->Texture.Proxy1D->Image[i]) {
|
---|
1218 | gl_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
|
---|
1219 | }
|
---|
1220 | if (ctx->Texture.Proxy2D->Image[i]) {
|
---|
1221 | gl_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
|
---|
1222 | }
|
---|
1223 | if (ctx->Texture.Proxy3D->Image[i]) {
|
---|
1224 | gl_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
|
---|
1225 | }
|
---|
1226 | }
|
---|
1227 | gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
|
---|
1228 | gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
|
---|
1229 | gl_free_texture_object(NULL, ctx->Texture.Proxy3D);
|
---|
1230 | return GL_FALSE;
|
---|
1231 | }
|
---|
1232 | else {
|
---|
1233 | return GL_TRUE;
|
---|
1234 | }
|
---|
1235 | }
|
---|
1236 |
|
---|
1237 |
|
---|
1238 |
|
---|
1239 | /*
|
---|
1240 | * Allocate and initialize a GLcontext structure.
|
---|
1241 | * Input: visual - a GLvisual pointer
|
---|
1242 | * sharelist - another context to share display lists with or NULL
|
---|
1243 | * driver_ctx - pointer to device driver's context state struct
|
---|
1244 | * Return: pointer to a new gl_context struct or NULL if error.
|
---|
1245 | */
|
---|
1246 | GLcontext *gl_create_context( GLvisual *visual,
|
---|
1247 | GLcontext *share_list,
|
---|
1248 | void *driver_ctx,
|
---|
1249 | GLboolean direct )
|
---|
1250 | {
|
---|
1251 | GLcontext *ctx;
|
---|
1252 | GLuint i;
|
---|
1253 |
|
---|
1254 | (void) direct; /* not used */
|
---|
1255 |
|
---|
1256 | /* do some implementation tests */
|
---|
1257 | assert( sizeof(GLbyte) == 1 );
|
---|
1258 | assert( sizeof(GLshort) >= 2 );
|
---|
1259 | assert( sizeof(GLint) >= 4 );
|
---|
1260 | assert( sizeof(GLubyte) == 1 );
|
---|
1261 | assert( sizeof(GLushort) >= 2 );
|
---|
1262 | assert( sizeof(GLuint) >= 4 );
|
---|
1263 |
|
---|
1264 | /* misc one-time initializations */
|
---|
1265 | one_time_init();
|
---|
1266 |
|
---|
1267 | ctx = (GLcontext *) CALLOC( sizeof(GLcontext) );
|
---|
1268 | if (!ctx) {
|
---|
1269 | return NULL;
|
---|
1270 | }
|
---|
1271 |
|
---|
1272 | ctx->DriverCtx = driver_ctx;
|
---|
1273 | ctx->Visual = visual;
|
---|
1274 | ctx->Buffer = NULL;
|
---|
1275 |
|
---|
1276 | ctx->VB = gl_vb_create_for_immediate( ctx );
|
---|
1277 |
|
---|
1278 | if (!ctx->VB) {
|
---|
1279 | FREE( ctx );
|
---|
1280 | return NULL;
|
---|
1281 | }
|
---|
1282 | ctx->input = ctx->VB->IM;
|
---|
1283 |
|
---|
1284 | ctx->PB = gl_alloc_pb();
|
---|
1285 |
|
---|
1286 | if (!ctx->PB) {
|
---|
1287 | FREE( ctx->VB );
|
---|
1288 | FREE( ctx );
|
---|
1289 | return NULL;
|
---|
1290 | }
|
---|
1291 |
|
---|
1292 | if (share_list) {
|
---|
1293 | /* share the group of display lists of another context */
|
---|
1294 | ctx->Shared = share_list->Shared;
|
---|
1295 | }
|
---|
1296 | else {
|
---|
1297 | /* allocate new group of display lists */
|
---|
1298 | ctx->Shared = alloc_shared_state();
|
---|
1299 | if (!ctx->Shared) {
|
---|
1300 | FREE(ctx->VB);
|
---|
1301 | FREE(ctx->PB);
|
---|
1302 | FREE(ctx);
|
---|
1303 | return NULL;
|
---|
1304 | }
|
---|
1305 | }
|
---|
1306 | ctx->Shared->RefCount++;
|
---|
1307 |
|
---|
1308 | initialize_context( ctx );
|
---|
1309 | gl_reset_vb( ctx->VB );
|
---|
1310 | gl_reset_input( ctx );
|
---|
1311 |
|
---|
1312 |
|
---|
1313 | ctx->ShineTabList = MALLOC_STRUCT( gl_shine_tab );
|
---|
1314 | make_empty_list( ctx->ShineTabList );
|
---|
1315 |
|
---|
1316 | for (i = 0 ; i < 10 ; i++) {
|
---|
1317 | struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
|
---|
1318 | s->shininess = -1;
|
---|
1319 | s->refcount = 0;
|
---|
1320 | insert_at_tail( ctx->ShineTabList, s );
|
---|
1321 | }
|
---|
1322 |
|
---|
1323 | for (i = 0 ; i < 4 ; i++) {
|
---|
1324 | ctx->ShineTable[i] = ctx->ShineTabList->prev;
|
---|
1325 | ctx->ShineTable[i]->refcount++;
|
---|
1326 | }
|
---|
1327 |
|
---|
1328 | if (visual->DBflag) {
|
---|
1329 | ctx->Color.DrawBuffer = GL_BACK;
|
---|
1330 | ctx->Color.DriverDrawBuffer = GL_BACK_LEFT;
|
---|
1331 | ctx->Color.DrawDestMask = BACK_LEFT_BIT;
|
---|
1332 | ctx->Pixel.ReadBuffer = GL_BACK;
|
---|
1333 | ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT;
|
---|
1334 | }
|
---|
1335 | else {
|
---|
1336 | ctx->Color.DrawBuffer = GL_FRONT;
|
---|
1337 | ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT;
|
---|
1338 | ctx->Color.DrawDestMask = FRONT_LEFT_BIT;
|
---|
1339 | ctx->Pixel.ReadBuffer = GL_FRONT;
|
---|
1340 | ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT;
|
---|
1341 | }
|
---|
1342 |
|
---|
1343 |
|
---|
1344 | /* Fill in some driver defaults now.
|
---|
1345 | */
|
---|
1346 | ctx->Driver.AllocDepthBuffer = gl_alloc_depth_buffer;
|
---|
1347 | ctx->Driver.ReadDepthSpanFloat = gl_read_depth_span_float;
|
---|
1348 | ctx->Driver.ReadDepthSpanInt = gl_read_depth_span_int;
|
---|
1349 |
|
---|
1350 |
|
---|
1351 | #ifdef PROFILE
|
---|
1352 | init_timings( ctx );
|
---|
1353 | #endif
|
---|
1354 |
|
---|
1355 | #ifdef GL_VERSION_1_1
|
---|
1356 | if (!alloc_proxy_textures(ctx)) {
|
---|
1357 | free_shared_state(ctx, ctx->Shared);
|
---|
1358 | FREE(ctx->VB);
|
---|
1359 | FREE(ctx->PB);
|
---|
1360 | FREE(ctx);
|
---|
1361 | return NULL;
|
---|
1362 | }
|
---|
1363 | #endif
|
---|
1364 |
|
---|
1365 | gl_init_api_function_pointers( ctx );
|
---|
1366 | ctx->API = ctx->Exec; /* GL_EXECUTE is default */
|
---|
1367 |
|
---|
1368 | return ctx;
|
---|
1369 | }
|
---|
1370 |
|
---|
1371 | /* Just reads the config files...
|
---|
1372 | */
|
---|
1373 | void gl_context_initialize( GLcontext *ctx )
|
---|
1374 | {
|
---|
1375 | gl_read_config_file( ctx );
|
---|
1376 | }
|
---|
1377 |
|
---|
1378 |
|
---|
1379 |
|
---|
1380 |
|
---|
1381 | /*
|
---|
1382 | * Destroy a gl_context structure.
|
---|
1383 | */
|
---|
1384 | void gl_destroy_context( GLcontext *ctx )
|
---|
1385 | {
|
---|
1386 | if (ctx) {
|
---|
1387 |
|
---|
1388 | GLuint i;
|
---|
1389 | struct gl_shine_tab *s, *tmps;
|
---|
1390 |
|
---|
1391 | #ifdef PROFILE
|
---|
1392 | if (getenv("MESA_PROFILE")) {
|
---|
1393 | print_timings( ctx );
|
---|
1394 | }
|
---|
1395 | #endif
|
---|
1396 |
|
---|
1397 | gl_matrix_dtr( &ctx->ModelView );
|
---|
1398 | for (i = 0 ; i < MAX_MODELVIEW_STACK_DEPTH ; i++) {
|
---|
1399 | gl_matrix_dtr( &ctx->ModelViewStack[i] );
|
---|
1400 | }
|
---|
1401 | gl_matrix_dtr( &ctx->ProjectionMatrix );
|
---|
1402 | for (i = 0 ; i < MAX_PROJECTION_STACK_DEPTH ; i++) {
|
---|
1403 | gl_matrix_dtr( &ctx->ProjectionStack[i] );
|
---|
1404 | }
|
---|
1405 |
|
---|
1406 | FREE( ctx->PB );
|
---|
1407 |
|
---|
1408 | if(ctx->input != ctx->VB->IM)
|
---|
1409 | gl_immediate_free( ctx->input );
|
---|
1410 |
|
---|
1411 | gl_vb_free( ctx->VB );
|
---|
1412 |
|
---|
1413 | ctx->Shared->RefCount--;
|
---|
1414 | assert(ctx->Shared->RefCount>=0);
|
---|
1415 | if (ctx->Shared->RefCount==0) {
|
---|
1416 | /* free shared state */
|
---|
1417 | free_shared_state( ctx, ctx->Shared );
|
---|
1418 | }
|
---|
1419 |
|
---|
1420 | foreach_s( s, tmps, ctx->ShineTabList ) {
|
---|
1421 | FREE( s );
|
---|
1422 | }
|
---|
1423 | FREE( ctx->ShineTabList );
|
---|
1424 |
|
---|
1425 | /* Free proxy texture objects */
|
---|
1426 | gl_free_texture_object( NULL, ctx->Texture.Proxy1D );
|
---|
1427 | gl_free_texture_object( NULL, ctx->Texture.Proxy2D );
|
---|
1428 | gl_free_texture_object( NULL, ctx->Texture.Proxy3D );
|
---|
1429 |
|
---|
1430 | /* Free evaluator data */
|
---|
1431 | if (ctx->EvalMap.Map1Vertex3.Points)
|
---|
1432 | FREE( ctx->EvalMap.Map1Vertex3.Points );
|
---|
1433 | if (ctx->EvalMap.Map1Vertex4.Points)
|
---|
1434 | FREE( ctx->EvalMap.Map1Vertex4.Points );
|
---|
1435 | if (ctx->EvalMap.Map1Index.Points)
|
---|
1436 | FREE( ctx->EvalMap.Map1Index.Points );
|
---|
1437 | if (ctx->EvalMap.Map1Color4.Points)
|
---|
1438 | FREE( ctx->EvalMap.Map1Color4.Points );
|
---|
1439 | if (ctx->EvalMap.Map1Normal.Points)
|
---|
1440 | FREE( ctx->EvalMap.Map1Normal.Points );
|
---|
1441 | if (ctx->EvalMap.Map1Texture1.Points)
|
---|
1442 | FREE( ctx->EvalMap.Map1Texture1.Points );
|
---|
1443 | if (ctx->EvalMap.Map1Texture2.Points)
|
---|
1444 | FREE( ctx->EvalMap.Map1Texture2.Points );
|
---|
1445 | if (ctx->EvalMap.Map1Texture3.Points)
|
---|
1446 | FREE( ctx->EvalMap.Map1Texture3.Points );
|
---|
1447 | if (ctx->EvalMap.Map1Texture4.Points)
|
---|
1448 | FREE( ctx->EvalMap.Map1Texture4.Points );
|
---|
1449 |
|
---|
1450 | if (ctx->EvalMap.Map2Vertex3.Points)
|
---|
1451 | FREE( ctx->EvalMap.Map2Vertex3.Points );
|
---|
1452 | if (ctx->EvalMap.Map2Vertex4.Points)
|
---|
1453 | FREE( ctx->EvalMap.Map2Vertex4.Points );
|
---|
1454 | if (ctx->EvalMap.Map2Index.Points)
|
---|
1455 | FREE( ctx->EvalMap.Map2Index.Points );
|
---|
1456 | if (ctx->EvalMap.Map2Color4.Points)
|
---|
1457 | FREE( ctx->EvalMap.Map2Color4.Points );
|
---|
1458 | if (ctx->EvalMap.Map2Normal.Points)
|
---|
1459 | FREE( ctx->EvalMap.Map2Normal.Points );
|
---|
1460 | if (ctx->EvalMap.Map2Texture1.Points)
|
---|
1461 | FREE( ctx->EvalMap.Map2Texture1.Points );
|
---|
1462 | if (ctx->EvalMap.Map2Texture2.Points)
|
---|
1463 | FREE( ctx->EvalMap.Map2Texture2.Points );
|
---|
1464 | if (ctx->EvalMap.Map2Texture3.Points)
|
---|
1465 | FREE( ctx->EvalMap.Map2Texture3.Points );
|
---|
1466 | if (ctx->EvalMap.Map2Texture4.Points)
|
---|
1467 | FREE( ctx->EvalMap.Map2Texture4.Points );
|
---|
1468 |
|
---|
1469 | /* Free cache of immediate buffers. */
|
---|
1470 | while (ctx->nr_im_queued-- > 0) {
|
---|
1471 | struct immediate * next = ctx->freed_im_queue->next;
|
---|
1472 | FREE( ctx->freed_im_queue );
|
---|
1473 | ctx->freed_im_queue = next;
|
---|
1474 | }
|
---|
1475 | gl_extensions_dtr(ctx);
|
---|
1476 |
|
---|
1477 | FREE( (void *) ctx );
|
---|
1478 |
|
---|
1479 | #ifndef THREADS
|
---|
1480 | if (ctx==CC) {
|
---|
1481 | CC = NULL;
|
---|
1482 | CURRENT_INPUT = NULL;
|
---|
1483 | }
|
---|
1484 | #endif
|
---|
1485 |
|
---|
1486 | }
|
---|
1487 | }
|
---|
1488 |
|
---|
1489 |
|
---|
1490 |
|
---|
1491 | /*
|
---|
1492 | * Create a new framebuffer. A GLframebuffer is a struct which
|
---|
1493 | * encapsulates the depth, stencil and accum buffers and related
|
---|
1494 | * parameters.
|
---|
1495 | * Input: visual - a GLvisual pointer
|
---|
1496 | * Return: pointer to new GLframebuffer struct or NULL if error.
|
---|
1497 | */
|
---|
1498 | GLframebuffer *gl_create_framebuffer( GLvisual *visual )
|
---|
1499 | {
|
---|
1500 | GLframebuffer *buffer;
|
---|
1501 |
|
---|
1502 | buffer = (GLframebuffer *) CALLOC( sizeof(GLframebuffer) );
|
---|
1503 | if (!buffer) {
|
---|
1504 | return NULL;
|
---|
1505 | }
|
---|
1506 |
|
---|
1507 | buffer->Visual = visual;
|
---|
1508 |
|
---|
1509 | return buffer;
|
---|
1510 | }
|
---|
1511 |
|
---|
1512 |
|
---|
1513 |
|
---|
1514 | /*
|
---|
1515 | * Free a framebuffer struct and its buffers.
|
---|
1516 | */
|
---|
1517 | void gl_destroy_framebuffer( GLframebuffer *buffer )
|
---|
1518 | {
|
---|
1519 | if (buffer) {
|
---|
1520 | if (buffer->Depth) {
|
---|
1521 | FREE( buffer->Depth );
|
---|
1522 | }
|
---|
1523 | if (buffer->Accum) {
|
---|
1524 | FREE( buffer->Accum );
|
---|
1525 | }
|
---|
1526 | if (buffer->Stencil) {
|
---|
1527 | FREE( buffer->Stencil );
|
---|
1528 | }
|
---|
1529 | if (buffer->FrontLeftAlpha) {
|
---|
1530 | FREE( buffer->FrontLeftAlpha );
|
---|
1531 | }
|
---|
1532 | if (buffer->BackLeftAlpha) {
|
---|
1533 | FREE( buffer->BackLeftAlpha );
|
---|
1534 | }
|
---|
1535 | if (buffer->FrontRightAlpha) {
|
---|
1536 | FREE( buffer->FrontRightAlpha );
|
---|
1537 | }
|
---|
1538 | if (buffer->BackRightAlpha) {
|
---|
1539 | FREE( buffer->BackRightAlpha );
|
---|
1540 | }
|
---|
1541 | FREE(buffer);
|
---|
1542 | }
|
---|
1543 | }
|
---|
1544 |
|
---|
1545 |
|
---|
1546 |
|
---|
1547 | /*
|
---|
1548 | * Set the current context, binding the given frame buffer to the context.
|
---|
1549 | */
|
---|
1550 | void gl_make_current( GLcontext *ctx, GLframebuffer *buffer )
|
---|
1551 | {
|
---|
1552 | GET_CONTEXT;
|
---|
1553 |
|
---|
1554 | /* Flush the old context
|
---|
1555 | */
|
---|
1556 | if (CC) {
|
---|
1557 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(CC, "gl_make_current");
|
---|
1558 | }
|
---|
1559 |
|
---|
1560 | #ifdef THREADS
|
---|
1561 | /* TODO: unbind old buffer from context? */
|
---|
1562 | set_thread_context( ctx );
|
---|
1563 | #else
|
---|
1564 | if (CC && CC->Buffer) {
|
---|
1565 | /* unbind frame buffer from context */
|
---|
1566 | CC->Buffer = NULL;
|
---|
1567 | }
|
---|
1568 |
|
---|
1569 | CC = ctx;
|
---|
1570 | if (ctx) {
|
---|
1571 | SET_IMMEDIATE(ctx, ctx->input);
|
---|
1572 | }
|
---|
1573 | #endif
|
---|
1574 |
|
---|
1575 | if (ctx && buffer) {
|
---|
1576 | /* TODO: check if ctx and buffer's visual match??? */
|
---|
1577 | ctx->Buffer = buffer; /* Bind the frame buffer to the context*/
|
---|
1578 | ctx->NewState = NEW_ALL; /* just to be safe*/
|
---|
1579 | gl_update_state( ctx );
|
---|
1580 | }
|
---|
1581 |
|
---|
1582 | /* We can use this to help debug user's problems. Tell the to set
|
---|
1583 | * the MESA_INFO env variable before running their app. Then the
|
---|
1584 | * first time each context is made current we'll print some useful
|
---|
1585 | * information.
|
---|
1586 | */
|
---|
1587 | if (ctx && ctx->FirstTimeCurrent)
|
---|
1588 | {
|
---|
1589 | dprintf(("Mesa GL_VERSION = %s\n", (char *) gl_GetString(ctx, GL_VERSION)));
|
---|
1590 | dprintf(("Mesa GL_RENDERER = %s\n", (char *) gl_GetString(ctx, GL_RENDERER)));
|
---|
1591 | dprintf(("Mesa GL_VENDOR = %s\n", (char *) gl_GetString(ctx, GL_VENDOR)));
|
---|
1592 | dprintf(("Mesa GL_EXTENSIONS = %s\n", (char *) gl_GetString(ctx, GL_EXTENSIONS)));
|
---|
1593 |
|
---|
1594 | ctx->FirstTimeCurrent = GL_FALSE;
|
---|
1595 | }
|
---|
1596 | }
|
---|
1597 |
|
---|
1598 |
|
---|
1599 | /*
|
---|
1600 | * Return current context handle.
|
---|
1601 | */
|
---|
1602 | GLcontext *gl_get_current_context( void )
|
---|
1603 | {
|
---|
1604 | #ifdef THREADS
|
---|
1605 | return gl_get_thread_context();
|
---|
1606 | #else
|
---|
1607 | return CC;
|
---|
1608 | #endif
|
---|
1609 | }
|
---|
1610 |
|
---|
1611 |
|
---|
1612 |
|
---|
1613 | /*
|
---|
1614 | * Copy attribute groups from one context to another.
|
---|
1615 | * Input: src - source context
|
---|
1616 | * dst - destination context
|
---|
1617 | * mask - bitwise OR of GL_*_BIT flags
|
---|
1618 | */
|
---|
1619 | void gl_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
|
---|
1620 | {
|
---|
1621 | if (mask & GL_ACCUM_BUFFER_BIT) {
|
---|
1622 | MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
|
---|
1623 | }
|
---|
1624 | if (mask & GL_COLOR_BUFFER_BIT) {
|
---|
1625 | MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
|
---|
1626 | }
|
---|
1627 | if (mask & GL_CURRENT_BIT) {
|
---|
1628 | MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
|
---|
1629 | }
|
---|
1630 | if (mask & GL_DEPTH_BUFFER_BIT) {
|
---|
1631 | MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
|
---|
1632 | }
|
---|
1633 | if (mask & GL_ENABLE_BIT) {
|
---|
1634 | /* no op */
|
---|
1635 | }
|
---|
1636 | if (mask & GL_EVAL_BIT) {
|
---|
1637 | MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
|
---|
1638 | }
|
---|
1639 | if (mask & GL_FOG_BIT) {
|
---|
1640 | MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
|
---|
1641 | }
|
---|
1642 | if (mask & GL_HINT_BIT) {
|
---|
1643 | MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
|
---|
1644 | }
|
---|
1645 | if (mask & GL_LIGHTING_BIT) {
|
---|
1646 | MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
|
---|
1647 | /* gl_reinit_light_attrib( &dst->Light ); */
|
---|
1648 | }
|
---|
1649 | if (mask & GL_LINE_BIT) {
|
---|
1650 | MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
|
---|
1651 | }
|
---|
1652 | if (mask & GL_LIST_BIT) {
|
---|
1653 | MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
|
---|
1654 | }
|
---|
1655 | if (mask & GL_PIXEL_MODE_BIT) {
|
---|
1656 | MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
|
---|
1657 | }
|
---|
1658 | if (mask & GL_POINT_BIT) {
|
---|
1659 | MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
|
---|
1660 | }
|
---|
1661 | if (mask & GL_POLYGON_BIT) {
|
---|
1662 | MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
|
---|
1663 | }
|
---|
1664 | if (mask & GL_POLYGON_STIPPLE_BIT) {
|
---|
1665 | #ifdef __WIN32OS2__
|
---|
1666 | MEMCPY( &dst->PolygonStipple, &src->PolygonStipple, 32*sizeof(GLint) );
|
---|
1667 | #else
|
---|
1668 | /* Use loop instead of MEMCPY due to problem with Portland Group's
|
---|
1669 | * C compiler. Reported by John Stone.
|
---|
1670 | */
|
---|
1671 | int i;
|
---|
1672 | for (i=0;i<32;i++) {
|
---|
1673 | dst->PolygonStipple[i] = src->PolygonStipple[i];
|
---|
1674 | }
|
---|
1675 | #endif
|
---|
1676 | }
|
---|
1677 | if (mask & GL_SCISSOR_BIT) {
|
---|
1678 | MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
|
---|
1679 | }
|
---|
1680 | if (mask & GL_STENCIL_BUFFER_BIT) {
|
---|
1681 | MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
|
---|
1682 | }
|
---|
1683 | if (mask & GL_TEXTURE_BIT) {
|
---|
1684 | MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
|
---|
1685 | }
|
---|
1686 | if (mask & GL_TRANSFORM_BIT) {
|
---|
1687 | MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
|
---|
1688 | }
|
---|
1689 | if (mask & GL_VIEWPORT_BIT) {
|
---|
1690 | MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
|
---|
1691 | }
|
---|
1692 | }
|
---|
1693 |
|
---|
1694 |
|
---|
1695 |
|
---|
1696 | /*
|
---|
1697 | * Someday a GLS library or OpenGL-like debugger may call this function
|
---|
1698 | * to register it's own set of API entry points.
|
---|
1699 | * Input: ctx - the context to set API pointers for
|
---|
1700 | * api - if NULL, restore original API pointers
|
---|
1701 | * else, set API function table to this table.
|
---|
1702 | */
|
---|
1703 | void gl_set_api_table( GLcontext *ctx, const struct gl_api_table *api )
|
---|
1704 | {
|
---|
1705 | if (api) {
|
---|
1706 | MEMCPY( &ctx->API, api, sizeof(struct gl_api_table) );
|
---|
1707 | }
|
---|
1708 | else {
|
---|
1709 | MEMCPY( &ctx->API, &ctx->Exec, sizeof(struct gl_api_table) );
|
---|
1710 | }
|
---|
1711 | }
|
---|
1712 |
|
---|
1713 |
|
---|
1714 |
|
---|
1715 |
|
---|
1716 | /**********************************************************************/
|
---|
1717 | /***** Miscellaneous functions *****/
|
---|
1718 | /**********************************************************************/
|
---|
1719 |
|
---|
1720 |
|
---|
1721 | /*
|
---|
1722 | * This function is called when the Mesa user has stumbled into a code
|
---|
1723 | * path which may not be implemented fully or correctly.
|
---|
1724 | */
|
---|
1725 | void gl_problem( const GLcontext *ctx, const char *s )
|
---|
1726 | {
|
---|
1727 | #ifdef __WIN32OS2__
|
---|
1728 | dprintf(("OPENGL32: Mesa implementation error: %s\n", s) );
|
---|
1729 | dprintf(("OPENGL32: Report to J.vandenHorn@fibre.a2000.nl\n" ));
|
---|
1730 | #else
|
---|
1731 | fprintf( stderr, "Mesa implementation error: %s\n", s );
|
---|
1732 | fprintf( stderr, "Report to mesa-bugs@mesa3d.org\n" );
|
---|
1733 | (void) ctx;
|
---|
1734 | #endif
|
---|
1735 | }
|
---|
1736 |
|
---|
1737 |
|
---|
1738 |
|
---|
1739 | /*
|
---|
1740 | * This is called to inform the user that he or she has tried to do
|
---|
1741 | * something illogical or if there's likely a bug in their program
|
---|
1742 | * (like enabled depth testing without a depth buffer).
|
---|
1743 | */
|
---|
1744 | void gl_warning( const GLcontext *ctx, const char *s )
|
---|
1745 | {
|
---|
1746 | GLboolean debug;
|
---|
1747 | #ifdef DEBUG
|
---|
1748 | debug = GL_TRUE;
|
---|
1749 | #else
|
---|
1750 | if (getenv("MESA_DEBUG")) {
|
---|
1751 | debug = GL_TRUE;
|
---|
1752 | }
|
---|
1753 | else {
|
---|
1754 | debug = GL_FALSE;
|
---|
1755 | }
|
---|
1756 | #endif
|
---|
1757 | #ifdef __WIN32OS2__
|
---|
1758 | dprintf(("OPENGL32: Mesa warning: %s\n", s ));
|
---|
1759 | #else
|
---|
1760 | if (debug) {
|
---|
1761 | fprintf( stderr, "Mesa warning: %s\n", s );
|
---|
1762 | }
|
---|
1763 | #endif
|
---|
1764 | (void) ctx;
|
---|
1765 | }
|
---|
1766 |
|
---|
1767 |
|
---|
1768 |
|
---|
1769 | void gl_compile_error( GLcontext *ctx, GLenum error, const char *s )
|
---|
1770 | {
|
---|
1771 | if (ctx->CompileFlag)
|
---|
1772 | gl_save_error( ctx, error, s );
|
---|
1773 |
|
---|
1774 | if (ctx->ExecuteFlag)
|
---|
1775 | gl_error( ctx, error, s );
|
---|
1776 | }
|
---|
1777 |
|
---|
1778 |
|
---|
1779 | /*
|
---|
1780 | * This is Mesa's error handler. Normally, all that's done is the updating
|
---|
1781 | * of the current error value. If Mesa is compiled with -DDEBUG or if the
|
---|
1782 | * environment variable "MESA_DEBUG" is defined then a real error message
|
---|
1783 | * is printed to stderr.
|
---|
1784 | * Input: error - the error value
|
---|
1785 | * s - a diagnostic string
|
---|
1786 | */
|
---|
1787 | void gl_error( GLcontext *ctx, GLenum error, const char *s )
|
---|
1788 | {
|
---|
1789 | GLboolean debug;
|
---|
1790 |
|
---|
1791 | #ifdef DEBUG
|
---|
1792 | debug = GL_TRUE;
|
---|
1793 | #else
|
---|
1794 | if (getenv("MESA_DEBUG")) {
|
---|
1795 | debug = GL_TRUE;
|
---|
1796 | }
|
---|
1797 | else {
|
---|
1798 | debug = GL_FALSE;
|
---|
1799 | }
|
---|
1800 | #endif
|
---|
1801 | #ifdef __WIN32OS2__
|
---|
1802 | {
|
---|
1803 | #else
|
---|
1804 | if (debug) {
|
---|
1805 | #endif
|
---|
1806 | char errstr[1000];
|
---|
1807 |
|
---|
1808 | switch (error) {
|
---|
1809 | case GL_NO_ERROR:
|
---|
1810 | strcpy( errstr, "GL_NO_ERROR" );
|
---|
1811 | break;
|
---|
1812 | case GL_INVALID_VALUE:
|
---|
1813 | strcpy( errstr, "GL_INVALID_VALUE" );
|
---|
1814 | break;
|
---|
1815 | case GL_INVALID_ENUM:
|
---|
1816 | strcpy( errstr, "GL_INVALID_ENUM" );
|
---|
1817 | break;
|
---|
1818 | case GL_INVALID_OPERATION:
|
---|
1819 | strcpy( errstr, "GL_INVALID_OPERATION" );
|
---|
1820 | break;
|
---|
1821 | case GL_STACK_OVERFLOW:
|
---|
1822 | strcpy( errstr, "GL_STACK_OVERFLOW" );
|
---|
1823 | break;
|
---|
1824 | case GL_STACK_UNDERFLOW:
|
---|
1825 | strcpy( errstr, "GL_STACK_UNDERFLOW" );
|
---|
1826 | break;
|
---|
1827 | case GL_OUT_OF_MEMORY:
|
---|
1828 | strcpy( errstr, "GL_OUT_OF_MEMORY" );
|
---|
1829 | break;
|
---|
1830 | default:
|
---|
1831 | strcpy( errstr, "unknown" );
|
---|
1832 | break;
|
---|
1833 | }
|
---|
1834 | #ifdef __WIN32OS2__
|
---|
1835 | dprintf( ("OPENGL32: Mesa user error: %s in %s\n", errstr, s ));
|
---|
1836 | #else
|
---|
1837 | fprintf( stderr, "Mesa user error: %s in %s\n", errstr, s );
|
---|
1838 | #endif
|
---|
1839 | }
|
---|
1840 |
|
---|
1841 | if (ctx->ErrorValue==GL_NO_ERROR) {
|
---|
1842 | ctx->ErrorValue = error;
|
---|
1843 | }
|
---|
1844 |
|
---|
1845 | /* Call device driver's error handler, if any. This is used on the Mac. */
|
---|
1846 | if (ctx->Driver.Error) {
|
---|
1847 | (*ctx->Driver.Error)( ctx );
|
---|
1848 | }
|
---|
1849 | }
|
---|
1850 |
|
---|
1851 |
|
---|
1852 |
|
---|
1853 | /*
|
---|
1854 | * Execute a glGetError command
|
---|
1855 | */
|
---|
1856 | GLenum gl_GetError( GLcontext *ctx )
|
---|
1857 | {
|
---|
1858 | GLenum e = ctx->ErrorValue;
|
---|
1859 |
|
---|
1860 | ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL( ctx, "glGetError", (GLenum) 0);
|
---|
1861 |
|
---|
1862 | if (MESA_VERBOSE & VERBOSE_API)
|
---|
1863 | fprintf(stderr, "glGetError <-- %s\n", gl_lookup_enum_by_nr(e));
|
---|
1864 |
|
---|
1865 | ctx->ErrorValue = (GLenum) GL_NO_ERROR;
|
---|
1866 | return e;
|
---|
1867 | }
|
---|
1868 |
|
---|
1869 |
|
---|
1870 |
|
---|
1871 | void gl_ResizeBuffersMESA( GLcontext *ctx )
|
---|
1872 | {
|
---|
1873 | GLuint buf_width, buf_height;
|
---|
1874 |
|
---|
1875 | if (MESA_VERBOSE & VERBOSE_API)
|
---|
1876 | fprintf(stderr, "glResizeBuffersMESA\n");
|
---|
1877 |
|
---|
1878 | /* ask device driver for size of output buffer */
|
---|
1879 | (*ctx->Driver.GetBufferSize)( ctx, &buf_width, &buf_height );
|
---|
1880 |
|
---|
1881 | dprintf(("OPENGL32: gl_ResizeBuffersMESA - new w/h %d/%d\n",buf_width,buf_height));
|
---|
1882 |
|
---|
1883 | /* see if size of device driver's color buffer (window) has changed */
|
---|
1884 | if (ctx->Buffer->Width == (GLint) buf_width &&
|
---|
1885 | ctx->Buffer->Height == (GLint) buf_height)
|
---|
1886 | return;
|
---|
1887 |
|
---|
1888 | ctx->NewState |= NEW_RASTER_OPS; /* to update scissor / window bounds*/
|
---|
1889 |
|
---|
1890 | /* save buffer size */
|
---|
1891 | ctx->Buffer->Width = buf_width;
|
---|
1892 | ctx->Buffer->Height = buf_height;
|
---|
1893 |
|
---|
1894 | /* Reallocate other buffers if needed. */
|
---|
1895 | if (ctx->Visual->DepthBits>0) {
|
---|
1896 | /* reallocate depth buffer */
|
---|
1897 | (*ctx->Driver.AllocDepthBuffer)( ctx );
|
---|
1898 | }
|
---|
1899 | if (ctx->Visual->StencilBits>0) {
|
---|
1900 | /* reallocate stencil buffer */
|
---|
1901 | gl_alloc_stencil_buffer( ctx );
|
---|
1902 | }
|
---|
1903 | if (ctx->Visual->AccumBits>0) {
|
---|
1904 | /* reallocate accum buffer */
|
---|
1905 | gl_alloc_accum_buffer( ctx );
|
---|
1906 | }
|
---|
1907 | if (ctx->Visual->SoftwareAlpha) {
|
---|
1908 | gl_alloc_alpha_buffers( ctx );
|
---|
1909 | }
|
---|
1910 |
|
---|
1911 | #ifdef DIVE
|
---|
1912 | DiveResizeBuffers(ctx->Buffer->Width,ctx->Buffer->Height);
|
---|
1913 | #endif
|
---|
1914 | }
|
---|
1915 |
|
---|
1916 |
|
---|
1917 |
|
---|
1918 |
|
---|
1919 | /**********************************************************************/
|
---|
1920 | /***** State update logic *****/
|
---|
1921 | /**********************************************************************/
|
---|
1922 |
|
---|
1923 |
|
---|
1924 | /*
|
---|
1925 | * Since the device driver may or may not support pixel logic ops we
|
---|
1926 | * have to make some extensive tests to determine whether or not
|
---|
1927 | * software-implemented logic operations have to be used.
|
---|
1928 | */
|
---|
1929 | static void update_pixel_logic( GLcontext *ctx )
|
---|
1930 | {
|
---|
1931 | if (ctx->Visual->RGBAflag) {
|
---|
1932 | /* RGBA mode blending w/ Logic Op */
|
---|
1933 | if (ctx->Color.ColorLogicOpEnabled) {
|
---|
1934 | if (ctx->Driver.LogicOp
|
---|
1935 | && (*ctx->Driver.LogicOp)( ctx, ctx->Color.LogicOp )) {
|
---|
1936 | /* Device driver can do logic, don't have to do it in software */
|
---|
1937 | ctx->Color.SWLogicOpEnabled = GL_FALSE;
|
---|
1938 | }
|
---|
1939 | else {
|
---|
1940 | /* Device driver can't do logic op so we do it in software */
|
---|
1941 | ctx->Color.SWLogicOpEnabled = GL_TRUE;
|
---|
1942 | }
|
---|
1943 | }
|
---|
1944 | else {
|
---|
1945 | /* no logic op */
|
---|
1946 | if (ctx->Driver.LogicOp) {
|
---|
1947 | (void) (*ctx->Driver.LogicOp)( ctx, GL_COPY );
|
---|
1948 | }
|
---|
1949 | ctx->Color.SWLogicOpEnabled = GL_FALSE;
|
---|
1950 | }
|
---|
1951 | }
|
---|
1952 | else {
|
---|
1953 | /* CI mode Logic Op */
|
---|
1954 | if (ctx->Color.IndexLogicOpEnabled) {
|
---|
1955 | if (ctx->Driver.LogicOp
|
---|
1956 | && (*ctx->Driver.LogicOp)( ctx, ctx->Color.LogicOp )) {
|
---|
1957 | /* Device driver can do logic, don't have to do it in software */
|
---|
1958 | ctx->Color.SWLogicOpEnabled = GL_FALSE;
|
---|
1959 | }
|
---|
1960 | else {
|
---|
1961 | /* Device driver can't do logic op so we do it in software */
|
---|
1962 | ctx->Color.SWLogicOpEnabled = GL_TRUE;
|
---|
1963 | }
|
---|
1964 | }
|
---|
1965 | else {
|
---|
1966 | /* no logic op */
|
---|
1967 | if (ctx->Driver.LogicOp) {
|
---|
1968 | (void) (*ctx->Driver.LogicOp)( ctx, GL_COPY );
|
---|
1969 | }
|
---|
1970 | ctx->Color.SWLogicOpEnabled = GL_FALSE;
|
---|
1971 | }
|
---|
1972 | }
|
---|
1973 | }
|
---|
1974 |
|
---|
1975 |
|
---|
1976 |
|
---|
1977 | /*
|
---|
1978 | * Check if software implemented RGBA or Color Index masking is needed.
|
---|
1979 | */
|
---|
1980 | static void update_pixel_masking( GLcontext *ctx )
|
---|
1981 | {
|
---|
1982 | if (ctx->Visual->RGBAflag) {
|
---|
1983 | GLuint *colorMask = (GLuint *) ctx->Color.ColorMask;
|
---|
1984 | if (*colorMask == 0xffffffff) {
|
---|
1985 | /* disable masking */
|
---|
1986 | if (ctx->Driver.ColorMask) {
|
---|
1987 | (void) (*ctx->Driver.ColorMask)( ctx, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
|
---|
1988 | }
|
---|
1989 | ctx->Color.SWmasking = GL_FALSE;
|
---|
1990 | }
|
---|
1991 | else {
|
---|
1992 | /* Ask driver to do color masking, if it can't then
|
---|
1993 | * do it in software
|
---|
1994 | */
|
---|
1995 | GLboolean red = ctx->Color.ColorMask[RCOMP] ? GL_TRUE : GL_FALSE;
|
---|
1996 | GLboolean green = ctx->Color.ColorMask[GCOMP] ? GL_TRUE : GL_FALSE;
|
---|
1997 | GLboolean blue = ctx->Color.ColorMask[BCOMP] ? GL_TRUE : GL_FALSE;
|
---|
1998 | GLboolean alpha = ctx->Color.ColorMask[ACOMP] ? GL_TRUE : GL_FALSE;
|
---|
1999 | if (ctx->Driver.ColorMask
|
---|
2000 | && (*ctx->Driver.ColorMask)( ctx, red, green, blue, alpha )) {
|
---|
2001 | ctx->Color.SWmasking = GL_FALSE;
|
---|
2002 | }
|
---|
2003 | else {
|
---|
2004 | ctx->Color.SWmasking = GL_TRUE;
|
---|
2005 | }
|
---|
2006 | }
|
---|
2007 | }
|
---|
2008 | else {
|
---|
2009 | if (ctx->Color.IndexMask==0xffffffff) {
|
---|
2010 | /* disable masking */
|
---|
2011 | if (ctx->Driver.IndexMask) {
|
---|
2012 | (void) (*ctx->Driver.IndexMask)( ctx, 0xffffffff );
|
---|
2013 | }
|
---|
2014 | ctx->Color.SWmasking = GL_FALSE;
|
---|
2015 | }
|
---|
2016 | else {
|
---|
2017 | /* Ask driver to do index masking, if it can't then
|
---|
2018 | * do it in software
|
---|
2019 | */
|
---|
2020 | if (ctx->Driver.IndexMask
|
---|
2021 | && (*ctx->Driver.IndexMask)( ctx, ctx->Color.IndexMask )) {
|
---|
2022 | ctx->Color.SWmasking = GL_FALSE;
|
---|
2023 | }
|
---|
2024 | else {
|
---|
2025 | ctx->Color.SWmasking = GL_TRUE;
|
---|
2026 | }
|
---|
2027 | }
|
---|
2028 | }
|
---|
2029 | }
|
---|
2030 |
|
---|
2031 |
|
---|
2032 | static void update_fog_mode( GLcontext *ctx )
|
---|
2033 | {
|
---|
2034 | int old_mode = ctx->FogMode;
|
---|
2035 | ctx->FogMode = FOG_NONE;
|
---|
2036 |
|
---|
2037 | if (ctx->Fog.Enabled) {
|
---|
2038 | ctx->FogMode = FOG_VERTEX;
|
---|
2039 |
|
---|
2040 | if (ctx->Texture.Enabled || ctx->Hint.Fog == GL_NICEST)
|
---|
2041 | ctx->FogMode = FOG_FRAGMENT;
|
---|
2042 |
|
---|
2043 | if ( ctx->Driver.GetParameteri &&
|
---|
2044 | ctx->Driver.GetParameteri( ctx, DD_HAVE_HARDWARE_FOG ) )
|
---|
2045 | ctx->FogMode = FOG_FRAGMENT;
|
---|
2046 | }
|
---|
2047 |
|
---|
2048 | if (old_mode != ctx->FogMode)
|
---|
2049 | ctx->NewState |= NEW_FOG;
|
---|
2050 | }
|
---|
2051 |
|
---|
2052 |
|
---|
2053 | /*
|
---|
2054 | * Recompute the value of ctx->RasterMask, etc. according to
|
---|
2055 | * the current context.
|
---|
2056 | */
|
---|
2057 | static void update_rasterflags( GLcontext *ctx )
|
---|
2058 | {
|
---|
2059 | ctx->RasterMask = 0;
|
---|
2060 |
|
---|
2061 | if (ctx->Color.AlphaEnabled) ctx->RasterMask |= ALPHATEST_BIT;
|
---|
2062 | if (ctx->Color.BlendEnabled) ctx->RasterMask |= BLEND_BIT;
|
---|
2063 | if (ctx->Depth.Test) ctx->RasterMask |= DEPTH_BIT;
|
---|
2064 | if (ctx->FogMode==FOG_FRAGMENT) ctx->RasterMask |= FOG_BIT;
|
---|
2065 | if (ctx->Color.SWLogicOpEnabled) ctx->RasterMask |= LOGIC_OP_BIT;
|
---|
2066 | if (ctx->Scissor.Enabled) ctx->RasterMask |= SCISSOR_BIT;
|
---|
2067 | if (ctx->Stencil.Enabled) ctx->RasterMask |= STENCIL_BIT;
|
---|
2068 | if (ctx->Color.SWmasking) ctx->RasterMask |= MASKING_BIT;
|
---|
2069 |
|
---|
2070 | if (ctx->Visual->SoftwareAlpha && ctx->Color.ColorMask[ACOMP]
|
---|
2071 | && ctx->Color.DrawBuffer != GL_NONE)
|
---|
2072 | ctx->RasterMask |= ALPHABUF_BIT;
|
---|
2073 |
|
---|
2074 | if ( ctx->Viewport.X<0
|
---|
2075 | || ctx->Viewport.X + ctx->Viewport.Width > ctx->Buffer->Width
|
---|
2076 | || ctx->Viewport.Y<0
|
---|
2077 | || ctx->Viewport.Y + ctx->Viewport.Height > ctx->Buffer->Height) {
|
---|
2078 | ctx->RasterMask |= WINCLIP_BIT;
|
---|
2079 | }
|
---|
2080 |
|
---|
2081 | /* If we're not drawing to exactly one color buffer set the
|
---|
2082 | * MULTI_DRAW_BIT flag. Also set it if we're drawing to no
|
---|
2083 | * buffers or the RGBA or CI mask disables all writes.
|
---|
2084 | */
|
---|
2085 |
|
---|
2086 | ctx->TriangleCaps &= ~DD_MULTIDRAW;
|
---|
2087 |
|
---|
2088 | if (ctx->Color.MultiDrawBuffer) {
|
---|
2089 | ctx->RasterMask |= MULTI_DRAW_BIT;
|
---|
2090 | ctx->TriangleCaps |= DD_MULTIDRAW;
|
---|
2091 | }
|
---|
2092 | else if (ctx->Color.DrawBuffer==GL_NONE) {
|
---|
2093 | ctx->RasterMask |= MULTI_DRAW_BIT;
|
---|
2094 | ctx->TriangleCaps |= DD_MULTIDRAW;
|
---|
2095 | }
|
---|
2096 | else if (ctx->Visual->RGBAflag && ctx->Color.ColorMask==0) {
|
---|
2097 | /* all RGBA channels disabled */
|
---|
2098 | ctx->RasterMask |= MULTI_DRAW_BIT;
|
---|
2099 | ctx->TriangleCaps |= DD_MULTIDRAW;
|
---|
2100 | ctx->Color.DrawDestMask = 0;
|
---|
2101 | }
|
---|
2102 | else if (!ctx->Visual->RGBAflag && ctx->Color.IndexMask==0) {
|
---|
2103 | /* all color index bits disabled */
|
---|
2104 | ctx->RasterMask |= MULTI_DRAW_BIT;
|
---|
2105 | ctx->TriangleCaps |= DD_MULTIDRAW;
|
---|
2106 | ctx->Color.DrawDestMask = 0;
|
---|
2107 | }
|
---|
2108 | }
|
---|
2109 |
|
---|
2110 |
|
---|
2111 | void gl_print_state( const char *msg, GLuint state )
|
---|
2112 | {
|
---|
2113 | fprintf(stderr,
|
---|
2114 | "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
|
---|
2115 | msg,
|
---|
2116 | state,
|
---|
2117 | (state & NEW_LIGHTING) ? "lighting, " : "",
|
---|
2118 | (state & NEW_RASTER_OPS) ? "raster-ops, " : "",
|
---|
2119 | (state & NEW_TEXTURING) ? "texturing, " : "",
|
---|
2120 | (state & NEW_POLYGON) ? "polygon, " : "",
|
---|
2121 | (state & NEW_DRVSTATE0) ? "driver-0, " : "",
|
---|
2122 | (state & NEW_DRVSTATE1) ? "driver-1, " : "",
|
---|
2123 | (state & NEW_DRVSTATE2) ? "driver-2, " : "",
|
---|
2124 | (state & NEW_DRVSTATE3) ? "driver-3, " : "",
|
---|
2125 | (state & NEW_MODELVIEW) ? "modelview, " : "",
|
---|
2126 | (state & NEW_PROJECTION) ? "projection, " : "",
|
---|
2127 | (state & NEW_TEXTURE_MATRIX) ? "texture-matrix, " : "",
|
---|
2128 | (state & NEW_USER_CLIP) ? "user-clip, " : "",
|
---|
2129 | (state & NEW_TEXTURE_ENV) ? "texture-env, " : "",
|
---|
2130 | (state & NEW_CLIENT_STATE) ? "client-state, " : "",
|
---|
2131 | (state & NEW_FOG) ? "fog, " : "",
|
---|
2132 | (state & NEW_NORMAL_TRANSFORM) ? "normal-transform, " : "",
|
---|
2133 | (state & NEW_VIEWPORT) ? "viewport, " : "",
|
---|
2134 | (state & NEW_TEXTURE_ENABLE) ? "texture-enable, " : "");
|
---|
2135 | }
|
---|
2136 |
|
---|
2137 | void gl_print_enable_flags( const char *msg, GLuint flags )
|
---|
2138 | {
|
---|
2139 | fprintf(stderr,
|
---|
2140 | "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s\n",
|
---|
2141 | msg,
|
---|
2142 | flags,
|
---|
2143 | (flags & ENABLE_TEX0) ? "tex-0, " : "",
|
---|
2144 | (flags & ENABLE_TEX1) ? "tex-1, " : "",
|
---|
2145 | (flags & ENABLE_LIGHT) ? "light, " : "",
|
---|
2146 | (flags & ENABLE_FOG) ? "fog, " : "",
|
---|
2147 | (flags & ENABLE_USERCLIP) ? "userclip, " : "",
|
---|
2148 | (flags & ENABLE_TEXGEN0) ? "tex-gen-0, " : "",
|
---|
2149 | (flags & ENABLE_TEXGEN1) ? "tex-gen-1, " : "",
|
---|
2150 | (flags & ENABLE_TEXMAT0) ? "tex-mat-0, " : "",
|
---|
2151 | (flags & ENABLE_TEXMAT1) ? "tex-mat-1, " : "",
|
---|
2152 | (flags & ENABLE_NORMALIZE) ? "normalize, " : "",
|
---|
2153 | (flags & ENABLE_RESCALE) ? "rescale, " : "");
|
---|
2154 | }
|
---|
2155 |
|
---|
2156 |
|
---|
2157 | /*
|
---|
2158 | * If ctx->NewState is non-zero then this function MUST be called before
|
---|
2159 | * rendering any primitive. Basically, function pointers and miscellaneous
|
---|
2160 | * flags are updated to reflect the current state of the state machine.
|
---|
2161 | */
|
---|
2162 | void gl_update_state( GLcontext *ctx )
|
---|
2163 | {
|
---|
2164 | GLuint i;
|
---|
2165 |
|
---|
2166 | if (MESA_VERBOSE & VERBOSE_STATE)
|
---|
2167 | gl_print_state("", ctx->NewState);
|
---|
2168 |
|
---|
2169 | if (ctx->NewState & NEW_CLIENT_STATE)
|
---|
2170 | gl_update_client_state( ctx );
|
---|
2171 |
|
---|
2172 | if ((ctx->NewState & NEW_TEXTURE_ENABLE) &&
|
---|
2173 | (ctx->Enabled & ENABLE_TEX_ANY) != ctx->Texture.Enabled)
|
---|
2174 | ctx->NewState |= NEW_TEXTURING | NEW_RASTER_OPS;
|
---|
2175 |
|
---|
2176 | if (ctx->NewState & NEW_TEXTURE_ENV) {
|
---|
2177 | if (ctx->Texture.Unit[0].EnvMode == ctx->Texture.Unit[0].LastEnvMode &&
|
---|
2178 | ctx->Texture.Unit[1].EnvMode == ctx->Texture.Unit[1].LastEnvMode)
|
---|
2179 | ctx->NewState &= ~NEW_TEXTURE_ENV;
|
---|
2180 | ctx->Texture.Unit[0].LastEnvMode = ctx->Texture.Unit[0].EnvMode;
|
---|
2181 | ctx->Texture.Unit[1].LastEnvMode = ctx->Texture.Unit[1].EnvMode;
|
---|
2182 | }
|
---|
2183 |
|
---|
2184 | if (ctx->NewState & NEW_TEXTURE_MATRIX) {
|
---|
2185 | ctx->Enabled &= ~(ENABLE_TEXMAT0|ENABLE_TEXMAT1);
|
---|
2186 |
|
---|
2187 | for (i=0; i < MAX_TEXTURE_UNITS; i++) {
|
---|
2188 | if (ctx->TextureMatrix[i].flags & MAT_DIRTY_ALL_OVER)
|
---|
2189 | {
|
---|
2190 | gl_matrix_analyze( &ctx->TextureMatrix[i] );
|
---|
2191 | ctx->TextureMatrix[i].flags &= ~MAT_DIRTY_DEPENDENTS;
|
---|
2192 |
|
---|
2193 | if (ctx->Texture.Unit[i].Enabled &&
|
---|
2194 | ctx->TextureMatrix[i].type != MATRIX_IDENTITY)
|
---|
2195 | ctx->Enabled |= ENABLE_TEXMAT0 << i;
|
---|
2196 | }
|
---|
2197 | }
|
---|
2198 | }
|
---|
2199 |
|
---|
2200 | if (ctx->NewState & (NEW_TEXTURING | NEW_TEXTURE_ENABLE)) {
|
---|
2201 | ctx->Texture.NeedNormals = GL_FALSE;
|
---|
2202 | gl_update_dirty_texobjs(ctx);
|
---|
2203 | ctx->Enabled &= ~(ENABLE_TEXGEN0|ENABLE_TEXGEN1);
|
---|
2204 | ctx->Texture.ReallyEnabled = 0;
|
---|
2205 |
|
---|
2206 | for (i=0; i < MAX_TEXTURE_UNITS; i++) {
|
---|
2207 | if (ctx->Texture.Unit[i].Enabled) {
|
---|
2208 | gl_update_texture_unit( ctx, &ctx->Texture.Unit[i] );
|
---|
2209 |
|
---|
2210 | ctx->Texture.ReallyEnabled |=
|
---|
2211 | ctx->Texture.Unit[i].ReallyEnabled<<(i*4);
|
---|
2212 |
|
---|
2213 | if (ctx->Texture.Unit[i].GenFlags != 0) {
|
---|
2214 | ctx->Enabled |= ENABLE_TEXGEN0 << i;
|
---|
2215 |
|
---|
2216 | if (ctx->Texture.Unit[i].GenFlags & TEXGEN_NEED_NORMALS)
|
---|
2217 | {
|
---|
2218 | ctx->Texture.NeedNormals = GL_TRUE;
|
---|
2219 | ctx->Texture.NeedEyeCoords = GL_TRUE;
|
---|
2220 | }
|
---|
2221 |
|
---|
2222 | if (ctx->Texture.Unit[i].GenFlags & TEXGEN_NEED_EYE_COORD)
|
---|
2223 | {
|
---|
2224 | ctx->Texture.NeedEyeCoords = GL_TRUE;
|
---|
2225 | }
|
---|
2226 | }
|
---|
2227 | }
|
---|
2228 | }
|
---|
2229 |
|
---|
2230 | ctx->Texture.Enabled = ctx->Enabled & ENABLE_TEX_ANY;
|
---|
2231 | ctx->NeedNormals = (ctx->Light.Enabled || ctx->Texture.NeedNormals);
|
---|
2232 | }
|
---|
2233 |
|
---|
2234 | if (ctx->NewState & (NEW_RASTER_OPS | NEW_LIGHTING | NEW_FOG)) {
|
---|
2235 |
|
---|
2236 |
|
---|
2237 | if (ctx->NewState & NEW_RASTER_OPS) {
|
---|
2238 | update_pixel_logic(ctx);
|
---|
2239 | update_pixel_masking(ctx);
|
---|
2240 | update_fog_mode(ctx);
|
---|
2241 | update_rasterflags(ctx);
|
---|
2242 | if (ctx->Driver.Dither) {
|
---|
2243 | (*ctx->Driver.Dither)( ctx, ctx->Color.DitherFlag );
|
---|
2244 | }
|
---|
2245 |
|
---|
2246 | /* Check if incoming colors can be modified during rasterization */
|
---|
2247 | if (ctx->Fog.Enabled ||
|
---|
2248 | ctx->Texture.Enabled ||
|
---|
2249 | ctx->Color.BlendEnabled ||
|
---|
2250 | ctx->Color.SWmasking ||
|
---|
2251 | ctx->Color.SWLogicOpEnabled) {
|
---|
2252 | ctx->MutablePixels = GL_TRUE;
|
---|
2253 | }
|
---|
2254 | else {
|
---|
2255 | ctx->MutablePixels = GL_FALSE;
|
---|
2256 | }
|
---|
2257 |
|
---|
2258 | /* update scissor region */
|
---|
2259 |
|
---|
2260 | ctx->Buffer->Xmin = 0;
|
---|
2261 | ctx->Buffer->Ymin = 0;
|
---|
2262 | ctx->Buffer->Xmax = ctx->Buffer->Width-1;
|
---|
2263 | ctx->Buffer->Ymax = ctx->Buffer->Height-1;
|
---|
2264 | if (ctx->Scissor.Enabled) {
|
---|
2265 | if (ctx->Scissor.X > ctx->Buffer->Xmin) {
|
---|
2266 | ctx->Buffer->Xmin = ctx->Scissor.X;
|
---|
2267 | }
|
---|
2268 | if (ctx->Scissor.Y > ctx->Buffer->Ymin) {
|
---|
2269 | ctx->Buffer->Ymin = ctx->Scissor.Y;
|
---|
2270 | }
|
---|
2271 | if (ctx->Scissor.X + ctx->Scissor.Width - 1 < ctx->Buffer->Xmax) {
|
---|
2272 | ctx->Buffer->Xmax = ctx->Scissor.X + ctx->Scissor.Width - 1;
|
---|
2273 | }
|
---|
2274 | if (ctx->Scissor.Y + ctx->Scissor.Height - 1 < ctx->Buffer->Ymax) {
|
---|
2275 | ctx->Buffer->Ymax = ctx->Scissor.Y + ctx->Scissor.Height - 1;
|
---|
2276 | }
|
---|
2277 | }
|
---|
2278 |
|
---|
2279 | /* The driver isn't managing the depth buffer.
|
---|
2280 | */
|
---|
2281 | if (ctx->Driver.AllocDepthBuffer == gl_alloc_depth_buffer)
|
---|
2282 | {
|
---|
2283 | if (ctx->Depth.Mask) {
|
---|
2284 | switch (ctx->Depth.Func) {
|
---|
2285 | case GL_LESS:
|
---|
2286 | ctx->Driver.DepthTestSpan = gl_depth_test_span_less;
|
---|
2287 | ctx->Driver.DepthTestPixels = gl_depth_test_pixels_less;
|
---|
2288 | break;
|
---|
2289 | case GL_GREATER:
|
---|
2290 | ctx->Driver.DepthTestSpan = gl_depth_test_span_greater;
|
---|
2291 | ctx->Driver.DepthTestPixels = gl_depth_test_pixels_greater;
|
---|
2292 | break;
|
---|
2293 | default:
|
---|
2294 | ctx->Driver.DepthTestSpan = gl_depth_test_span_generic;
|
---|
2295 | ctx->Driver.DepthTestPixels = gl_depth_test_pixels_generic;
|
---|
2296 | }
|
---|
2297 | }
|
---|
2298 | else {
|
---|
2299 | ctx->Driver.DepthTestSpan = gl_depth_test_span_generic;
|
---|
2300 | ctx->Driver.DepthTestPixels = gl_depth_test_pixels_generic;
|
---|
2301 | }
|
---|
2302 | }
|
---|
2303 | }
|
---|
2304 |
|
---|
2305 | if (ctx->NewState & NEW_LIGHTING) {
|
---|
2306 | ctx->TriangleCaps &= ~(DD_TRI_LIGHT_TWOSIDE|DD_LIGHTING_CULL);
|
---|
2307 | if (ctx->Light.Enabled) {
|
---|
2308 | if (ctx->Light.Model.TwoSide)
|
---|
2309 | ctx->TriangleCaps |= (DD_TRI_LIGHT_TWOSIDE|DD_LIGHTING_CULL);
|
---|
2310 | gl_update_lighting(ctx);
|
---|
2311 | }
|
---|
2312 | }
|
---|
2313 | }
|
---|
2314 |
|
---|
2315 | if (ctx->NewState & (NEW_POLYGON | NEW_LIGHTING)) {
|
---|
2316 |
|
---|
2317 | ctx->TriangleCaps &= ~DD_TRI_CULL_FRONT_BACK;
|
---|
2318 |
|
---|
2319 | if (ctx->NewState & NEW_POLYGON) {
|
---|
2320 | /* Setup CullBits bitmask */
|
---|
2321 | if (ctx->Polygon.CullFlag) {
|
---|
2322 | ctx->backface_sign = 1;
|
---|
2323 | switch(ctx->Polygon.CullFaceMode) {
|
---|
2324 | case GL_BACK:
|
---|
2325 | if(ctx->Polygon.FrontFace==GL_CCW)
|
---|
2326 | ctx->backface_sign = -1;
|
---|
2327 | ctx->Polygon.CullBits = 1;
|
---|
2328 | break;
|
---|
2329 | case GL_FRONT:
|
---|
2330 | if(ctx->Polygon.FrontFace!=GL_CCW)
|
---|
2331 | ctx->backface_sign = -1;
|
---|
2332 | ctx->Polygon.CullBits = 2;
|
---|
2333 | break;
|
---|
2334 | default:
|
---|
2335 | case GL_FRONT_AND_BACK:
|
---|
2336 | ctx->backface_sign = 0;
|
---|
2337 | ctx->Polygon.CullBits = 0;
|
---|
2338 | ctx->TriangleCaps |= DD_TRI_CULL_FRONT_BACK;
|
---|
2339 | break;
|
---|
2340 | }
|
---|
2341 | }
|
---|
2342 | else {
|
---|
2343 | ctx->Polygon.CullBits = 3;
|
---|
2344 | ctx->backface_sign = 0;
|
---|
2345 | }
|
---|
2346 |
|
---|
2347 | /* Any Polygon offsets enabled? */
|
---|
2348 | ctx->TriangleCaps &= ~DD_TRI_OFFSET;
|
---|
2349 |
|
---|
2350 | if (ctx->Polygon.OffsetPoint ||
|
---|
2351 | ctx->Polygon.OffsetLine ||
|
---|
2352 | ctx->Polygon.OffsetFill)
|
---|
2353 | ctx->TriangleCaps |= DD_TRI_OFFSET;
|
---|
2354 |
|
---|
2355 | /* reset Z offsets now */
|
---|
2356 | ctx->PointZoffset = 0.0;
|
---|
2357 | ctx->LineZoffset = 0.0;
|
---|
2358 | ctx->PolygonZoffset = 0.0;
|
---|
2359 | }
|
---|
2360 | }
|
---|
2361 |
|
---|
2362 | if (ctx->NewState & ~(NEW_CLIENT_STATE|
|
---|
2363 | NEW_DRIVER_STATE|NEW_USER_CLIP|
|
---|
2364 | NEW_POLYGON))
|
---|
2365 | gl_update_clipmask(ctx);
|
---|
2366 |
|
---|
2367 | if (ctx->NewState & (NEW_LIGHTING|
|
---|
2368 | NEW_RASTER_OPS|
|
---|
2369 | NEW_TEXTURING|
|
---|
2370 | NEW_TEXTURE_ENABLE|
|
---|
2371 | NEW_TEXTURE_ENV|
|
---|
2372 | NEW_POLYGON|
|
---|
2373 | NEW_DRVSTATE0|
|
---|
2374 | NEW_DRVSTATE1|
|
---|
2375 | NEW_DRVSTATE2|
|
---|
2376 | NEW_DRVSTATE3|
|
---|
2377 | NEW_USER_CLIP))
|
---|
2378 | {
|
---|
2379 | ctx->IndirectTriangles = ctx->TriangleCaps & ~ctx->Driver.TriangleCaps;
|
---|
2380 | ctx->IndirectTriangles |= DD_SW_RASTERIZE;
|
---|
2381 |
|
---|
2382 | if (MESA_VERBOSE&VERBOSE_CULL)
|
---|
2383 | gl_print_tri_caps("initial indirect tris", ctx->IndirectTriangles);
|
---|
2384 |
|
---|
2385 | ctx->Driver.PointsFunc = NULL;
|
---|
2386 | ctx->Driver.LineFunc = NULL;
|
---|
2387 | ctx->Driver.TriangleFunc = NULL;
|
---|
2388 | ctx->Driver.QuadFunc = NULL;
|
---|
2389 | ctx->Driver.RectFunc = NULL;
|
---|
2390 | ctx->Driver.RenderVBClippedTab = NULL;
|
---|
2391 | ctx->Driver.RenderVBCulledTab = NULL;
|
---|
2392 | ctx->Driver.RenderVBRawTab = NULL;
|
---|
2393 |
|
---|
2394 | /*
|
---|
2395 | * Here the driver sets up all the ctx->Driver function pointers to
|
---|
2396 | * it's specific, private functions.
|
---|
2397 | */
|
---|
2398 | ctx->Driver.UpdateState(ctx);
|
---|
2399 |
|
---|
2400 | if (MESA_VERBOSE&VERBOSE_CULL)
|
---|
2401 | gl_print_tri_caps("indirect tris", ctx->IndirectTriangles);
|
---|
2402 |
|
---|
2403 | /*
|
---|
2404 | * In case the driver didn't hook in an optimized point, line or
|
---|
2405 | * triangle function we'll now select "core/fallback" point, line
|
---|
2406 | * and triangle functions.
|
---|
2407 | */
|
---|
2408 | if (ctx->IndirectTriangles & DD_SW_RASTERIZE) {
|
---|
2409 | gl_set_point_function(ctx);
|
---|
2410 | gl_set_line_function(ctx);
|
---|
2411 | gl_set_triangle_function(ctx);
|
---|
2412 | gl_set_quad_function(ctx);
|
---|
2413 |
|
---|
2414 | if ((ctx->IndirectTriangles &
|
---|
2415 | (DD_TRI_SW_RASTERIZE|DD_QUAD_SW_RASTERIZE|DD_TRI_CULL)) ==
|
---|
2416 | (DD_TRI_SW_RASTERIZE|DD_QUAD_SW_RASTERIZE|DD_TRI_CULL))
|
---|
2417 | ctx->IndirectTriangles &= ~DD_TRI_CULL;
|
---|
2418 | }
|
---|
2419 |
|
---|
2420 | if (MESA_VERBOSE&VERBOSE_CULL)
|
---|
2421 | gl_print_tri_caps("indirect tris 2", ctx->IndirectTriangles);
|
---|
2422 |
|
---|
2423 | gl_set_render_vb_function(ctx);
|
---|
2424 | }
|
---|
2425 |
|
---|
2426 | /* Should only be calc'd when !need_eye_coords and not culling.
|
---|
2427 | */
|
---|
2428 | if (ctx->NewState & (NEW_MODELVIEW|NEW_PROJECTION)) {
|
---|
2429 | if (ctx->NewState & NEW_MODELVIEW) {
|
---|
2430 | gl_matrix_analyze( &ctx->ModelView );
|
---|
2431 | ctx->ProjectionMatrix.flags &= ~MAT_DIRTY_DEPENDENTS;
|
---|
2432 | }
|
---|
2433 |
|
---|
2434 | if (ctx->NewState & NEW_PROJECTION) {
|
---|
2435 | gl_matrix_analyze( &ctx->ProjectionMatrix );
|
---|
2436 | ctx->ProjectionMatrix.flags &= ~MAT_DIRTY_DEPENDENTS;
|
---|
2437 |
|
---|
2438 | if (ctx->Transform.AnyClip) {
|
---|
2439 | gl_update_userclip( ctx );
|
---|
2440 | }
|
---|
2441 | }
|
---|
2442 |
|
---|
2443 | gl_calculate_model_project_matrix( ctx );
|
---|
2444 | ctx->ModelProjectWinMatrixUptodate = 0;
|
---|
2445 | }
|
---|
2446 |
|
---|
2447 | /* Figure out whether we can light in object space or not. If we
|
---|
2448 | * can, find the current positions of the lights in object space
|
---|
2449 | */
|
---|
2450 | if ((ctx->Enabled & (ENABLE_POINT_ATTEN | ENABLE_LIGHT | ENABLE_FOG |
|
---|
2451 | ENABLE_TEXGEN0 | ENABLE_TEXGEN1)) &&
|
---|
2452 | (ctx->NewState & (NEW_LIGHTING |
|
---|
2453 | NEW_FOG |
|
---|
2454 | NEW_MODELVIEW |
|
---|
2455 | NEW_PROJECTION |
|
---|
2456 | NEW_TEXTURING |
|
---|
2457 | NEW_RASTER_OPS |
|
---|
2458 | NEW_USER_CLIP)))
|
---|
2459 | {
|
---|
2460 | GLboolean oldcoord, oldnorm;
|
---|
2461 |
|
---|
2462 | oldcoord = ctx->NeedEyeCoords;
|
---|
2463 | oldnorm = ctx->NeedEyeNormals;
|
---|
2464 |
|
---|
2465 | ctx->NeedNormals = (ctx->Light.Enabled || ctx->Texture.NeedNormals);
|
---|
2466 | ctx->NeedEyeCoords = (ctx->FogMode == FOG_VERTEX ||
|
---|
2467 | ctx->Point.Attenuated);
|
---|
2468 | ctx->NeedEyeNormals = GL_FALSE;
|
---|
2469 |
|
---|
2470 | if (ctx->Light.Enabled) {
|
---|
2471 | if (ctx->Light.Flags & LIGHT_POSITIONAL) {
|
---|
2472 | /* Need length for attenuation */
|
---|
2473 | if (!TEST_MAT_FLAGS( &ctx->ModelView, MAT_FLAGS_LENGTH_PRESERVING))
|
---|
2474 | ctx->NeedEyeCoords = GL_TRUE;
|
---|
2475 | } else if (ctx->Light.NeedVertices) {
|
---|
2476 | /* Need angle for spot calculations */
|
---|
2477 | if (!TEST_MAT_FLAGS( &ctx->ModelView, MAT_FLAGS_ANGLE_PRESERVING))
|
---|
2478 | ctx->NeedEyeCoords = GL_TRUE;
|
---|
2479 | }
|
---|
2480 | ctx->NeedEyeNormals = ctx->NeedEyeCoords;
|
---|
2481 | }
|
---|
2482 | if (ctx->Texture.Enabled || ctx->RenderMode==GL_FEEDBACK) {
|
---|
2483 | if (ctx->Texture.NeedEyeCoords) ctx->NeedEyeCoords = GL_TRUE;
|
---|
2484 | if (ctx->Texture.NeedNormals)
|
---|
2485 | ctx->NeedNormals = ctx->NeedEyeNormals = GL_TRUE;
|
---|
2486 | }
|
---|
2487 |
|
---|
2488 | ctx->vb_proj_matrix = &ctx->ModelProjectMatrix;
|
---|
2489 |
|
---|
2490 | if (ctx->NeedEyeCoords)
|
---|
2491 | ctx->vb_proj_matrix = &ctx->ProjectionMatrix;
|
---|
2492 |
|
---|
2493 | if (ctx->Light.Enabled) {
|
---|
2494 | gl_update_lighting_function(ctx);
|
---|
2495 |
|
---|
2496 | if ( (ctx->NewState & NEW_LIGHTING) ||
|
---|
2497 | ((ctx->NewState & (NEW_MODELVIEW| NEW_PROJECTION)) &&
|
---|
2498 | !ctx->NeedEyeCoords) ||
|
---|
2499 | oldcoord != ctx->NeedEyeCoords ||
|
---|
2500 | oldnorm != ctx->NeedEyeNormals) {
|
---|
2501 | gl_compute_light_positions(ctx);
|
---|
2502 | }
|
---|
2503 |
|
---|
2504 | ctx->rescale_factor = 1.0F;
|
---|
2505 |
|
---|
2506 | if (ctx->ModelView.flags & (MAT_FLAG_UNIFORM_SCALE |
|
---|
2507 | MAT_FLAG_GENERAL_SCALE |
|
---|
2508 | MAT_FLAG_GENERAL_3D |
|
---|
2509 | MAT_FLAG_GENERAL) )
|
---|
2510 |
|
---|
2511 | {
|
---|
2512 | GLfloat *m = ctx->ModelView.inv;
|
---|
2513 | GLfloat f = m[2]*m[2] + m[6]*m[6] + m[10]*m[10];
|
---|
2514 | if (f > 1e-12 && (f-1)*(f-1) > 1e-12)
|
---|
2515 | ctx->rescale_factor = 1.0/GL_SQRT(f);
|
---|
2516 | }
|
---|
2517 | }
|
---|
2518 |
|
---|
2519 | gl_update_normal_transform( ctx );
|
---|
2520 | }
|
---|
2521 |
|
---|
2522 | gl_update_pipelines(ctx);
|
---|
2523 | ctx->NewState = 0;
|
---|
2524 | }
|
---|