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 v0.2 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 rgb_flag
; /* RGB mode? */
70 GLuint depth
; /* bits per pixel (1, 8, 24, etc) */
72 GLint caps
; /* video mode capabilities */
76 * In C++ terms, this class derives from the GLframebuffer class.
77 * Add system-specific fields to it.
80 GLframebuffer
*gl_buffer
; /* The depth, stencil, accum, etc buffers */
81 void *the_window
; /* your window handle, etc */
83 int xpos
, ypos
; /* position */
84 int width
, height
; /* size in pixels */
85 int pitch
, len
; /* number of bytes in a line, then total */
86 int cwidth
; /* scan width */
88 int caps
; /* video mode capabilities */
90 void (*tri_rgb_flat
) ();
94 * In C++ terms, this class derives from the GLcontext class.
95 * Add system-specific fields to it.
97 struct dmesa_context
{
98 GLcontext
*gl_ctx
; /* the core library context */
107 static void dmesa_update_state (GLcontext
*ctx
, GLuint new_state
);
111 /**********************************************************************/
112 /***** Read/Write pixels *****/
113 /**********************************************************************/
117 #define FLIP(y) (c->Buffer->height - (y) - 1)
118 #define FLIP2(y) (h - (y) - 1)
122 static void write_rgba_span (const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
123 const GLubyte rgba
[][4], const GLubyte mask
[])
125 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
126 void *b
= c
->Buffer
->the_window
;
129 offset
= c
->Buffer
->cwidth
* FLIP(y
) + x
;
131 /* draw some pixels */
132 for (i
=0; i
<n
; i
++, offset
++) {
134 vl_putpixel(b
, offset
, vl_mixrgba(rgba
[i
]));
138 /* draw all pixels */
139 for (i
=0; i
<n
; i
++, offset
++) {
140 vl_putpixel(b
, offset
, vl_mixrgba(rgba
[i
]));
145 static void write_rgb_span (const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
146 const GLubyte rgb
[][3], const GLubyte mask
[])
148 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
149 void *b
= c
->Buffer
->the_window
;
152 offset
= c
->Buffer
->cwidth
* FLIP(y
) + x
;
154 /* draw some pixels */
155 for (i
=0; i
<n
; i
++, offset
++) {
157 vl_putpixel(b
, offset
, vl_mixrgb(rgb
[i
]));
161 /* draw all pixels */
162 for (i
=0; i
<n
; i
++, offset
++) {
163 vl_putpixel(b
, offset
, vl_mixrgb(rgb
[i
]));
168 static void write_mono_rgba_span (const GLcontext
*ctx
,
169 GLuint n
, GLint x
, GLint y
,
170 const GLchan color
[4], const GLubyte mask
[])
172 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
173 void *b
= c
->Buffer
->the_window
;
174 GLuint i
, offset
, rgba
= vl_mixrgba(color
);
176 offset
= c
->Buffer
->cwidth
* FLIP(y
) + x
;
178 /* draw some pixels */
179 for (i
=0; i
<n
; i
++, offset
++) {
181 vl_putpixel(b
, offset
, rgba
);
185 /* draw all pixels */
186 for (i
=0; i
<n
; i
++, offset
++) {
187 vl_putpixel(b
, offset
, rgba
);
192 static void read_rgba_span (const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
195 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
196 void *b
= c
->Buffer
->the_window
;
199 offset
= c
->Buffer
->cwidth
* FLIP(y
) + x
;
200 /* read all pixels */
201 for (i
=0; i
<n
; i
++, offset
++) {
202 vl_getrgba(b
, offset
, rgba
[i
]);
206 static void write_rgba_pixels (const GLcontext
*ctx
,
207 GLuint n
, const GLint x
[], const GLint y
[],
208 const GLubyte rgba
[][4], const GLubyte mask
[])
210 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
211 void *b
= c
->Buffer
->the_window
;
212 GLuint i
, w
= c
->Buffer
->cwidth
, h
= c
->Buffer
->height
;
215 /* draw some pixels */
216 for (i
=0; i
<n
; i
++) {
218 vl_putpixel(b
, FLIP2(y
[i
])*w
+ x
[i
], vl_mixrgba(rgba
[i
]));
222 /* draw all pixels */
223 for (i
=0; i
<n
; i
++) {
224 vl_putpixel(b
, FLIP2(y
[i
])*w
+ x
[i
], vl_mixrgba(rgba
[i
]));
229 static void write_mono_rgba_pixels (const GLcontext
*ctx
,
230 GLuint n
, const GLint x
[], const GLint y
[],
231 const GLchan color
[4], const GLubyte mask
[])
233 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
234 void *b
= c
->Buffer
->the_window
;
235 GLuint i
, w
= c
->Buffer
->cwidth
, h
= c
->Buffer
->height
, rgba
= vl_mixrgba(color
);
238 /* draw some pixels */
239 for (i
=0; i
<n
; i
++) {
241 vl_putpixel(b
, FLIP2(y
[i
])*w
+ x
[i
], rgba
);
245 /* draw all pixels */
246 for (i
=0; i
<n
; i
++) {
247 vl_putpixel(b
, FLIP2(y
[i
])*w
+ x
[i
], rgba
);
252 static void read_rgba_pixels (const GLcontext
*ctx
,
253 GLuint n
, const GLint x
[], const GLint y
[],
254 GLubyte rgba
[][4], const GLubyte mask
[])
256 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
257 void *b
= c
->Buffer
->the_window
;
258 GLuint i
, w
= c
->Buffer
->cwidth
, h
= c
->Buffer
->height
;
261 /* read some pixels */
262 for (i
=0; i
<n
; i
++) {
264 vl_getrgba(b
, FLIP2(y
[i
])*w
+ x
[i
], rgba
[i
]);
268 /* read all pixels */
269 for (i
=0; i
<n
; i
++) {
270 vl_getrgba(b
, FLIP2(y
[i
])*w
+ x
[i
], rgba
[i
]);
277 /**********************************************************************/
278 /***** Optimized triangle rendering *****/
279 /**********************************************************************/
284 * flat, NON-depth-buffered, triangle.
286 static void tri_rgb_flat (GLcontext
*ctx
,
291 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
292 void *b
= c
->Buffer
->the_window
;
293 GLuint w
= c
->Buffer
->cwidth
, h
= c
->Buffer
->height
;
295 if (c
->Buffer
->tri_rgb_flat
) {
296 c
->Buffer
->tri_rgb_flat(IROUND(v0
->win
[0]), IROUND(FLIP2(v0
->win
[1])),
297 IROUND(v1
->win
[0]), IROUND(FLIP2(v1
->win
[1])),
298 IROUND(v2
->win
[0]), IROUND(FLIP2(v2
->win
[1])),
299 vl_mixrgb(v2
->color
));
301 #define SETUP_CODE GLuint rgb = vl_mixrgb(v2->color);
303 #define RENDER_SPAN(span) \
304 GLuint i, offset = FLIP2(span.y)*w + span.x; \
305 for (i = 0; i < span.count; i++, offset++) { \
306 vl_putpixel(b, offset, rgb); \
309 #include "swrast/s_tritemp.h"
316 * flat, depth-buffered, triangle.
318 static void tri_rgb_flat_z (GLcontext
*ctx
,
323 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
324 void *b
= c
->Buffer
->the_window
;
325 GLuint w
= c
->Buffer
->cwidth
, h
= c
->Buffer
->height
;
328 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
329 #define SETUP_CODE GLuint rgb = vl_mixrgb(v2->color);
331 #define RENDER_SPAN(span) \
332 GLuint i, offset = FLIP2(span.y)*w + span.x; \
333 for (i = 0; i < span.count; i++, offset++) { \
334 const DEPTH_TYPE z = FixedToDepth(span.z); \
336 vl_putpixel(b, offset, rgb); \
339 span.z += span.zStep; \
342 #include "swrast/s_tritemp.h"
348 * smooth, NON-depth-buffered, triangle.
350 static void tri_rgb_smooth (GLcontext
*ctx
,
355 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
356 void *b
= c
->Buffer
->the_window
;
357 GLuint w
= c
->Buffer
->cwidth
, h
= c
->Buffer
->height
;
360 #define RENDER_SPAN(span) \
361 GLuint i, offset = FLIP2(span.y)*w + span.x; \
362 for (i = 0; i < span.count; i++, offset++) { \
363 unsigned char rgb[3]; \
364 rgb[0] = FixedToInt(span.red); \
365 rgb[1] = FixedToInt(span.green); \
366 rgb[2] = FixedToInt(span.blue); \
367 vl_putpixel(b, offset, vl_mixrgb(rgb)); \
368 span.red += span.redStep; \
369 span.green += span.greenStep; \
370 span.blue += span.blueStep; \
373 #include "swrast/s_tritemp.h"
379 * smooth, depth-buffered, triangle.
381 static void tri_rgb_smooth_z (GLcontext
*ctx
,
386 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
387 void *b
= c
->Buffer
->the_window
;
388 GLuint w
= c
->Buffer
->cwidth
, h
= c
->Buffer
->height
;
391 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
394 #define RENDER_SPAN(span) \
395 GLuint i, offset = FLIP2(span.y)*w + span.x; \
396 for (i = 0; i < span.count; i++, offset++) { \
397 const DEPTH_TYPE z = FixedToDepth(span.z); \
399 unsigned char rgb[3]; \
400 rgb[0] = FixedToInt(span.red); \
401 rgb[1] = FixedToInt(span.green); \
402 rgb[2] = FixedToInt(span.blue); \
403 vl_putpixel(b, offset, vl_mixrgb(rgb)); \
406 span.red += span.redStep; \
407 span.green += span.greenStep; \
408 span.blue += span.blueStep; \
409 span.z += span.zStep; \
412 #include "swrast/s_tritemp.h"
418 * Analyze context state to see if we can provide a fast triangle function
419 * Otherwise, return NULL.
421 static swrast_tri_func
dmesa_choose_tri_function (GLcontext
*ctx
)
423 const SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
425 if (ctx
->RenderMode
!= GL_RENDER
) return (swrast_tri_func
) NULL
;
426 if (ctx
->Polygon
.SmoothFlag
) return (swrast_tri_func
) NULL
;
427 if (ctx
->Texture
._ReallyEnabled
) return (swrast_tri_func
) NULL
;
429 if (ctx
->Light
.ShadeModel
==GL_SMOOTH
430 && swrast
->_RasterMask
==DEPTH_BIT
431 && ctx
->Depth
.Func
==GL_LESS
432 && ctx
->Depth
.Mask
==GL_TRUE
433 && ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
434 && ctx
->Polygon
.StippleFlag
==GL_FALSE
) {
435 return tri_rgb_smooth_z
;
437 if (ctx
->Light
.ShadeModel
==GL_FLAT
438 && swrast
->_RasterMask
==DEPTH_BIT
439 && ctx
->Depth
.Func
==GL_LESS
440 && ctx
->Depth
.Mask
==GL_TRUE
441 && ctx
->Visual
.depthBits
== DEFAULT_SOFTWARE_DEPTH_BITS
442 && ctx
->Polygon
.StippleFlag
==GL_FALSE
) {
443 return tri_rgb_flat_z
;
445 if (swrast
->_RasterMask
==0 /* no depth test */
446 && ctx
->Light
.ShadeModel
==GL_SMOOTH
447 && ctx
->Polygon
.StippleFlag
==GL_FALSE
) {
448 return tri_rgb_smooth
;
450 if (swrast
->_RasterMask
==0 /* no depth test */
451 && ctx
->Light
.ShadeModel
==GL_FLAT
452 && ctx
->Polygon
.StippleFlag
==GL_FALSE
) {
456 return (swrast_tri_func
)NULL
;
461 /* Override for the swrast triangle-selection function. Try to use one
462 * of our internal line functions, otherwise fall back to the
463 * standard swrast functions.
465 static void dmesa_choose_tri (GLcontext
*ctx
)
467 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
469 if (!(swrast
->Triangle
=dmesa_choose_tri_function(ctx
)))
470 _swrast_choose_triangle(ctx
);
475 /**********************************************************************/
476 /***** Miscellaneous device driver funcs *****/
477 /**********************************************************************/
481 static void clear_color (GLcontext
*ctx
, const GLchan color
[4])
483 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
484 c
->ClearColor
= vl_mixrgba(color
);
489 static void clear (GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
490 GLint x
, GLint y
, GLint width
, GLint height
)
492 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
493 const GLuint
*colorMask
= (GLuint
*)&ctx
->Color
.ColorMask
;
494 DMesaBuffer b
= c
->Buffer
;
497 * Clear the specified region of the buffers indicated by 'mask'
498 * using the clear color or index as specified by one of the two
500 * If all==GL_TRUE, clear whole buffer, else just clear region defined
501 * by x,y,width,height
504 /* we can't handle color or index masking */
505 if (*colorMask
==0xffffffff) {
506 if (mask
& DD_BACK_LEFT_BIT
) {
508 if CHECK_SOFTDB(b
->caps
) {
509 vl_clear_virtual(b
->the_window
, b
->len
, c
->ClearColor
);
511 vl_clear(b
->the_window
, 0, 0, b
->width
, b
->height
, c
->ClearColor
);
514 vl_clear(b
->the_window
, x
, y
, width
, height
, c
->ClearColor
);
516 mask
&= ~DD_BACK_LEFT_BIT
;
518 if (mask
& DD_FRONT_LEFT_BIT
) {
525 vl_clear(b
->the_window
, x
, y
, width
, height
, c
->ClearColor
);
526 mask
&= ~DD_FRONT_LEFT_BIT
;
531 _swrast_Clear(ctx
, mask
, all
, x
, y
, width
, height
);
538 * Set the current reading buffer.
540 static void set_read_buffer (GLcontext
*ctx
, GLframebuffer
*buffer
,
544 DMesaContext c = (DMesaContext)ctx->DriverCtx;
545 dmesa_update_state(ctx);
552 * Set the destination/draw buffer.
554 static GLboolean
set_draw_buffer (GLcontext
*ctx
, GLenum mode
)
556 if (mode
==GL_BACK_LEFT
|| mode
==GL_FRONT_LEFT
) {
566 * Return the width and height of the current buffer.
567 * If anything special has to been done when the buffer/window is
568 * resized, do it now.
570 static void get_buffer_size (GLcontext
*ctx
, GLuint
*width
, GLuint
*height
)
572 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
574 *width
= c
->Buffer
->width
;
575 *height
= c
->Buffer
->height
;
580 static const GLubyte
* get_string (GLcontext
*ctx
, GLenum name
)
584 return (const GLubyte
*)"DOS Mesa";
592 /**********************************************************************/
593 /***** Miscellaneous device driver funcs *****/
594 /***** Note that these functions are mandatory *****/
595 /**********************************************************************/
599 /* OPTIONAL FUNCTION: implements glFinish if possible */
600 static void finish (GLcontext
*ctx
)
603 DMesaContext c = (DMesaContext)ctx->DriverCtx;
609 /* OPTIONAL FUNCTION: implements glFlush if possible */
610 static void flush (GLcontext
*ctx
)
613 DMesaContext c = (DMesaContext)ctx->DriverCtx;
619 /**********************************************************************/
620 /**********************************************************************/
624 #define DMESA_NEW_TRIANGLE (_NEW_POLYGON | \
629 _SWRAST_NEW_RASTERMASK)
633 /* Extend the software rasterizer with our line and triangle
636 static void dmesa_register_swrast_functions (GLcontext
*ctx
)
638 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
640 swrast
->choose_triangle
= dmesa_choose_tri
;
642 swrast
->invalidate_triangle
|= DMESA_NEW_TRIANGLE
;
647 /* Setup pointers and other driver state that is constant for the life
650 void dmesa_init_pointers (GLcontext
*ctx
)
654 ctx
->Driver
.UpdateState
= dmesa_update_state
;
656 ctx
->Driver
.GetString
= get_string
;
657 ctx
->Driver
.GetBufferSize
= get_buffer_size
;
658 ctx
->Driver
.Flush
= flush
;
659 ctx
->Driver
.Finish
= finish
;
661 /* Software rasterizer pixel paths:
663 ctx
->Driver
.Accum
= _swrast_Accum
;
664 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
665 ctx
->Driver
.Clear
= clear
;
666 ctx
->Driver
.ResizeBuffersMESA
= _swrast_alloc_buffers
;
667 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
668 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
669 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;
671 /* Software texture functions:
673 ctx
->Driver
.ChooseTextureFormat
= _mesa_choose_tex_format
;
674 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
675 ctx
->Driver
.TexImage2D
= _mesa_store_teximage2d
;
676 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
677 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
678 ctx
->Driver
.TexSubImage2D
= _mesa_store_texsubimage2d
;
679 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
680 ctx
->Driver
.TestProxyTexImage
= _mesa_test_proxy_teximage
;
682 ctx
->Driver
.CopyTexImage1D
= _swrast_copy_teximage1d
;
683 ctx
->Driver
.CopyTexImage2D
= _swrast_copy_teximage2d
;
684 ctx
->Driver
.CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
685 ctx
->Driver
.CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
686 ctx
->Driver
.CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
688 ctx
->Driver
.BaseCompressedTexFormat
= _mesa_base_compressed_texformat
;
689 ctx
->Driver
.CompressedTextureSize
= _mesa_compressed_texture_size
;
690 ctx
->Driver
.GetCompressedTexImage
= _mesa_get_compressed_teximage
;
692 /* Swrast hooks for imaging extensions:
694 ctx
->Driver
.CopyColorTable
= _swrast_CopyColorTable
;
695 ctx
->Driver
.CopyColorSubTable
= _swrast_CopyColorSubTable
;
696 ctx
->Driver
.CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
697 ctx
->Driver
.CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
699 /* Statechange callbacks:
701 ctx
->Driver
.SetDrawBuffer
= set_draw_buffer
;
702 ctx
->Driver
.ClearColor
= clear_color
;
704 /* Initialize the TNL driver interface:
706 tnl
= TNL_CONTEXT(ctx
);
707 tnl
->Driver
.RunPipeline
= _tnl_run_pipeline
;
709 /* Install swsetup for tnl->Driver.Render.*:
711 _swsetup_Wakeup(ctx
);
716 static void dmesa_update_state (GLcontext
*ctx
, GLuint new_state
)
718 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
719 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
721 /* Initialize all the pointers in the DD struct. Do this whenever */
722 /* a new context is made current or we change buffers via set_buffer! */
724 _swrast_InvalidateState(ctx
, new_state
);
725 _swsetup_InvalidateState(ctx
, new_state
);
726 _ac_InvalidateState(ctx
, new_state
);
727 _tnl_InvalidateState(ctx
, new_state
);
729 swdd
->SetReadBuffer
= set_read_buffer
;
731 /* RGB(A) span/pixel functions */
732 swdd
->WriteRGBASpan
= write_rgba_span
;
733 swdd
->WriteRGBSpan
= write_rgb_span
;
734 swdd
->WriteMonoRGBASpan
= write_mono_rgba_span
;
735 swdd
->WriteRGBAPixels
= write_rgba_pixels
;
736 swdd
->WriteMonoRGBAPixels
= write_mono_rgba_pixels
;
737 swdd
->ReadRGBASpan
= read_rgba_span
;
738 swdd
->ReadRGBAPixels
= read_rgba_pixels
;
743 /**********************************************************************/
744 /***** DMesa Public API Functions *****/
745 /**********************************************************************/
750 * The exact arguments to this function will depend on your window system
752 DMesaVisual
DMesaCreateVisual (GLint width
, GLint height
, GLint colDepth
,
753 GLboolean dbFlag
, GLint depthSize
,
758 GLint redBits
, greenBits
, blueBits
, alphaBits
;
788 if (vl_video_init(width
, height
, colDepth
, &caps
)!=0) {
792 if ((v
=(DMesaVisual
)calloc(1, sizeof(struct dmesa_visual
)))!=NULL
) {
793 /* Create core visual */
794 v
->gl_visual
= _mesa_create_visual(colDepth
>8, /* rgb */
796 GL_FALSE
, /* stereo */
804 accumSize
, /* accumRed */
805 accumSize
, /* accumGreen */
806 accumSize
, /* accumBlue */
807 alphaBits
?accumSize
:0, /* accumAlpha */
819 void DMesaDestroyVisual (DMesaVisual v
)
822 _mesa_destroy_visual(v
->gl_visual
);
828 DMesaBuffer
DMesaCreateBuffer (DMesaVisual visual
,
829 GLint xpos
, GLint ypos
,
830 GLint width
, GLint height
)
834 if ((b
=(DMesaBuffer
)calloc(1, sizeof(struct dmesa_buffer
)))!=NULL
) {
836 b
->gl_buffer
= _mesa_create_framebuffer(visual
->gl_visual
,
837 visual
->gl_visual
->depthBits
> 0,
838 visual
->gl_visual
->stencilBits
> 0,
839 visual
->gl_visual
->accumRedBits
> 0,
840 visual
->gl_visual
->alphaBits
> 0);
845 b
->caps
= visual
->caps
;
846 b
->pitch
= b
->width
*((visual
->depth
+7)/8);
847 b
->len
= b
->pitch
*b
->height
;
849 b
->tri_rgb_flat
= vl_getprim(TRI_RGB_FLAT
);
857 void DMesaDestroyBuffer (DMesaBuffer b
)
859 if CHECK_SOFTDB(b
->caps
) {
862 _mesa_destroy_framebuffer(b
->gl_buffer
);
868 DMesaContext
DMesaCreateContext (DMesaVisual visual
,
872 GLboolean direct
= GL_FALSE
;
874 if ((c
=(DMesaContext
)calloc(1, sizeof(struct dmesa_context
)))!=NULL
) {
875 c
->gl_ctx
= _mesa_create_context(visual
->gl_visual
,
876 share
? share
->gl_ctx
: NULL
,
879 _mesa_enable_sw_extensions(c
->gl_ctx
);
880 _mesa_enable_1_3_extensions(c
->gl_ctx
);
882 /* you probably have to do a bunch of other initializations here. */
885 /* Initialize the software rasterizer and helper modules.
887 _swrast_CreateContext(c
->gl_ctx
);
888 _ac_CreateContext(c
->gl_ctx
);
889 _tnl_CreateContext(c
->gl_ctx
);
890 _swsetup_CreateContext(c
->gl_ctx
);
891 dmesa_init_pointers(c
->gl_ctx
);
892 dmesa_register_swrast_functions(c
->gl_ctx
);
900 void DMesaDestroyContext (DMesaContext c
)
902 _mesa_destroy_context(c
->gl_ctx
);
909 * Make the specified context and buffer the current one.
911 GLboolean
DMesaMakeCurrent (DMesaContext c
, DMesaBuffer b
)
914 void *ptr
= vl_sync_buffer(b
->the_window
, b
->xpos
, b
->ypos
, b
->width
, b
->height
, &b
->cwidth
);
923 dmesa_update_state(c
->gl_ctx
, 0);
924 _mesa_make_current(c
->gl_ctx
, b
->gl_buffer
);
925 if (c
->gl_ctx
->Viewport
.Width
==0) {
926 /* initialize viewport to window size */
927 _mesa_Viewport(0, 0, c
->Buffer
->width
, c
->Buffer
->height
);
931 _mesa_make_current(NULL
, NULL
);
939 void DMesaSwapBuffers (DMesaBuffer b
)
941 /* copy/swap back buffer to front if applicable */
942 b
->the_window
= vl_flip(b
->the_window
, b
->width
, b
->height
, b
->pitch
);