2 * Mesa 3-D graphics library
5 * Copyright (C) 1999 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * DOS/DJGPP device driver v1.1 for Mesa 4.0
28 * Copyright (C) 2002 - Borca Daniel
29 * Email : dborca@yahoo.com
30 * Web : http://www.geocities.com/dborca
37 #include "extensions.h"
41 #include "texformat.h"
43 #include "array_cache/acache.h"
44 #include "swrast/s_context.h"
45 #include "swrast/s_depth.h"
46 #include "swrast/s_lines.h"
47 #include "swrast/s_triangle.h"
48 #include "swrast/s_trispan.h"
49 #include "swrast/swrast.h"
50 #include "swrast_setup/swrast_setup.h"
52 #include "tnl/t_context.h"
53 #include "tnl/t_pipeline.h"
60 * In C++ terms, this class derives from the GLvisual class.
61 * Add system-specific fields to it.
65 GLboolean db_flag
; /* double buffered? */
66 GLboolean rgb_flag
; /* RGB mode? */
67 GLuint depth
; /* bits per pixel (1, 8, 24, etc) */
71 * In C++ terms, this class derives from the GLframebuffer class.
72 * Add system-specific fields to it.
75 GLframebuffer gl_buffer
; /* The depth, stencil, accum, etc buffers */
76 void *the_window
; /* your window handle, etc */
78 int xpos
, ypos
; /* position */
79 int width
, height
; /* size in pixels */
80 int bypp
, stride
, bytes
; /* bytes per pixel, in a line, then total */
84 * In C++ terms, this class derives from the GLcontext class.
85 * Add system-specific fields to it.
87 struct dmesa_context
{
88 GLcontext
*gl_ctx
; /* the core library context */
97 static void dmesa_update_state (GLcontext
*ctx
, GLuint new_state
);
101 /**********************************************************************/
102 /***** Read/Write pixels *****/
103 /**********************************************************************/
107 #define FLIP(y) (c->Buffer->height - (y) - 1)
108 #define FLIP2(y) (h - (y) - 1)
112 static void write_rgba_span (const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
113 const GLubyte rgba
[][4], const GLubyte mask
[])
115 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
116 void *b
= c
->Buffer
->the_window
;
119 offset
= c
->Buffer
->width
* FLIP(y
) + x
;
121 /* draw some pixels */
122 for (i
=0; i
<n
; i
++, offset
++) {
124 vl_putpixel(b
, offset
, vl_mixrgba(rgba
[i
]));
128 /* draw all pixels */
129 for (i
=0; i
<n
; i
++, offset
++) {
130 vl_putpixel(b
, offset
, vl_mixrgba(rgba
[i
]));
135 static void write_rgb_span (const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
136 const GLubyte rgb
[][3], const GLubyte mask
[])
138 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
139 void *b
= c
->Buffer
->the_window
;
142 offset
= c
->Buffer
->width
* FLIP(y
) + x
;
144 /* draw some pixels */
145 for (i
=0; i
<n
; i
++, offset
++) {
147 vl_putpixel(b
, offset
, vl_mixrgb(rgb
[i
]));
151 /* draw all pixels */
152 for (i
=0; i
<n
; i
++, offset
++) {
153 vl_putpixel(b
, offset
, vl_mixrgb(rgb
[i
]));
158 static void write_mono_rgba_span (const GLcontext
*ctx
,
159 GLuint n
, GLint x
, GLint y
,
160 const GLchan color
[4], const GLubyte mask
[])
162 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
163 void *b
= c
->Buffer
->the_window
;
164 GLuint i
, offset
, rgba
= vl_mixrgba(color
);
166 offset
= c
->Buffer
->width
* FLIP(y
) + x
;
168 /* draw some pixels */
169 for (i
=0; i
<n
; i
++, offset
++) {
171 vl_putpixel(b
, offset
, rgba
);
175 /* draw all pixels */
176 for (i
=0; i
<n
; i
++, offset
++) {
177 vl_putpixel(b
, offset
, rgba
);
182 static void read_rgba_span (const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
185 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
186 void *b
= c
->Buffer
->the_window
;
189 offset
= c
->Buffer
->width
* FLIP(y
) + x
;
190 /* read all pixels */
191 for (i
=0; i
<n
; i
++, offset
++) {
192 vl_getrgba(b
, offset
, rgba
[i
]);
196 static void write_rgba_pixels (const GLcontext
*ctx
,
197 GLuint n
, const GLint x
[], const GLint y
[],
198 const GLubyte rgba
[][4], const GLubyte mask
[])
200 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
201 void *b
= c
->Buffer
->the_window
;
202 GLuint i
, w
= c
->Buffer
->width
, h
= c
->Buffer
->height
;
205 /* draw some pixels */
206 for (i
=0; i
<n
; i
++) {
208 vl_putpixel(b
, FLIP2(y
[i
])*w
+ x
[i
], vl_mixrgba(rgba
[i
]));
212 /* draw all pixels */
213 for (i
=0; i
<n
; i
++) {
214 vl_putpixel(b
, FLIP2(y
[i
])*w
+ x
[i
], vl_mixrgba(rgba
[i
]));
219 static void write_mono_rgba_pixels (const GLcontext
*ctx
,
220 GLuint n
, const GLint x
[], const GLint y
[],
221 const GLchan color
[4], const GLubyte mask
[])
223 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
224 void *b
= c
->Buffer
->the_window
;
225 GLuint i
, w
= c
->Buffer
->width
, h
= c
->Buffer
->height
, rgba
= vl_mixrgba(color
);
228 /* draw some pixels */
229 for (i
=0; i
<n
; i
++) {
231 vl_putpixel(b
, FLIP2(y
[i
])*w
+ x
[i
], rgba
);
235 /* draw all pixels */
236 for (i
=0; i
<n
; i
++) {
237 vl_putpixel(b
, FLIP2(y
[i
])*w
+ x
[i
], rgba
);
242 static void read_rgba_pixels (const GLcontext
*ctx
,
243 GLuint n
, const GLint x
[], const GLint y
[],
244 GLubyte rgba
[][4], const GLubyte mask
[])
246 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
247 void *b
= c
->Buffer
->the_window
;
248 GLuint i
, w
= c
->Buffer
->width
, h
= c
->Buffer
->height
;
251 /* read some pixels */
252 for (i
=0; i
<n
; i
++) {
254 vl_getrgba(b
, FLIP2(y
[i
])*w
+ x
[i
], rgba
[i
]);
258 /* read all pixels */
259 for (i
=0; i
<n
; i
++) {
260 vl_getrgba(b
, FLIP2(y
[i
])*w
+ x
[i
], rgba
[i
]);
267 /**********************************************************************/
268 /***** Optimized triangle rendering *****/
269 /**********************************************************************/
274 * flat, NON-depth-buffered, triangle.
276 static void tri_rgb_flat (GLcontext
*ctx
,
281 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
282 void *b
= c
->Buffer
->the_window
;
283 GLuint w
= c
->Buffer
->width
, h
= c
->Buffer
->height
;
285 #define SETUP_CODE GLuint rgb = vl_mixrgb(v2->color);
287 #define RENDER_SPAN(span) \
288 GLuint i, offset = FLIP2(span.y)*w + span.x; \
289 for (i = 0; i < span.count; i++, offset++) { \
290 vl_putpixel(b, offset, rgb); \
293 #include "swrast/s_tritemp.h"
299 * flat, depth-buffered, triangle.
301 static void tri_rgb_flat_z (GLcontext
*ctx
,
306 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
307 void *b
= c
->Buffer
->the_window
;
308 GLuint w
= c
->Buffer
->width
, h
= c
->Buffer
->height
;
311 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
312 #define SETUP_CODE GLuint rgb = vl_mixrgb(v2->color);
314 #define RENDER_SPAN(span) \
315 GLuint i, offset = FLIP2(span.y)*w + span.x; \
316 for (i = 0; i < span.count; i++, offset++) { \
317 const DEPTH_TYPE z = FixedToDepth(span.z); \
319 vl_putpixel(b, offset, rgb); \
322 span.z += span.zStep; \
325 #include "swrast/s_tritemp.h"
331 * smooth, NON-depth-buffered, triangle.
333 static void tri_rgb_smooth (GLcontext
*ctx
,
338 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
339 void *b
= c
->Buffer
->the_window
;
340 GLuint w
= c
->Buffer
->width
, h
= c
->Buffer
->height
;
343 #define RENDER_SPAN(span) \
344 GLuint i, offset = FLIP2(span.y)*w + span.x; \
345 for (i = 0; i < span.count; i++, offset++) { \
346 unsigned char rgb[3]; \
347 rgb[0] = FixedToInt(span.red); \
348 rgb[1] = FixedToInt(span.green); \
349 rgb[2] = FixedToInt(span.blue); \
350 vl_putpixel(b, offset, vl_mixrgb(rgb)); \
351 span.red += span.redStep; \
352 span.green += span.greenStep; \
353 span.blue += span.blueStep; \
356 #include "swrast/s_tritemp.h"
362 * smooth, depth-buffered, triangle.
364 static void tri_rgb_smooth_z (GLcontext
*ctx
,
369 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
370 void *b
= c
->Buffer
->the_window
;
371 GLuint w
= c
->Buffer
->width
, h
= c
->Buffer
->height
;
374 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
377 #define RENDER_SPAN(span) \
378 GLuint i, offset = FLIP2(span.y)*w + span.x; \
379 for (i = 0; i < span.count; i++, offset++) { \
380 const DEPTH_TYPE z = FixedToDepth(span.z); \
382 unsigned char rgb[3]; \
383 rgb[0] = FixedToInt(span.red); \
384 rgb[1] = FixedToInt(span.green); \
385 rgb[2] = FixedToInt(span.blue); \
386 vl_putpixel(b, offset, vl_mixrgb(rgb)); \
389 span.red += span.redStep; \
390 span.green += span.greenStep; \
391 span.blue += span.blueStep; \
392 span.z += span.zStep; \
395 #include "swrast/s_tritemp.h"
401 * Analyze context state to see if we can provide a fast triangle function
402 * Otherwise, return NULL.
404 static swrast_tri_func
dmesa_choose_tri_function (GLcontext
*ctx
)
406 const SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
408 if (ctx
->RenderMode
!= GL_RENDER
) return (swrast_tri_func
) NULL
;
409 if (ctx
->Polygon
.SmoothFlag
) return (swrast_tri_func
) NULL
;
410 if (ctx
->Texture
._EnabledUnits
) return (swrast_tri_func
) NULL
;
412 if (ctx
->Light
.ShadeModel
==GL_SMOOTH
413 && swrast
->_RasterMask
==DEPTH_BIT
414 && ctx
->Depth
.Func
==GL_LESS
415 && ctx
->Depth
.Mask
==GL_TRUE
416 && ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
417 && ctx
->Polygon
.StippleFlag
==GL_FALSE
) {
418 return tri_rgb_smooth_z
;
420 if (ctx
->Light
.ShadeModel
==GL_FLAT
421 && swrast
->_RasterMask
==DEPTH_BIT
422 && ctx
->Depth
.Func
==GL_LESS
423 && ctx
->Depth
.Mask
==GL_TRUE
424 && ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
425 && ctx
->Polygon
.StippleFlag
==GL_FALSE
) {
426 return tri_rgb_flat_z
;
428 if (swrast
->_RasterMask
==0 /* no depth test */
429 && ctx
->Light
.ShadeModel
==GL_SMOOTH
430 && ctx
->Polygon
.StippleFlag
==GL_FALSE
) {
431 return tri_rgb_smooth
;
433 if (swrast
->_RasterMask
==0 /* no depth test */
434 && ctx
->Light
.ShadeModel
==GL_FLAT
435 && ctx
->Polygon
.StippleFlag
==GL_FALSE
) {
439 return (swrast_tri_func
)NULL
;
444 /* Override for the swrast triangle-selection function. Try to use one
445 * of our internal line functions, otherwise fall back to the
446 * standard swrast functions.
448 static void dmesa_choose_tri (GLcontext
*ctx
)
450 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
452 if (!(swrast
->Triangle
=dmesa_choose_tri_function(ctx
)))
453 _swrast_choose_triangle(ctx
);
458 /**********************************************************************/
459 /***** Miscellaneous device driver funcs *****/
460 /**********************************************************************/
464 static void clear_color (GLcontext
*ctx
, const GLchan color
[4])
466 const GLubyte col
[4];
467 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
468 CLAMPED_FLOAT_TO_UBYTE(col
[0], color
[0]);
469 CLAMPED_FLOAT_TO_UBYTE(col
[1], color
[1]);
470 CLAMPED_FLOAT_TO_UBYTE(col
[2], color
[2]);
471 CLAMPED_FLOAT_TO_UBYTE(col
[3], color
[3]);
472 c
->ClearColor
= vl_mixrgba(col
);
477 static void clear (GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
478 GLint x
, GLint y
, GLint width
, GLint height
)
480 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
481 const GLuint
*colorMask
= (GLuint
*)&ctx
->Color
.ColorMask
;
482 DMesaBuffer b
= c
->Buffer
;
485 * Clear the specified region of the buffers indicated by 'mask'
486 * using the clear color or index as specified by one of the two
488 * If all==GL_TRUE, clear whole buffer, else just clear region defined
489 * by x,y,width,height
492 /* we can't handle color or index masking */
493 if (*colorMask
==0xffffffff) {
494 if (mask
& DD_BACK_LEFT_BIT
) {
496 vl_clear(b
->the_window
, b
->bytes
, c
->ClearColor
);
498 vl_rect(b
->the_window
, x
, y
, width
, height
, c
->ClearColor
);
500 mask
&= ~DD_BACK_LEFT_BIT
;
505 _swrast_Clear(ctx
, mask
, all
, x
, y
, width
, height
);
512 * Set the current reading buffer.
514 static void set_read_buffer (GLcontext
*ctx
, GLframebuffer
*buffer
,
518 XXX this has to be fixed
525 * Set the destination/draw buffer.
527 static void set_draw_buffer (GLcontext
*ctx
, GLenum mode
)
530 XXX this has to be fixed
537 * Return the width and height of the current buffer.
538 * If anything special has to been done when the buffer/window is
539 * resized, do it now.
541 static void get_buffer_size (GLframebuffer
*buffer
, GLuint
*width
, GLuint
*height
)
543 DMesaBuffer b
= (DMesaBuffer
)buffer
;
551 static const GLubyte
* get_string (GLcontext
*ctx
, GLenum name
)
555 return (const GLubyte
*)"Mesa DJGPP\0port (c) Borca Daniel 3-sep-2002";
563 /**********************************************************************/
564 /***** Miscellaneous device driver funcs *****/
565 /***** Note that these functions are mandatory *****/
566 /**********************************************************************/
570 /* OPTIONAL FUNCTION: implements glFinish if possible */
571 static void finish (GLcontext
*ctx
)
574 DMesaContext c = (DMesaContext)ctx->DriverCtx;
580 /* OPTIONAL FUNCTION: implements glFlush if possible */
581 static void flush (GLcontext
*ctx
)
584 DMesaContext c = (DMesaContext)ctx->DriverCtx;
590 /**********************************************************************/
591 /**********************************************************************/
595 #define DMESA_NEW_TRIANGLE (_NEW_POLYGON | \
600 _SWRAST_NEW_RASTERMASK)
604 /* Extend the software rasterizer with our line and triangle
607 static void dmesa_register_swrast_functions (GLcontext
*ctx
)
609 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
611 swrast
->choose_triangle
= dmesa_choose_tri
;
613 swrast
->invalidate_triangle
|= DMESA_NEW_TRIANGLE
;
618 /* Setup pointers and other driver state that is constant for the life
621 void dmesa_init_pointers (GLcontext
*ctx
)
625 ctx
->Driver
.UpdateState
= dmesa_update_state
;
627 ctx
->Driver
.GetString
= get_string
;
628 ctx
->Driver
.GetBufferSize
= get_buffer_size
;
629 ctx
->Driver
.Flush
= flush
;
630 ctx
->Driver
.Finish
= finish
;
632 /* Software rasterizer pixel paths:
634 ctx
->Driver
.Accum
= _swrast_Accum
;
635 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
636 ctx
->Driver
.Clear
= clear
;
637 ctx
->Driver
.ResizeBuffers
= _swrast_alloc_buffers
;
638 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
639 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
640 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;
642 /* Software texture functions:
644 ctx
->Driver
.ChooseTextureFormat
= _mesa_choose_tex_format
;
645 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
646 ctx
->Driver
.TexImage2D
= _mesa_store_teximage2d
;
647 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
648 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
649 ctx
->Driver
.TexSubImage2D
= _mesa_store_texsubimage2d
;
650 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
651 ctx
->Driver
.TestProxyTexImage
= _mesa_test_proxy_teximage
;
653 ctx
->Driver
.CompressedTexImage1D
= _mesa_store_compressed_teximage1d
;
654 ctx
->Driver
.CompressedTexImage2D
= _mesa_store_compressed_teximage2d
;
655 ctx
->Driver
.CompressedTexImage3D
= _mesa_store_compressed_teximage3d
;
656 ctx
->Driver
.CompressedTexSubImage1D
= _mesa_store_compressed_texsubimage1d
;
657 ctx
->Driver
.CompressedTexSubImage2D
= _mesa_store_compressed_texsubimage2d
;
658 ctx
->Driver
.CompressedTexSubImage3D
= _mesa_store_compressed_texsubimage3d
;
660 ctx
->Driver
.CopyTexImage1D
= _swrast_copy_teximage1d
;
661 ctx
->Driver
.CopyTexImage2D
= _swrast_copy_teximage2d
;
662 ctx
->Driver
.CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
663 ctx
->Driver
.CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
664 ctx
->Driver
.CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
666 /* Swrast hooks for imaging extensions:
668 ctx
->Driver
.CopyColorTable
= _swrast_CopyColorTable
;
669 ctx
->Driver
.CopyColorSubTable
= _swrast_CopyColorSubTable
;
670 ctx
->Driver
.CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
671 ctx
->Driver
.CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
673 /* Statechange callbacks:
675 ctx
->Driver
.SetDrawBuffer
= set_draw_buffer
;
676 ctx
->Driver
.ClearColor
= clear_color
;
678 /* Initialize the TNL driver interface:
680 tnl
= TNL_CONTEXT(ctx
);
681 tnl
->Driver
.RunPipeline
= _tnl_run_pipeline
;
683 /* Install swsetup for tnl->Driver.Render.*:
685 _swsetup_Wakeup(ctx
);
690 static void dmesa_update_state (GLcontext
*ctx
, GLuint new_state
)
692 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
693 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
695 /* Initialize all the pointers in the DD struct. Do this whenever */
696 /* a new context is made current or we change buffers via set_buffer! */
698 _swrast_InvalidateState(ctx
, new_state
);
699 _swsetup_InvalidateState(ctx
, new_state
);
700 _ac_InvalidateState(ctx
, new_state
);
701 _tnl_InvalidateState(ctx
, new_state
);
703 swdd
->SetReadBuffer
= set_read_buffer
;
705 /* RGB(A) span/pixel functions */
706 swdd
->WriteRGBASpan
= write_rgba_span
;
707 swdd
->WriteRGBSpan
= write_rgb_span
;
708 swdd
->WriteMonoRGBASpan
= write_mono_rgba_span
;
709 swdd
->WriteRGBAPixels
= write_rgba_pixels
;
710 swdd
->WriteMonoRGBAPixels
= write_mono_rgba_pixels
;
711 swdd
->ReadRGBASpan
= read_rgba_span
;
712 swdd
->ReadRGBAPixels
= read_rgba_pixels
;
717 /**********************************************************************/
718 /***** DMesa Public API Functions *****/
719 /**********************************************************************/
724 * The exact arguments to this function will depend on your window system
726 DMesaVisual
DMesaCreateVisual (GLint width
, GLint height
, GLint colDepth
,
727 GLboolean dbFlag
, GLint depthSize
,
732 GLint redBits
, greenBits
, blueBits
, alphaBits
;
735 char *var
= getenv("DMESA_REFRESH");
736 if ((var
== NULL
) || ((refresh
=atoi(var
)) == 0)) {
766 if (vl_video_init(width
, height
, colDepth
, refresh
) != 0) {
770 if ((v
=(DMesaVisual
)calloc(1, sizeof(struct dmesa_visual
)))!=NULL
) {
771 /* Create core visual */
772 v
->gl_visual
= _mesa_create_visual(colDepth
>8, /* rgb */
774 GL_FALSE
, /* stereo */
782 accumSize
, /* accumRed */
783 accumSize
, /* accumGreen */
784 accumSize
, /* accumBlue */
785 alphaBits
?accumSize
:0, /* accumAlpha */
797 void DMesaDestroyVisual (DMesaVisual v
)
800 _mesa_destroy_visual(v
->gl_visual
);
806 DMesaBuffer
DMesaCreateBuffer (DMesaVisual visual
,
807 GLint xpos
, GLint ypos
,
808 GLint width
, GLint height
)
812 if ((b
=(DMesaBuffer
)calloc(1, sizeof(struct dmesa_buffer
)))!=NULL
) {
814 _mesa_initialize_framebuffer(&b
->gl_buffer
,
816 visual
->gl_visual
->depthBits
> 0,
817 visual
->gl_visual
->stencilBits
> 0,
818 visual
->gl_visual
->accumRedBits
> 0,
819 visual
->gl_visual
->alphaBits
> 0);
824 b
->bypp
= (visual
->depth
+7)/8;
832 void DMesaDestroyBuffer (DMesaBuffer b
)
835 _mesa_free_framebuffer_data(&b
->gl_buffer
);
841 DMesaContext
DMesaCreateContext (DMesaVisual visual
,
845 GLboolean direct
= GL_FALSE
;
847 if ((c
=(DMesaContext
)calloc(1, sizeof(struct dmesa_context
)))!=NULL
) {
848 c
->gl_ctx
= _mesa_create_context(visual
->gl_visual
,
849 share
? share
->gl_ctx
: NULL
,
852 _mesa_enable_sw_extensions(c
->gl_ctx
);
853 _mesa_enable_1_3_extensions(c
->gl_ctx
);
855 /* you probably have to do a bunch of other initializations here. */
858 /* Initialize the software rasterizer and helper modules.
860 _swrast_CreateContext(c
->gl_ctx
);
861 _ac_CreateContext(c
->gl_ctx
);
862 _tnl_CreateContext(c
->gl_ctx
);
863 _swsetup_CreateContext(c
->gl_ctx
);
864 dmesa_init_pointers(c
->gl_ctx
);
865 dmesa_register_swrast_functions(c
->gl_ctx
);
873 void DMesaDestroyContext (DMesaContext c
)
875 _mesa_destroy_context(c
->gl_ctx
);
881 GLboolean
DMesaViewport (DMesaBuffer b
,
882 GLint xpos
, GLint ypos
,
883 GLint width
, GLint height
)
887 if ((new_window
=vl_sync_buffer(b
->the_window
, xpos
, ypos
, width
, height
))==NULL
) {
890 b
->the_window
= new_window
;
895 b
->stride
= width
* b
->bypp
;
896 b
->bytes
= b
->stride
* height
;
904 * Make the specified context and buffer the current one.
906 GLboolean
DMesaMakeCurrent (DMesaContext c
, DMesaBuffer b
)
909 if (!DMesaViewport(b
, b
->xpos
, b
->ypos
, b
->width
, b
->height
)) {
915 dmesa_update_state(c
->gl_ctx
, 0);
916 _mesa_make_current(c
->gl_ctx
, &b
->gl_buffer
);
917 if (c
->gl_ctx
->Viewport
.Width
==0) {
918 /* initialize viewport to window size */
919 _mesa_Viewport(0, 0, b
->width
, b
->height
);
923 _mesa_make_current(NULL
, NULL
);
931 void DMesaSwapBuffers (DMesaBuffer b
)
933 /* copy/swap back buffer to front if applicable */
934 GET_CURRENT_CONTEXT(ctx
);
935 _mesa_notifySwapBuffers(ctx
);
936 vl_flip(b
->the_window
, b
->stride
, b
->height
);