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
._ReallyEnabled
) 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 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
471 c
->ClearColor
= vl_mixrgba(color
);
476 static void clear (GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
477 GLint x
, GLint y
, GLint width
, GLint height
)
479 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
480 const GLuint
*colorMask
= (GLuint
*)&ctx
->Color
.ColorMask
;
481 DMesaBuffer b
= c
->Buffer
;
484 * Clear the specified region of the buffers indicated by 'mask'
485 * using the clear color or index as specified by one of the two
487 * If all==GL_TRUE, clear whole buffer, else just clear region defined
488 * by x,y,width,height
491 /* we can't handle color or index masking */
492 if (*colorMask
==0xffffffff) {
493 if (mask
& DD_BACK_LEFT_BIT
) {
495 vl_clear(b
->the_window
, b
->bytes
, c
->ClearColor
);
497 vl_rect(b
->the_window
, x
, y
, width
, height
, c
->ClearColor
);
499 mask
&= ~DD_BACK_LEFT_BIT
;
504 _swrast_Clear(ctx
, mask
, all
, x
, y
, width
, height
);
511 * Set the current reading buffer.
513 static void set_read_buffer (GLcontext
*ctx
, GLframebuffer
*buffer
,
517 XXX this has to be fixed
524 * Set the destination/draw buffer.
526 static void set_draw_buffer (GLcontext
*ctx
, GLenum mode
)
529 XXX this has to be fixed
536 * Return the width and height of the current buffer.
537 * If anything special has to been done when the buffer/window is
538 * resized, do it now.
540 static void get_buffer_size (GLframebuffer
*buffer
, GLuint
*width
, GLuint
*height
)
542 DMesaBuffer b
= (DMesaBuffer
)buffer
;
550 static const GLubyte
* get_string (GLcontext
*ctx
, GLenum name
)
554 return (const GLubyte
*)"Mesa DJGPP\0port (c) Borca Daniel 3-sep-2002";
562 /**********************************************************************/
563 /***** Miscellaneous device driver funcs *****/
564 /***** Note that these functions are mandatory *****/
565 /**********************************************************************/
569 /* OPTIONAL FUNCTION: implements glFinish if possible */
570 static void finish (GLcontext
*ctx
)
573 DMesaContext c = (DMesaContext)ctx->DriverCtx;
579 /* OPTIONAL FUNCTION: implements glFlush if possible */
580 static void flush (GLcontext
*ctx
)
583 DMesaContext c = (DMesaContext)ctx->DriverCtx;
589 /**********************************************************************/
590 /**********************************************************************/
594 #define DMESA_NEW_TRIANGLE (_NEW_POLYGON | \
599 _SWRAST_NEW_RASTERMASK)
603 /* Extend the software rasterizer with our line and triangle
606 static void dmesa_register_swrast_functions (GLcontext
*ctx
)
608 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
610 swrast
->choose_triangle
= dmesa_choose_tri
;
612 swrast
->invalidate_triangle
|= DMESA_NEW_TRIANGLE
;
617 /* Setup pointers and other driver state that is constant for the life
620 void dmesa_init_pointers (GLcontext
*ctx
)
624 ctx
->Driver
.UpdateState
= dmesa_update_state
;
626 ctx
->Driver
.GetString
= get_string
;
627 ctx
->Driver
.GetBufferSize
= get_buffer_size
;
628 ctx
->Driver
.Flush
= flush
;
629 ctx
->Driver
.Finish
= finish
;
631 /* Software rasterizer pixel paths:
633 ctx
->Driver
.Accum
= _swrast_Accum
;
634 ctx
->Driver
.Bitmap
= _swrast_Bitmap
;
635 ctx
->Driver
.Clear
= clear
;
636 ctx
->Driver
.ResizeBuffers
= _swrast_alloc_buffers
;
637 ctx
->Driver
.CopyPixels
= _swrast_CopyPixels
;
638 ctx
->Driver
.DrawPixels
= _swrast_DrawPixels
;
639 ctx
->Driver
.ReadPixels
= _swrast_ReadPixels
;
641 /* Software texture functions:
643 ctx
->Driver
.ChooseTextureFormat
= _mesa_choose_tex_format
;
644 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
645 ctx
->Driver
.TexImage2D
= _mesa_store_teximage2d
;
646 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
647 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
648 ctx
->Driver
.TexSubImage2D
= _mesa_store_texsubimage2d
;
649 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
650 ctx
->Driver
.TestProxyTexImage
= _mesa_test_proxy_teximage
;
652 ctx
->Driver
.CopyTexImage1D
= _swrast_copy_teximage1d
;
653 ctx
->Driver
.CopyTexImage2D
= _swrast_copy_teximage2d
;
654 ctx
->Driver
.CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
655 ctx
->Driver
.CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
656 ctx
->Driver
.CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
658 ctx
->Driver
.BaseCompressedTexFormat
= _mesa_base_compressed_texformat
;
659 ctx
->Driver
.CompressedTextureSize
= _mesa_compressed_texture_size
;
660 ctx
->Driver
.GetCompressedTexImage
= _mesa_get_compressed_teximage
;
662 /* Swrast hooks for imaging extensions:
664 ctx
->Driver
.CopyColorTable
= _swrast_CopyColorTable
;
665 ctx
->Driver
.CopyColorSubTable
= _swrast_CopyColorSubTable
;
666 ctx
->Driver
.CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
667 ctx
->Driver
.CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
669 /* Statechange callbacks:
671 ctx
->Driver
.SetDrawBuffer
= set_draw_buffer
;
672 ctx
->Driver
.ClearColor
= clear_color
;
674 /* Initialize the TNL driver interface:
676 tnl
= TNL_CONTEXT(ctx
);
677 tnl
->Driver
.RunPipeline
= _tnl_run_pipeline
;
679 /* Install swsetup for tnl->Driver.Render.*:
681 _swsetup_Wakeup(ctx
);
686 static void dmesa_update_state (GLcontext
*ctx
, GLuint new_state
)
688 DMesaContext c
= (DMesaContext
)ctx
->DriverCtx
;
689 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
691 /* Initialize all the pointers in the DD struct. Do this whenever */
692 /* a new context is made current or we change buffers via set_buffer! */
694 _swrast_InvalidateState(ctx
, new_state
);
695 _swsetup_InvalidateState(ctx
, new_state
);
696 _ac_InvalidateState(ctx
, new_state
);
697 _tnl_InvalidateState(ctx
, new_state
);
699 swdd
->SetReadBuffer
= set_read_buffer
;
701 /* RGB(A) span/pixel functions */
702 swdd
->WriteRGBASpan
= write_rgba_span
;
703 swdd
->WriteRGBSpan
= write_rgb_span
;
704 swdd
->WriteMonoRGBASpan
= write_mono_rgba_span
;
705 swdd
->WriteRGBAPixels
= write_rgba_pixels
;
706 swdd
->WriteMonoRGBAPixels
= write_mono_rgba_pixels
;
707 swdd
->ReadRGBASpan
= read_rgba_span
;
708 swdd
->ReadRGBAPixels
= read_rgba_pixels
;
713 /**********************************************************************/
714 /***** DMesa Public API Functions *****/
715 /**********************************************************************/
720 * The exact arguments to this function will depend on your window system
722 DMesaVisual
DMesaCreateVisual (GLint width
, GLint height
, GLint colDepth
,
723 GLboolean dbFlag
, GLint depthSize
,
728 GLint redBits
, greenBits
, blueBits
, alphaBits
;
731 char *var
= getenv("DMESA_REFRESH");
732 if ((var
== NULL
) || ((refresh
=atoi(var
)) == 0)) {
762 if (vl_video_init(width
, height
, colDepth
, refresh
) != 0) {
766 if ((v
=(DMesaVisual
)calloc(1, sizeof(struct dmesa_visual
)))!=NULL
) {
767 /* Create core visual */
768 v
->gl_visual
= _mesa_create_visual(colDepth
>8, /* rgb */
770 GL_FALSE
, /* stereo */
778 accumSize
, /* accumRed */
779 accumSize
, /* accumGreen */
780 accumSize
, /* accumBlue */
781 alphaBits
?accumSize
:0, /* accumAlpha */
793 void DMesaDestroyVisual (DMesaVisual v
)
796 _mesa_destroy_visual(v
->gl_visual
);
802 DMesaBuffer
DMesaCreateBuffer (DMesaVisual visual
,
803 GLint xpos
, GLint ypos
,
804 GLint width
, GLint height
)
808 if ((b
=(DMesaBuffer
)calloc(1, sizeof(struct dmesa_buffer
)))!=NULL
) {
810 _mesa_initialize_framebuffer(&b
->gl_buffer
,
812 visual
->gl_visual
->depthBits
> 0,
813 visual
->gl_visual
->stencilBits
> 0,
814 visual
->gl_visual
->accumRedBits
> 0,
815 visual
->gl_visual
->alphaBits
> 0);
820 b
->bypp
= (visual
->depth
+7)/8;
828 void DMesaDestroyBuffer (DMesaBuffer b
)
831 _mesa_free_framebuffer_data(&b
->gl_buffer
);
837 DMesaContext
DMesaCreateContext (DMesaVisual visual
,
841 GLboolean direct
= GL_FALSE
;
843 if ((c
=(DMesaContext
)calloc(1, sizeof(struct dmesa_context
)))!=NULL
) {
844 c
->gl_ctx
= _mesa_create_context(visual
->gl_visual
,
845 share
? share
->gl_ctx
: NULL
,
848 _mesa_enable_sw_extensions(c
->gl_ctx
);
849 _mesa_enable_1_3_extensions(c
->gl_ctx
);
851 /* you probably have to do a bunch of other initializations here. */
854 /* Initialize the software rasterizer and helper modules.
856 _swrast_CreateContext(c
->gl_ctx
);
857 _ac_CreateContext(c
->gl_ctx
);
858 _tnl_CreateContext(c
->gl_ctx
);
859 _swsetup_CreateContext(c
->gl_ctx
);
860 dmesa_init_pointers(c
->gl_ctx
);
861 dmesa_register_swrast_functions(c
->gl_ctx
);
869 void DMesaDestroyContext (DMesaContext c
)
871 _mesa_destroy_context(c
->gl_ctx
);
877 GLboolean
DMesaViewport (DMesaBuffer b
,
878 GLint xpos
, GLint ypos
,
879 GLint width
, GLint height
)
883 if ((new_window
=vl_sync_buffer(b
->the_window
, xpos
, ypos
, width
, height
))==NULL
) {
886 b
->the_window
= new_window
;
891 b
->stride
= width
* b
->bypp
;
892 b
->bytes
= b
->stride
* height
;
900 * Make the specified context and buffer the current one.
902 GLboolean
DMesaMakeCurrent (DMesaContext c
, DMesaBuffer b
)
905 if (!DMesaViewport(b
, b
->xpos
, b
->ypos
, b
->width
, b
->height
)) {
911 dmesa_update_state(c
->gl_ctx
, 0);
912 _mesa_make_current(c
->gl_ctx
, &b
->gl_buffer
);
913 if (c
->gl_ctx
->Viewport
.Width
==0) {
914 /* initialize viewport to window size */
915 _mesa_Viewport(0, 0, b
->width
, b
->height
);
919 _mesa_make_current(NULL
, NULL
);
927 void DMesaSwapBuffers (DMesaBuffer b
)
929 /* copy/swap back buffer to front if applicable */
930 GET_CURRENT_CONTEXT(ctx
);
931 _mesa_swapbuffers(ctx
);
932 vl_flip(b
->the_window
, b
->stride
, b
->height
);