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
40 #include "extensions.h"
44 #include "texformat.h"
46 #include "array_cache/acache.h"
47 #include "swrast/s_context.h"
48 #include "swrast/s_depth.h"
49 #include "swrast/s_lines.h"
50 #include "swrast/s_triangle.h"
51 #include "swrast/s_trispan.h"
52 #include "swrast/swrast.h"
53 #include "swrast_setup/swrast_setup.h"
55 #include "tnl/t_context.h"
56 #include "tnl/t_pipeline.h"
64 * In C++ terms, this class derives from the GLvisual class.
65 * Add system-specific fields to it.
69 GLboolean db_flag
; /* double buffered? */
70 GLboolean rgb_flag
; /* RGB mode? */
71 GLuint depth
; /* bits per pixel (1, 8, 24, etc) */
75 * In C++ terms, this class derives from the GLframebuffer class.
76 * Add system-specific fields to it.
79 GLframebuffer gl_buffer
; /* The depth, stencil, accum, etc buffers */
80 void *the_window
; /* your window handle, etc */
82 int xpos
, ypos
; /* position */
83 int width
, height
; /* size in pixels */
84 int bypp
, stride
, bytes
; /* bytes per pixel, in a line, then total */
88 * In C++ terms, this class derives from the GLcontext class.
89 * Add system-specific fields to it.
91 struct dmesa_context
{
92 GLcontext
*gl_ctx
; /* the core library context */
101 static void dmesa_update_state (GLcontext
*ctx
, GLuint new_state
);
105 /**********************************************************************/
106 /***** Read/Write pixels *****/
107 /**********************************************************************/
111 #define FLIP(y) (c->Buffer->height - (y) - 1)
112 #define FLIP2(y) (h - (y) - 1)
116 static void write_rgba_span (const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
117 const GLubyte rgba
[][4], const GLubyte mask
[])
119 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
120 void *b
= c
->Buffer
->the_window
;
123 offset
= c
->Buffer
->width
* FLIP(y
) + x
;
125 /* draw some pixels */
126 for (i
=0; i
<n
; i
++, offset
++) {
128 vl_putpixel(b
, offset
, vl_mixrgba(rgba
[i
]));
132 /* draw all pixels */
133 for (i
=0; i
<n
; i
++, offset
++) {
134 vl_putpixel(b
, offset
, vl_mixrgba(rgba
[i
]));
139 static void write_rgb_span (const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
140 const GLubyte rgb
[][3], const GLubyte mask
[])
142 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
143 void *b
= c
->Buffer
->the_window
;
146 offset
= c
->Buffer
->width
* FLIP(y
) + x
;
148 /* draw some pixels */
149 for (i
=0; i
<n
; i
++, offset
++) {
151 vl_putpixel(b
, offset
, vl_mixrgb(rgb
[i
]));
155 /* draw all pixels */
156 for (i
=0; i
<n
; i
++, offset
++) {
157 vl_putpixel(b
, offset
, vl_mixrgb(rgb
[i
]));
162 static void write_mono_rgba_span (const GLcontext
*ctx
,
163 GLuint n
, GLint x
, GLint y
,
164 const GLchan color
[4], const GLubyte mask
[])
166 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
167 void *b
= c
->Buffer
->the_window
;
168 GLuint i
, offset
, rgba
= vl_mixrgba(color
);
170 offset
= c
->Buffer
->width
* FLIP(y
) + x
;
172 /* draw some pixels */
173 for (i
=0; i
<n
; i
++, offset
++) {
175 vl_putpixel(b
, offset
, rgba
);
179 /* draw all pixels */
180 for (i
=0; i
<n
; i
++, offset
++) {
181 vl_putpixel(b
, offset
, rgba
);
186 static void read_rgba_span (const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
189 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
190 void *b
= c
->Buffer
->the_window
;
193 offset
= c
->Buffer
->width
* FLIP(y
) + x
;
194 /* read all pixels */
195 for (i
=0; i
<n
; i
++, offset
++) {
196 vl_getrgba(b
, offset
, rgba
[i
]);
200 static void write_rgba_pixels (const GLcontext
*ctx
,
201 GLuint n
, const GLint x
[], const GLint y
[],
202 const GLubyte rgba
[][4], const GLubyte mask
[])
204 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
205 void *b
= c
->Buffer
->the_window
;
206 GLuint i
, w
= c
->Buffer
->width
, h
= c
->Buffer
->height
;
209 /* draw some pixels */
210 for (i
=0; i
<n
; i
++) {
212 vl_putpixel(b
, FLIP2(y
[i
])*w
+ x
[i
], vl_mixrgba(rgba
[i
]));
216 /* draw all pixels */
217 for (i
=0; i
<n
; i
++) {
218 vl_putpixel(b
, FLIP2(y
[i
])*w
+ x
[i
], vl_mixrgba(rgba
[i
]));
223 static void write_mono_rgba_pixels (const GLcontext
*ctx
,
224 GLuint n
, const GLint x
[], const GLint y
[],
225 const GLchan color
[4], const GLubyte mask
[])
227 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
228 void *b
= c
->Buffer
->the_window
;
229 GLuint i
, w
= c
->Buffer
->width
, h
= c
->Buffer
->height
, rgba
= vl_mixrgba(color
);
232 /* draw some pixels */
233 for (i
=0; i
<n
; i
++) {
235 vl_putpixel(b
, FLIP2(y
[i
])*w
+ x
[i
], rgba
);
239 /* draw all pixels */
240 for (i
=0; i
<n
; i
++) {
241 vl_putpixel(b
, FLIP2(y
[i
])*w
+ x
[i
], rgba
);
246 static void read_rgba_pixels (const GLcontext
*ctx
,
247 GLuint n
, const GLint x
[], const GLint y
[],
248 GLubyte rgba
[][4], const GLubyte mask
[])
250 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
251 void *b
= c
->Buffer
->the_window
;
252 GLuint i
, w
= c
->Buffer
->width
, h
= c
->Buffer
->height
;
255 /* read some pixels */
256 for (i
=0; i
<n
; i
++) {
258 vl_getrgba(b
, FLIP2(y
[i
])*w
+ x
[i
], rgba
[i
]);
262 /* read all pixels */
263 for (i
=0; i
<n
; i
++) {
264 vl_getrgba(b
, FLIP2(y
[i
])*w
+ x
[i
], rgba
[i
]);
271 /**********************************************************************/
272 /***** Optimized triangle rendering *****/
273 /**********************************************************************/
278 * flat, NON-depth-buffered, triangle.
280 static void tri_rgb_flat (GLcontext
*ctx
,
285 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
286 void *b
= c
->Buffer
->the_window
;
287 GLuint w
= c
->Buffer
->width
, h
= c
->Buffer
->height
;
289 #define SETUP_CODE GLuint rgb = vl_mixrgb(v2->color);
291 #define RENDER_SPAN(span) \
292 GLuint i, offset = FLIP2(span.y)*w + span.x; \
293 for (i = 0; i < span.count; i++, offset++) { \
294 vl_putpixel(b, offset, rgb); \
297 #include "swrast/s_tritemp.h"
303 * flat, depth-buffered, triangle.
305 static void tri_rgb_flat_z (GLcontext
*ctx
,
310 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
311 void *b
= c
->Buffer
->the_window
;
312 GLuint w
= c
->Buffer
->width
, h
= c
->Buffer
->height
;
315 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
316 #define SETUP_CODE GLuint rgb = vl_mixrgb(v2->color);
318 #define RENDER_SPAN(span) \
319 GLuint i, offset = FLIP2(span.y)*w + span.x; \
320 for (i = 0; i < span.count; i++, offset++) { \
321 const DEPTH_TYPE z = FixedToDepth(span.z); \
323 vl_putpixel(b, offset, rgb); \
326 span.z += span.zStep; \
329 #include "swrast/s_tritemp.h"
335 * smooth, NON-depth-buffered, triangle.
337 static void tri_rgb_smooth (GLcontext
*ctx
,
342 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
343 void *b
= c
->Buffer
->the_window
;
344 GLuint w
= c
->Buffer
->width
, h
= c
->Buffer
->height
;
347 #define RENDER_SPAN(span) \
348 GLuint i, offset = FLIP2(span.y)*w + span.x; \
349 for (i = 0; i < span.count; i++, offset++) { \
350 unsigned char rgb[3]; \
351 rgb[0] = FixedToInt(span.red); \
352 rgb[1] = FixedToInt(span.green); \
353 rgb[2] = FixedToInt(span.blue); \
354 vl_putpixel(b, offset, vl_mixrgb(rgb)); \
355 span.red += span.redStep; \
356 span.green += span.greenStep; \
357 span.blue += span.blueStep; \
360 #include "swrast/s_tritemp.h"
366 * smooth, depth-buffered, triangle.
368 static void tri_rgb_smooth_z (GLcontext
*ctx
,
373 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
374 void *b
= c
->Buffer
->the_window
;
375 GLuint w
= c
->Buffer
->width
, h
= c
->Buffer
->height
;
378 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
381 #define RENDER_SPAN(span) \
382 GLuint i, offset = FLIP2(span.y)*w + span.x; \
383 for (i = 0; i < span.count; i++, offset++) { \
384 const DEPTH_TYPE z = FixedToDepth(span.z); \
386 unsigned char rgb[3]; \
387 rgb[0] = FixedToInt(span.red); \
388 rgb[1] = FixedToInt(span.green); \
389 rgb[2] = FixedToInt(span.blue); \
390 vl_putpixel(b, offset, vl_mixrgb(rgb)); \
393 span.red += span.redStep; \
394 span.green += span.greenStep; \
395 span.blue += span.blueStep; \
396 span.z += span.zStep; \
399 #include "swrast/s_tritemp.h"
405 * Analyze context state to see if we can provide a fast triangle function
406 * Otherwise, return NULL.
408 static swrast_tri_func
dmesa_choose_tri_function (GLcontext
*ctx
)
410 const SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
412 if (ctx
->RenderMode
!= GL_RENDER
) return (swrast_tri_func
) NULL
;
413 if (ctx
->Polygon
.SmoothFlag
) return (swrast_tri_func
) NULL
;
414 if (ctx
->Texture
._EnabledUnits
) return (swrast_tri_func
) NULL
;
416 if (ctx
->Light
.ShadeModel
==GL_SMOOTH
417 && swrast
->_RasterMask
==DEPTH_BIT
418 && ctx
->Depth
.Func
==GL_LESS
419 && ctx
->Depth
.Mask
==GL_TRUE
420 && ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
421 && ctx
->Polygon
.StippleFlag
==GL_FALSE
) {
422 return tri_rgb_smooth_z
;
424 if (ctx
->Light
.ShadeModel
==GL_FLAT
425 && swrast
->_RasterMask
==DEPTH_BIT
426 && ctx
->Depth
.Func
==GL_LESS
427 && ctx
->Depth
.Mask
==GL_TRUE
428 && ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
429 && ctx
->Polygon
.StippleFlag
==GL_FALSE
) {
430 return tri_rgb_flat_z
;
432 if (swrast
->_RasterMask
==0 /* no depth test */
433 && ctx
->Light
.ShadeModel
==GL_SMOOTH
434 && ctx
->Polygon
.StippleFlag
==GL_FALSE
) {
435 return tri_rgb_smooth
;
437 if (swrast
->_RasterMask
==0 /* no depth test */
438 && ctx
->Light
.ShadeModel
==GL_FLAT
439 && ctx
->Polygon
.StippleFlag
==GL_FALSE
) {
443 return (swrast_tri_func
)NULL
;
448 /* Override for the swrast triangle-selection function. Try to use one
449 * of our internal line functions, otherwise fall back to the
450 * standard swrast functions.
452 static void dmesa_choose_tri (GLcontext
*ctx
)
454 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
456 if (!(swrast
->Triangle
=dmesa_choose_tri_function(ctx
)))
457 _swrast_choose_triangle(ctx
);
462 /**********************************************************************/
463 /***** Miscellaneous device driver funcs *****/
464 /**********************************************************************/
468 static void clear_color (GLcontext
*ctx
, const GLchan color
[4])
470 const GLubyte col
[4];
471 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
472 CLAMPED_FLOAT_TO_UBYTE(col
[0], color
[0]);
473 CLAMPED_FLOAT_TO_UBYTE(col
[1], color
[1]);
474 CLAMPED_FLOAT_TO_UBYTE(col
[2], color
[2]);
475 CLAMPED_FLOAT_TO_UBYTE(col
[3], color
[3]);
476 c
->ClearColor
= vl_mixrgba(col
);
481 static void clear (GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
482 GLint x
, GLint y
, GLint width
, GLint height
)
484 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
485 const GLuint
*colorMask
= (GLuint
*)&ctx
->Color
.ColorMask
;
486 DMesaBuffer b
= c
->Buffer
;
489 * Clear the specified region of the buffers indicated by 'mask'
490 * using the clear color or index as specified by one of the two
492 * If all==GL_TRUE, clear whole buffer, else just clear region defined
493 * by x,y,width,height
496 /* we can't handle color or index masking */
497 if (*colorMask
==0xffffffff) {
498 if (mask
& DD_BACK_LEFT_BIT
) {
500 vl_clear(b
->the_window
, b
->bytes
, c
->ClearColor
);
502 vl_rect(b
->the_window
, x
, y
, width
, height
, c
->ClearColor
);
504 mask
&= ~DD_BACK_LEFT_BIT
;
509 _swrast_Clear(ctx
, mask
, all
, x
, y
, width
, height
);
516 * Set the current reading buffer.
518 static void set_read_buffer (GLcontext
*ctx
, GLframebuffer
*buffer
,
522 XXX this has to be fixed
529 * Set the destination/draw buffer.
531 static void set_draw_buffer (GLcontext
*ctx
, GLenum mode
)
534 XXX this has to be fixed
541 * Return the width and height of the current buffer.
542 * If anything special has to been done when the buffer/window is
543 * resized, do it now.
545 static void get_buffer_size (GLframebuffer
*buffer
, GLuint
*width
, GLuint
*height
)
547 DMesaBuffer b
= (DMesaBuffer
)buffer
;
555 static const GLubyte
* get_string (GLcontext
*ctx
, GLenum name
)
559 return (const GLubyte
*)"Mesa DJGPP\0port (c) Borca Daniel 3-sep-2002";
567 /**********************************************************************/
568 /***** Miscellaneous device driver funcs *****/
569 /***** Note that these functions are mandatory *****/
570 /**********************************************************************/
574 /* OPTIONAL FUNCTION: implements glFinish if possible */
575 static void finish (GLcontext
*ctx
)
578 DMesaContext c = (DMesaContext)ctx->DriverCtx;
584 /* OPTIONAL FUNCTION: implements glFlush if possible */
585 static void flush (GLcontext
*ctx
)
588 DMesaContext c = (DMesaContext)ctx->DriverCtx;
594 /**********************************************************************/
595 /**********************************************************************/
599 #define DMESA_NEW_TRIANGLE (_NEW_POLYGON | \
604 _SWRAST_NEW_RASTERMASK)
608 /* Extend the software rasterizer with our line and triangle
611 static void dmesa_register_swrast_functions (GLcontext
*ctx
)
613 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
615 swrast
->choose_triangle
= dmesa_choose_tri
;
617 swrast
->invalidate_triangle
|= DMESA_NEW_TRIANGLE
;
622 /* Setup pointers and other driver state that is constant for the life
625 void dmesa_init_pointers (GLcontext
*ctx
)
629 ctx
->Driver
.UpdateState
= dmesa_update_state
;
631 ctx
->Driver
.GetString
= get_string
;
632 ctx
->Driver
.GetBufferSize
= get_buffer_size
;
633 ctx
->Driver
.Flush
= flush
;
634 ctx
->Driver
.Finish
= finish
;
636 /* Software rasterizer pixel paths:
638 ctx
->Driver
.Accum
= _swrast_Accum
;
639 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
640 ctx
->Driver
.Clear
= clear
;
641 ctx
->Driver
.ResizeBuffers
= _swrast_alloc_buffers
;
642 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
643 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
644 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;
646 /* Software texture functions:
648 ctx
->Driver
.ChooseTextureFormat
= _mesa_choose_tex_format
;
649 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
650 ctx
->Driver
.TexImage2D
= _mesa_store_teximage2d
;
651 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
652 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
653 ctx
->Driver
.TexSubImage2D
= _mesa_store_texsubimage2d
;
654 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
655 ctx
->Driver
.TestProxyTexImage
= _mesa_test_proxy_teximage
;
657 ctx
->Driver
.CompressedTexImage1D
= _mesa_store_compressed_teximage1d
;
658 ctx
->Driver
.CompressedTexImage2D
= _mesa_store_compressed_teximage2d
;
659 ctx
->Driver
.CompressedTexImage3D
= _mesa_store_compressed_teximage3d
;
660 ctx
->Driver
.CompressedTexSubImage1D
= _mesa_store_compressed_texsubimage1d
;
661 ctx
->Driver
.CompressedTexSubImage2D
= _mesa_store_compressed_texsubimage2d
;
662 ctx
->Driver
.CompressedTexSubImage3D
= _mesa_store_compressed_texsubimage3d
;
664 ctx
->Driver
.CopyTexImage1D
= _swrast_copy_teximage1d
;
665 ctx
->Driver
.CopyTexImage2D
= _swrast_copy_teximage2d
;
666 ctx
->Driver
.CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
667 ctx
->Driver
.CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
668 ctx
->Driver
.CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
670 /* Swrast hooks for imaging extensions:
672 ctx
->Driver
.CopyColorTable
= _swrast_CopyColorTable
;
673 ctx
->Driver
.CopyColorSubTable
= _swrast_CopyColorSubTable
;
674 ctx
->Driver
.CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
675 ctx
->Driver
.CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
677 /* Statechange callbacks:
679 ctx
->Driver
.SetDrawBuffer
= set_draw_buffer
;
680 ctx
->Driver
.ClearColor
= clear_color
;
682 /* Initialize the TNL driver interface:
684 tnl
= TNL_CONTEXT(ctx
);
685 tnl
->Driver
.RunPipeline
= _tnl_run_pipeline
;
687 /* Install swsetup for tnl->Driver.Render.*:
689 _swsetup_Wakeup(ctx
);
694 static void dmesa_update_state (GLcontext
*ctx
, GLuint new_state
)
696 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
697 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
699 /* Initialize all the pointers in the DD struct. Do this whenever */
700 /* a new context is made current or we change buffers via set_buffer! */
702 _swrast_InvalidateState(ctx
, new_state
);
703 _swsetup_InvalidateState(ctx
, new_state
);
704 _ac_InvalidateState(ctx
, new_state
);
705 _tnl_InvalidateState(ctx
, new_state
);
707 swdd
->SetReadBuffer
= set_read_buffer
;
709 /* RGB(A) span/pixel functions */
710 swdd
->WriteRGBASpan
= write_rgba_span
;
711 swdd
->WriteRGBSpan
= write_rgb_span
;
712 swdd
->WriteMonoRGBASpan
= write_mono_rgba_span
;
713 swdd
->WriteRGBAPixels
= write_rgba_pixels
;
714 swdd
->WriteMonoRGBAPixels
= write_mono_rgba_pixels
;
715 swdd
->ReadRGBASpan
= read_rgba_span
;
716 swdd
->ReadRGBAPixels
= read_rgba_pixels
;
721 /**********************************************************************/
722 /***** DMesa Public API Functions *****/
723 /**********************************************************************/
728 * The exact arguments to this function will depend on your window system
730 DMesaVisual
DMesaCreateVisual (GLint width
, GLint height
, GLint colDepth
,
731 GLboolean dbFlag
, GLint depthSize
,
736 GLint redBits
, greenBits
, blueBits
, alphaBits
;
739 char *var
= getenv("DMESA_REFRESH");
740 if ((var
== NULL
) || ((refresh
=atoi(var
)) == 0)) {
770 if (vl_video_init(width
, height
, colDepth
, refresh
) != 0) {
774 if ((v
=(DMesaVisual
)calloc(1, sizeof(struct dmesa_visual
)))!=NULL
) {
775 /* Create core visual */
776 v
->gl_visual
= _mesa_create_visual(colDepth
>8, /* rgb */
778 GL_FALSE
, /* stereo */
786 accumSize
, /* accumRed */
787 accumSize
, /* accumGreen */
788 accumSize
, /* accumBlue */
789 alphaBits
?accumSize
:0, /* accumAlpha */
801 void DMesaDestroyVisual (DMesaVisual v
)
804 _mesa_destroy_visual(v
->gl_visual
);
810 DMesaBuffer
DMesaCreateBuffer (DMesaVisual visual
,
811 GLint xpos
, GLint ypos
,
812 GLint width
, GLint height
)
816 if ((b
=(DMesaBuffer
)calloc(1, sizeof(struct dmesa_buffer
)))!=NULL
) {
818 _mesa_initialize_framebuffer(&b
->gl_buffer
,
820 visual
->gl_visual
->depthBits
> 0,
821 visual
->gl_visual
->stencilBits
> 0,
822 visual
->gl_visual
->accumRedBits
> 0,
823 visual
->gl_visual
->alphaBits
> 0);
828 b
->bypp
= (visual
->depth
+7)/8;
836 void DMesaDestroyBuffer (DMesaBuffer b
)
839 _mesa_free_framebuffer_data(&b
->gl_buffer
);
845 DMesaContext
DMesaCreateContext (DMesaVisual visual
,
849 GLboolean direct
= GL_FALSE
;
851 if ((c
=(DMesaContext
)calloc(1, sizeof(struct dmesa_context
)))!=NULL
) {
852 c
->gl_ctx
= _mesa_create_context(visual
->gl_visual
,
853 share
? share
->gl_ctx
: NULL
,
856 _mesa_enable_sw_extensions(c
->gl_ctx
);
857 _mesa_enable_1_3_extensions(c
->gl_ctx
);
859 /* you probably have to do a bunch of other initializations here. */
862 /* Initialize the software rasterizer and helper modules.
864 _swrast_CreateContext(c
->gl_ctx
);
865 _ac_CreateContext(c
->gl_ctx
);
866 _tnl_CreateContext(c
->gl_ctx
);
867 _swsetup_CreateContext(c
->gl_ctx
);
868 dmesa_init_pointers(c
->gl_ctx
);
869 dmesa_register_swrast_functions(c
->gl_ctx
);
877 void DMesaDestroyContext (DMesaContext c
)
879 _mesa_destroy_context(c
->gl_ctx
);
885 GLboolean
DMesaViewport (DMesaBuffer b
,
886 GLint xpos
, GLint ypos
,
887 GLint width
, GLint height
)
891 if ((new_window
=vl_sync_buffer(b
->the_window
, xpos
, ypos
, width
, height
))==NULL
) {
894 b
->the_window
= new_window
;
899 b
->stride
= width
* b
->bypp
;
900 b
->bytes
= b
->stride
* height
;
908 * Make the specified context and buffer the current one.
910 GLboolean
DMesaMakeCurrent (DMesaContext c
, DMesaBuffer b
)
913 if (!DMesaViewport(b
, b
->xpos
, b
->ypos
, b
->width
, b
->height
)) {
919 dmesa_update_state(c
->gl_ctx
, 0);
920 _mesa_make_current(c
->gl_ctx
, &b
->gl_buffer
);
921 if (c
->gl_ctx
->Viewport
.Width
==0) {
922 /* initialize viewport to window size */
923 _mesa_Viewport(0, 0, b
->width
, b
->height
);
927 _mesa_make_current(NULL
, NULL
);
935 void DMesaSwapBuffers (DMesaBuffer b
)
937 /* copy/swap back buffer to front if applicable */
938 GET_CURRENT_CONTEXT(ctx
);
939 _mesa_swapbuffers(ctx
);
940 vl_flip(b
->the_window
, b
->stride
, b
->height
);