1 /* $Id: dosmesa.c,v 1.1 1999/08/19 00:55:41 jtg Exp $ */
4 * Mesa 3-D graphics library
6 * Copyright (C) 1995-1997 Brian Paul
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the Free
20 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 * Revision 1.1 1999/08/19 00:55:41 jtg
29 * Revision 1.2 1999/03/28 21:11:57 brianp
30 * updated SetBuffer driver function
32 * Revision 1.1 1999/02/24 03:56:31 brianp
36 * Revision 1.5 1997/06/19 22:00:00 Brian Paul
37 * Removed all ColorShift stuff
39 * Revision 1.4 1997/06/03 19:00:00 Brian Paul
40 * Replaced VB->Unclipped[] with VB->ClipMask[]
42 * Revision 1.3 1997/05/28 07:00:00 Phil Frisbie, Jr.
43 * Now pass red/green/blue/alpha bits to gl_create_visual()
44 * Fixed DJGPP mode 13 support.
46 * Revision 1.2 1996/12/08 16:13:45 Charlie
47 * Added VESA support via Scitechs SVGA kit.
49 * Revision 1.1 1996/12/08 16:09:52 Charlie
56 * DOS VGA/VESA/MGL/Mesa interface.
63 * Improve the colour matcher for rgb non vesa modes, its pretty bad and incorrect
65 * Comments and tidy up.
66 * Add support for VESA without SVGAKIT.
68 * Better GLIDE Support.
69 * Clear up the #ifdef madness.
74 #if defined(DOSVGA) && !defined(GLIDE) && defined(DJGPP) && !defined(UNIVBE) && !defined(MGL)
76 /* Should help cut down on the crazy #if`s */
97 #include "GL/DOSmesa.h"
104 static void glideshutdown( void );
108 /* the glide modes available, set one */
110 //#define GLIDE_MODE GR_RESOLUTION_
111 #define GLIDE_MODE GR_RESOLUTION_800x600
112 //#define GLIDE_MODE GR_RESOLUTION_640x480
114 static GrVertex gr_vtx
,gr_vtx1
,gr_vtx2
;
119 /* You get this file from Scitechs VESA development kit */
123 Set these to the VESA mode you require, the first is for 256 colour modes,
124 the other is High colour modes, they must both be the same XRes and YRes.
127 #define VESA_256COLOUR_MODE 0x11c
128 #define VESA_HICOLOUR_MODE 0x11f
132 struct DOSmesa_context
{
133 GLcontext
*gl_ctx
; /* the core Mesa context */
134 GLvisual
*gl_vis
; /* describes the color buffer */
135 GLframebuffer
*gl_buffer
; /* the ancillary buffers */
136 GLuint index
; /* current color index */
137 GLint red
, green
, blue
; /* current rgb color */
138 GLint width
, height
; /* size of color buffer */
139 GLint depth
; /* bits per pixel (8,16,24 or 32) */
142 static DOSMesaContext DOSMesa
= NULL
; /* the current context */
146 int useLinear
= TRUE
;
147 SV_modeInfo
*mi
=NULL
;
148 unsigned long modeNumber
= 0;
157 /* DOSVGA With no UniVBE support */
159 unsigned char *video_buffer
;
161 #define VID_BUF(x,y) *(video_buffer+x+(y*320))
163 #if defined(__WATCOMC__) && defined(__386__) && defined(__DOS__)
165 void setupcopy(void);
168 /* Watcom C specfic, screen copy and clear */
170 #pragma aux setupcopy = \
173 "mov esi,video_buffer" \
178 #pragma aux copyscr = \
180 "lop1: mov eax,[esi]"\
185 "mov dword ptr [esi],ebp"\
186 "mov dword ptr [esi+4],ebp"\
187 "mov dword ptr [esi+8],ebp"\
188 "mov dword ptr [esi+12],ebp"\
193 "mov ebx,[esi+4+16]"\
194 "mov edx,[esi+8+16]"\
196 "mov eax,[esi+12+16]"\
197 "mov dword ptr [esi+16],ebp"\
198 "mov dword ptr [esi+4+16],ebp"\
199 "mov dword ptr [esi+8+16],ebp"\
200 "mov dword ptr [esi+12+16],ebp"\
201 "mov [edi+4+16],ebx"\
202 "mov [edi+8+16],edx"\
203 "mov [edi+12+16],eax"\
209 modify exact [edi esi eax ebx ecx] ;
216 * Convert Mesa window Y coordinate to VGA screen Y coordinate:
218 #define FLIP(Y) (DOSMesa->height-(Y)-1)
220 unsigned short vga_cindex
= 32768 ;
222 static points_func
choose_points_function( void );
223 static line_func
choose_line_function( void );
224 static triangle_func
choose_polygon_function( void );
225 static void fast_tri(GLcontext
*ctx
,GLuint v0
, GLuint v1
, GLuint v2
, GLuint pv
);
227 static points_func
choose_points_function( void )
232 static line_func
choose_line_function( void )
237 static triangle_func
choose_triangle_function( void )
253 void setgfxmode(void);
254 void settextmode(void);
257 #pragma aux setgfxmode = \
262 #pragma aux settextmode = \
267 void setgfxmode(void)
269 union REGS in_regs
,out_regs
;
272 int386(0x10,&in_regs
,&out_regs
);
275 void settextmode(void)
277 union REGS in_regs
,out_regs
;
280 int386(0x10,&in_regs
,&out_regs
);
285 int set_video_mode(unsigned short x
,unsigned short y
,char mode
)
288 return 1; /* likelyhood of this failing is very small */
291 void restore_video_mode(void)
296 int vga_getcolors(void)
301 int vga_getxdim(void)
306 int vga_getydim(void)
311 static unsigned short num_rgb_alloc
= 1; /* start from 1, zero is black */
313 /* an unlikely colour */
314 static unsigned char last_r
=1,last_g
=255,last_b
=99;
316 extern void set_onecolor(int index
,int R
,int G
,int B
);
318 static unsigned char rgbtable
[64][64][64];
320 void vga_setrgbcolor(int r
,int g
,int b
)
324 * make this into a translation table
333 if( (r
== last_r
) && (g
== last_g
) && (b
== last_b
) ) return;
344 if( rgbtable
[r
][g
][b
] == 0 ) {
345 /* not allocated yet */
346 if(num_rgb_alloc
<256) {
347 DOSMesa
->index
= num_rgb_alloc
;
348 set_onecolor(num_rgb_alloc
,r
,g
,b
);
349 rgbtable
[r
][g
][b
] = num_rgb_alloc
;
354 /* need to search for a close colour */
356 unsigned short pass
;
358 for(pass
=0;pass
<64;pass
++) {
360 if( rgbtable
[r
-pass
][g
][b
] !=0 ) {
361 rgbtable
[r
][g
][b
] = rgbtable
[r
-pass
][g
][b
];
362 DOSMesa
->index
= rgbtable
[r
-pass
][g
][b
];
367 if( rgbtable
[r
+pass
][g
][b
] !=0 ) {
368 rgbtable
[r
][g
][b
] = rgbtable
[r
+pass
][g
][b
];
369 DOSMesa
->index
= rgbtable
[r
+pass
][g
][b
];
375 rgbtable
[r
][g
][b
] = rand()%255;
378 DOSMesa
->index
= rgbtable
[r
][g
][b
];
388 /* Check if we`re using watcom and DOS */
389 #if defined(__WATCOMC__) && defined(__386__) && defined(__DOS__)
403 movl _video_buffer, %esi
416 /* copy the RAM buffer to the Video memory */
417 memcpy((unsigned char *)0xa0000,video_buffer
, vga_getxdim()*vga_getydim() );
421 /* clear the RAM buffer */
422 memset(video_buffer
,0, vga_getxdim()*vga_getydim() );
429 #define vga_drawpixel(x,y) { VID_BUF(x,y) = DOSMesa->index; }
431 void vga_drawpixel(x
,y
)
433 VID_BUF(x
,y
) = DOSMesa
->index
;
437 int vga_getpixel(int x
,int y
)
447 void vga_setcolor(int index
)
449 /* does something, what i`ve no idea */
450 DOSMesa
->index
= index
;
458 /* UniVBE VESA support */
460 void set_video_mode(unsigned short x
,unsigned short y
,char mode
)
462 if( setup_vesa_mode(x
,y
,mode
) == FALSE
) {
463 fprintf(stderr
,"VESA: Set mode failed\n");
469 This is problematic as we don`t know what resolution the user program
470 wants when we reach here. This is why the 256 colour and HiColour modes
471 should be the same resolution, perhaps i`ll make this an environment
481 DC
= SV_init( TRUE
);
484 if(modeNumber
== 0 ) {
485 modeNumber
= VESA_HICOLOUR_MODE
;
488 SV_getModeInfo(modeNumber
,mi
);
493 int setup_vesa_mode(short height
,short width
,short depth
)
496 DC
= SV_init( TRUE
);
497 /* how many bits per pixel */
499 modeNumber
= VESA_256COLOUR_MODE
;
501 modeNumber
= VESA_HICOLOUR_MODE
;
504 /* Check if correct VESA Version is available */
505 if( !DC
|| DC
->VBEVersion
< 0x0102) {
506 fprintf(stderr
,"Require a VESA VBE version 1.2 or higher\n");
510 /* Check for LFB Supprt */
511 if(DC
->VBEVersion
< 0x0200 ) {
517 /* Get desired mode info */
518 if(!SV_getModeInfo( modeNumber
, mi
))
522 if(!SV_setMode(modeNumber
| svMultiBuffer
, FALSE
, TRUE
, mi
->NumberOfPages
) )
528 void restore_video_mode(void)
540 activePage
= 1-activePage
;
541 visualPage
= 1-activePage
;
543 SV_setActivePage(activePage
);
546 Change false to true if you`re getting flickering
547 even in double buffer mode, ( sets wait for Vertical retrace )
549 SV_setVisualPage(visualPage
,false);
552 int vga_getcolors(void)
555 switch ( mi
->BitsPerPixel
) {
566 int vga_getxdim(void)
569 return mi
->XResolution
;
572 int vga_getydim(void)
575 return mi
->YResolution
;
578 unsigned long current_color
= 255;
580 void vga_setrgbcolor(int r
,int g
,int b
)
585 current_color
= SV_rgbColor(r
,g
,b
);
588 void vga_setcolor(int index
)
590 DOSMesa
->index
= index
;
591 current_color
= index
;
594 void vga_drawpixel(x
,y
)
596 SV_putPixel(x
,y
,current_color
);
600 int vga_getpixel(x
,y
)
602 /* return (int)SV_getPixel(x,y); */
603 fprintf(stderr
,"vga_getpixel: Not implemented yet\n");
607 /* End of UNIVBE section */
610 /* Scitechs MegaGraphicsLibrary http://www.scitechsoft.com/ */
616 unsigned short BitsPerPixel
;
617 unsigned long XResolution
;
618 unsigned long YResolution
;
624 static int activePage
= 0;
625 static int visualPage
= 1;
626 static int modeNumber
= 0;
628 void set_video_mode(unsigned short xres
,unsigned short yres
,char mode
)
630 int i
,driver
= grDETECT
,dmode
= grDETECT
;
633 /* Start the MGL with only the SVGA 16m driver active */
634 MGL_registerDriver(MGL_SVGA16NAME
,SVGA16_driver
);
635 if (!MGL_init(&driver
,&dmode
,"..\\..\\"))
636 MGL_fatalError(MGL_errorMsg(MGL_result()));
637 if ((DC
= MGL_createDisplayDC(false)) == NULL
)
638 MGL_fatalError(MGL_errorMsg(MGL_result()));
639 MGL_makeCurrentDC(DC
);
643 This is problematic as we don`t know what resolution the user program
644 wants when we reach here. This is why the 256 colour and HiColour modes
645 should be the same resolution, perhaps i`ll make this an environment
649 #define MGL_HICOLOUR_MODE 0
657 // DC = SV_init( TRUE );
660 if(modeNumber
== 0 ) {
661 modeNumber
= MGL_HICOLOUR_MODE
;
664 // SV_getModeInfo(modeNumber,mi);
669 void restore_video_mode(void)
681 activePage
= 1-activePage
;
682 visualPage
= 1-activePage
;
684 // SV_setActivePage(activePage);
687 Change false to true if you`re getting flickering
688 even in double buffer mode, ( sets wait for Vertical retrace )
690 // SV_setVisualPage(visualPage,false);
693 int vga_getcolors(void)
696 switch ( mi
->BitsPerPixel
) {
707 int vga_getxdim(void)
710 return mi
->XResolution
;
713 int vga_getydim(void)
716 return mi
->YResolution
;
719 unsigned long current_color
= 255;
721 void vga_setrgbcolor(int r
,int g
,int b
)
726 current_color
= MGL_rgbColor(DC
,r
,g
,b
);
729 void vga_setcolor(int index
)
731 DOSMesa
->index
= index
;
732 current_color
= index
;
735 void vga_drawpixel(x
,y
)
741 int vga_getpixel(x
,y
)
743 /* return (int)SV_getPixel(x,y); */
744 fprintf(stderr
,"vga_getpixel: Not implemented yet\n");
748 /* End of UNIVBE section */
755 static GrHwConfiguration hwconfig
;
757 void set_video_mode(unsigned short x
,unsigned short y
,char mode
)
760 if( grSstQueryHardware( &hwconfig
) ) {
762 if( !grSstOpen( GLIDE_MODE
,
765 GR_ORIGIN_UPPER_LEFT
,
768 fprintf(stderr
,"Detected 3DFX board, but couldn`t initialize!");
772 grBufferClear( 0, 0, GR_WDEPTHVALUE_FARTHEST
);
774 grDisableAllEffects();
775 atexit( glideshutdown
);
777 // guColorCombineFunction( GR_COLORCOMBINE_ITRGB );
778 // grTexCombineFunction( GR_TMU0, GR_TEXTURECOMBINE_ZERO);
782 void restore_video_mode(void)
786 static void glideshutdown( void )
794 grBufferClear( 0, 0, GR_WDEPTHVALUE_FARTHEST
);
801 int vga_getcolors(void)
806 int vga_getxdim(void)
808 #if GLIDE_MODE == GR_RESOLUTION_800x600
815 int vga_getydim(void)
817 #if GLIDE_MODE == GR_RESOLUTION_800x600
824 unsigned long current_color
= 255;
826 void vga_setrgbcolor(int r
,int g
,int b
)
833 void vga_setcolor(int index
)
835 DOSMesa
->index
= index
;
838 void vga_drawpixel(x
,y
)
844 gr_vtx
.r
= DOSMesa
->red
;
845 gr_vtx
.g
= DOSMesa
->green
;
846 gr_vtx
.b
= DOSMesa
->blue
;
848 grDrawPoint( &gr_vtx
);
851 static void fast_tri(GLcontext
*ctx
,GLuint v0
, GLuint v1
, GLuint v2
, GLuint pv
)
853 struct vertex_buffer
*VB
= ctx
->VB
;
860 gr_vtx
.r
= DOSMesa
->red
;
861 gr_vtx
.g
= DOSMesa
->green
;
862 gr_vtx
.b
= DOSMesa
->blue
;
863 gr_vtx1
.r
= DOSMesa
->red
;
864 gr_vtx1
.g
= DOSMesa
->green
;
865 gr_vtx1
.b
= DOSMesa
->blue
;
866 gr_vtx2
.r
= DOSMesa
->red
;
867 gr_vtx2
.g
= DOSMesa
->green
;
868 gr_vtx2
.b
= DOSMesa
->blue
;
870 if(ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
871 gr_vtx
.r
= FixedToInt( VB
->Color
[v0
][0] );
872 gr_vtx
.g
= FixedToInt( VB
->Color
[v0
][1] );
873 gr_vtx
.b
= FixedToInt( VB
->Color
[v0
][2] );
875 gr_vtx1
.r
= FixedToInt( VB
->Color
[v1
][0] );
876 gr_vtx1
.g
= FixedToInt( VB
->Color
[v1
][1] );
877 gr_vtx1
.b
= FixedToInt( VB
->Color
[v1
][2] );
879 gr_vtx2
.r
= FixedToInt( VB
->Color
[v2
][0] );
880 gr_vtx2
.g
= FixedToInt( VB
->Color
[v2
][1] );
881 gr_vtx2
.b
= FixedToInt( VB
->Color
[v2
][2] );
883 gr_vtx
.r
= VB
->Color
[pv
][0];
884 gr_vtx
.g
= VB
->Color
[pv
][1];
885 gr_vtx
.b
= VB
->Color
[pv
][2];
887 gr_vtx1
.r
= VB
->Color
[pv
][0];
888 gr_vtx1
.g
= VB
->Color
[pv
][1];
889 gr_vtx1
.b
= VB
->Color
[pv
][2];
891 gr_vtx2
.r
= VB
->Color
[pv
][0];
892 gr_vtx2
.g
= VB
->Color
[pv
][1];
893 gr_vtx2
.b
= VB
->Color
[pv
][2];
897 gr_vtx
.x
= (VB
->Win
[v0
][0] );
898 gr_vtx
.y
= FLIP( (VB
->Win
[v0
][1] ) );
899 gr_vtx1
.x
= (VB
->Win
[v1
][0] );
900 gr_vtx1
.y
= FLIP( (VB
->Win
[v1
][1] ) );
901 gr_vtx2
.x
= (VB
->Win
[v2
][0] );
902 gr_vtx2
.y
= FLIP( (VB
->Win
[v2
][1] ) );
904 if(gr_vtx
.x
<0 || gr_vtx
.x
> 639 )
906 if(gr_vtx1
.x
<0 || gr_vtx1
.x
> 639 )
908 if(gr_vtx2
.x
<0 || gr_vtx2
.x
> 639 )
911 if(gr_vtx
.y
<0 || gr_vtx
.y
> 479 )
913 if(gr_vtx1
.y
<0 || gr_vtx1
.y
> 479 )
915 if(gr_vtx2
.y
<0 || gr_vtx2
.y
> 479 )
918 grDrawTriangle( &gr_vtx
,&gr_vtx1
,&gr_vtx2
);
921 void fast_plot(GLcontext
*ctx
,GLuint first
,GLuint last
)
923 struct vertex_buffer
*VB
= ctx
->VB
;
929 gr_vtx
.r
= DOSMesa
->red
;
930 gr_vtx
.g
= DOSMesa
->green
;
931 gr_vtx
.b
= DOSMesa
->blue
;
933 for(i
=first
;i
<last
;i
++) {
934 if(VB
->ClipMask
[i
]==0) {
935 gr_vtx
.x
= VB
->Win
[i
][0];
936 gr_vtx
.y
= FLIP(VB
->Win
[i
][1]);
943 int vga_getpixel(x
,y
)
945 /* return (int)SV_getPixel(x,y); */
946 fprintf(stderr
,"vga_getpixel: Not implemented yet\n");
950 /* End of GLIDE section */
953 /**********************************************************************/
954 /***** Miscellaneous functions *****/
955 /**********************************************************************/
958 static void get_buffer_size( GLcontext
*ctx
, GLuint
*width
, GLuint
*height
)
960 *width
= DOSMesa
->width
= vga_getxdim();
961 *height
= DOSMesa
->height
= vga_getydim();
965 /* Set current color index */
966 static void set_index( GLcontext
*ctx
, GLuint index
)
968 DOSMesa
->index
= index
;
969 /*vga_setcolor( index );*/
973 /* Set current drawing color */
974 static void set_color( GLcontext
*ctx
,
975 GLubyte red
, GLubyte green
,
976 GLubyte blue
, GLubyte alpha
)
979 DOSMesa
->green
= green
;
980 DOSMesa
->blue
= blue
;
981 vga_setrgbcolor( red
, green
, blue
);
985 static void clear_index( GLcontext
*ctx
, GLuint index
)
987 /* TODO: Implements glClearIndex() */
991 static void clear_color( GLcontext
*ctx
,
992 GLubyte red
, GLubyte green
,
993 GLubyte blue
, GLubyte alpha
)
995 /* TODO: Implements glClearColor() */
999 static void clear( GLcontext
*ctx
,
1001 GLint x
, GLint y
, GLint width
, GLint height
)
1007 static GLboolean
set_buffer( GLcontext
*ctx
,
1010 /* TODO: implement double buffering and use this function to select */
1011 /* between front and back buffers. */
1012 if (buffer
== GL_FRONT_LEFT
)
1014 else if (buffer
== GL_BACK_LEFT
)
1023 /**********************************************************************/
1024 /***** Write spans of pixels *****/
1025 /**********************************************************************/
1028 static void write_index_span( GLcontext
*ctx
,
1029 GLuint n
, GLint x
, GLint y
,
1030 const GLuint index
[],
1031 const GLubyte mask
[] )
1038 for (i
=0;i
<n
;i
++,x
++) {
1041 SV_putPixelFast(x
,y
,current_color
);
1043 vga_setcolor( index
[i
] );
1044 vga_drawpixel( x
, y
);
1057 static void write_monoindex_span( GLcontext
*ctx
,
1058 GLuint n
, GLint x
, GLint y
,
1059 const GLubyte mask
[] )
1063 /* use current color index */
1064 vga_setcolor( DOSMesa
->index
);
1068 for (i
=0;i
<n
;i
++,x
++) {
1071 SV_putPixelFast(x
,y
,current_color
);
1073 vga_drawpixel( x
, y
);
1084 static void write_color_span( GLcontext
*ctx
,
1085 GLuint n
, GLint x
, GLint y
,
1086 const GLubyte red
[], const GLubyte green
[],
1087 const GLubyte blue
[], const GLubyte alpha
[],
1088 const GLubyte mask
[] )
1096 /* draw some pixels */
1097 for (i
=0; i
<n
; i
++, x
++) {
1100 SV_putPixelFast(x
,y
,SV_rgbColor(red
[i
], green
[i
], blue
[i
]) );
1102 vga_setrgbcolor( red
[i
], green
[i
], blue
[i
] );
1103 vga_drawpixel( x
, y
);
1109 /* draw all pixels */
1110 for (i
=0; i
<n
; i
++, x
++) {
1112 SV_putPixelFast(x
,y
,SV_rgbColor(red
[i
], green
[i
], blue
[i
]) );
1114 vga_setrgbcolor( red
[i
], green
[i
], blue
[i
] );
1115 vga_drawpixel( x
, y
);
1126 static void write_monocolor_span( GLcontext
*ctx
,
1127 GLuint n
, GLint x
, GLint y
,
1128 const GLubyte mask
[])
1135 /* use current rgb color */
1136 vga_setrgbcolor( DOSMesa
->red
, DOSMesa
->green
, DOSMesa
->blue
);
1137 for (i
=0; i
<n
; i
++, x
++) {
1140 SV_putPixelFast(x
,y
,current_color
);
1142 vga_drawpixel( x
, y
);
1153 /**********************************************************************/
1154 /***** Read spans of pixels *****/
1155 /**********************************************************************/
1158 static void read_index_span( GLcontext
*ctx
,
1159 GLuint n
, GLint x
, GLint y
, GLuint index
[])
1163 for (i
=0; i
<n
; i
++,x
++) {
1164 index
[i
] = vga_getpixel( x
, y
);
1170 static void read_color_span( GLcontext
*ctx
,
1171 GLuint n
, GLint x
, GLint y
,
1172 GLubyte red
[], GLubyte green
[],
1173 GLubyte blue
[], GLubyte alpha
[] )
1176 for (i
=0; i
<n
; i
++, x
++) {
1183 /**********************************************************************/
1184 /***** Write arrays of pixels *****/
1185 /**********************************************************************/
1188 static void write_index_pixels( GLcontext
*ctx
,
1189 GLuint n
, const GLint x
[], const GLint y
[],
1190 const GLuint index
[], const GLubyte mask
[] )
1196 for (i
=0; i
<n
; i
++) {
1199 SV_putPixelFast(x
[i
], FLIP(y
[i
]), index
[i
] );
1201 vga_setcolor( index
[i
] );
1202 vga_drawpixel( x
[i
], FLIP(y
[i
]) );
1213 static void write_monoindex_pixels( GLcontext
*ctx
,
1215 const GLint x
[], const GLint y
[],
1216 const GLubyte mask
[] )
1219 /* use current color index */
1220 vga_setcolor( DOSMesa
->index
);
1224 for (i
=0; i
<n
; i
++) {
1227 SV_putPixelFast(x
[i
], FLIP(y
[i
]), DOSMesa
->index
);
1229 vga_drawpixel( x
[i
], FLIP(y
[i
]) );
1240 static void write_color_pixels( GLcontext
*ctx
,
1241 GLuint n
, const GLint x
[], const GLint y
[],
1242 const GLubyte r
[], const GLubyte g
[],
1243 const GLubyte b
[], const GLubyte a
[],
1244 const GLubyte mask
[] )
1250 for (i
=0; i
<n
; i
++) {
1253 SV_putPixelFast(x
[i
], FLIP(y
[i
]), SV_rgbColor(r
[i
], g
[i
], b
[i
]) );
1255 vga_setrgbcolor( r
[i
], g
[i
], b
[i
] );
1256 vga_drawpixel( x
[i
], FLIP(y
[i
]) );
1265 static void write_monocolor_pixels( GLcontext
*ctx
,
1267 const GLint x
[], const GLint y
[],
1268 const GLubyte mask
[] )
1271 /* use current rgb color */
1272 vga_setrgbcolor( DOSMesa
->red
, DOSMesa
->green
, DOSMesa
->blue
);
1276 for (i
=0; i
<n
; i
++) {
1279 SV_putPixelFast(x
[i
], FLIP(y
[i
]), current_color
);
1281 vga_drawpixel( x
[i
], FLIP(y
[i
]) );
1290 /**********************************************************************/
1291 /***** Read arrays of pixels *****/
1292 /**********************************************************************/
1294 /* Read an array of color index pixels. */
1295 static void read_index_pixels( GLcontext
*ctx
,
1296 GLuint n
, const GLint x
[], const GLint y
[],
1297 GLuint index
[], const GLubyte mask
[] )
1300 for (i
=0; i
<n
; i
++) {
1301 index
[i
] = vga_getpixel( x
[i
], FLIP(y
[i
]) );
1307 static void read_color_pixels( GLcontext
*ctx
,
1308 GLuint n
, const GLint x
[], const GLint y
[],
1309 GLubyte red
[], GLubyte green
[],
1310 GLubyte blue
[], GLubyte alpha
[],
1311 const GLubyte mask
[] )
1316 static void DOSmesa_setup_DD_pointers( GLcontext
*ctx
)
1318 /* Initialize all the pointers in the DD struct. Do this whenever */
1319 /* a new context is made current or we change buffers via set_buffer! */
1321 ctx
->Driver
.UpdateState
= DOSmesa_setup_DD_pointers
;
1323 ctx
->Driver
.ClearIndex
= clear_index
;
1324 ctx
->Driver
.ClearColor
= clear_color
;
1325 ctx
->Driver
.Clear
= clear
;
1327 ctx
->Driver
.Index
= set_index
;
1328 ctx
->Driver
.Color
= set_color
;
1330 ctx
->Driver
.SetBuffer
= set_buffer
;
1331 ctx
->Driver
.GetBufferSize
= get_buffer_size
;
1333 ctx
->Driver
.PointsFunc
= choose_points_function();
1334 ctx
->Driver
.LineFunc
= choose_line_function();
1335 ctx
->Driver
.TriangleFunc
= choose_triangle_function();
1338 /* Pixel/span writing functions: */
1339 /* TODO: use different funcs for 8, 16, 32-bit depths */
1340 ctx
->Driver
.WriteColorSpan
= write_color_span
;
1341 ctx
->Driver
.WriteMonocolorSpan
= write_monocolor_span
;
1342 ctx
->Driver
.WriteColorPixels
= write_color_pixels
;
1343 ctx
->Driver
.WriteMonocolorPixels
= write_monocolor_pixels
;
1344 ctx
->Driver
.WriteIndexSpan
= write_index_span
;
1345 ctx
->Driver
.WriteMonoindexSpan
= write_monoindex_span
;
1346 ctx
->Driver
.WriteIndexPixels
= write_index_pixels
;
1347 ctx
->Driver
.WriteMonoindexPixels
= write_monoindex_pixels
;
1349 /* Pixel/span reading functions: */
1350 /* TODO: use different funcs for 8, 16, 32-bit depths */
1351 ctx
->Driver
.ReadIndexSpan
= read_index_span
;
1352 ctx
->Driver
.ReadColorSpan
= read_color_span
;
1353 ctx
->Driver
.ReadIndexPixels
= read_index_pixels
;
1354 ctx
->Driver
.ReadColorPixels
= read_color_pixels
;
1358 * Create a new VGA/Mesa context and return a handle to it.
1360 DOSMesaContext
DOSMesaCreateContext( void )
1364 GLfloat redscale
, greenscale
, bluescale
, alphascale
;
1365 GLboolean db_flag
= GL_FALSE
;
1366 GLboolean alpha_flag
= GL_FALSE
;
1369 GLint redbits
, greenbits
, bluebits
, alphabits
;
1371 #if !defined(UNIVBE) && !defined(GLIDE) && !defined(MGL)
1372 video_buffer
= (unsigned char *) malloc( vga_getxdim() * vga_getydim() );
1374 memset(video_buffer
,0, vga_getxdim() * vga_getydim() );
1376 memset(rgbtable
,0,sizeof( rgbtable
) );
1379 #if defined( DJGPP ) && !defined(UNIVBE) && !defined(GLIDE)
1380 dos_seg
= _go32_conventional_mem_selector();
1383 /* determine if we're in RGB or color index mode */
1384 colors
= vga_getcolors();
1385 if (colors
==32768) {
1387 redscale
= greenscale
= bluescale
= alphascale
= 255.0;
1388 redbits
= greenbits
= bluebits
= 8;
1392 else if (colors
==256) {
1393 rgb_flag
= GL_FALSE
;
1394 redscale
= greenscale
= bluescale
= alphascale
= 0.0;
1395 redbits
= greenbits
= bluebits
= alphabits
= 0;
1399 restore_video_mode();
1400 fprintf(stderr
,"[%d] >16 bit color not implemented yet!\n",colors
);
1404 ctx
= (DOSMesaContext
) calloc( 1, sizeof(struct DOSmesa_context
) );
1409 ctx
->gl_vis
= gl_create_visual( rgb_flag
,
1412 16, /* depth_size */
1413 8, /* stencil_size */
1414 16, /* accum_size */
1421 bluebits
, alphabits
);
1423 ctx
->gl_ctx
= gl_create_context( ctx
->gl_vis
,
1424 NULL
, /* share list context */
1428 ctx
->gl_buffer
= gl_create_framebuffer( ctx
->gl_vis
);
1431 ctx
->red
= ctx
->green
= ctx
->blue
= 255;
1433 ctx
->width
= ctx
->height
= 0; /* temporary until first "make-current" */
1439 * Destroy the given VGA/Mesa context.
1441 void DOSMesaDestroyContext( DOSMesaContext ctx
)
1444 gl_destroy_visual( ctx
->gl_vis
);
1445 gl_destroy_context( ctx
->gl_ctx
);
1446 gl_destroy_framebuffer( ctx
->gl_buffer
);
1457 * Make the specified VGA/Mesa context the current one.
1459 void DOSMesaMakeCurrent( DOSMesaContext ctx
)
1462 gl_make_current( ctx
->gl_ctx
, ctx
->gl_buffer
);
1463 DOSmesa_setup_DD_pointers( ctx
->gl_ctx
);
1465 if (ctx
->width
==0 || ctx
->height
==0) {
1466 /* setup initial viewport */
1467 ctx
->width
= vga_getxdim();
1468 ctx
->height
= vga_getydim();
1469 gl_Viewport( ctx
->gl_ctx
, 0, 0, ctx
->width
, ctx
->height
);
1476 * Return a handle to the current VGA/Mesa context.
1478 DOSMesaContext
DOSMesaGetCurrentContext( void )
1485 * Swap front/back buffers for current context if double buffered.
1487 void DOSMesaSwapBuffers( void )
1489 #if !defined(UNIVBE)
1490 /* Assume double buffering is available if in UNIVBE,
1491 if it isn`t its taken care of anyway */
1492 // if (DOSMesa->gl_vis->DBflag)
1503 * Need this to provide at least one external definition when DOS is
1504 * not defined on the compiler command line.
1507 int gl_DOS_dummy_function(void)