2 * Mesa 3-D graphics library
4 * Copyright (C) 1995-1998 Brian Paul
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 GLvisual
*GLVisual
; /* inherit from GLvisual */
34 GLboolean DBFlag
; /* double buffered? */
35 GLuint Depth
; /* bits per pixel ( >= 15 ) */
41 GLframebuffer
*GLBuffer
; /* inherit from GLframebuffer */
51 GLcontext
*GLContext
; /* inherit from GLcontext */
59 static void setup_dd_pointers(GLcontext
*ctx
);
62 /**********************************************************************/
63 /***** drawing functions *****/
64 /**********************************************************************/
66 #define FLIP(context, y) (context->Buffer->Height - (y) - 1)
68 #include "allegro/generic.h"
69 #include "allegro/direct.h"
72 /**********************************************************************/
73 /***** 15-bit accelerated drawing funcs *****/
74 /**********************************************************************/
76 IMPLEMENT_WRITE_RGBA_SPAN(15, unsigned short)
77 IMPLEMENT_WRITE_RGB_SPAN(15, unsigned short)
78 IMPLEMENT_WRITE_MONO_RGBA_SPAN(15, unsigned short)
79 IMPLEMENT_READ_RGBA_SPAN(15, unsigned short)
80 IMPLEMENT_WRITE_RGBA_PIXELS(15, unsigned short)
81 IMPLEMENT_WRITE_MONO_RGBA_PIXELS(15, unsigned short)
82 IMPLEMENT_READ_RGBA_PIXELS(15, unsigned short)
85 /**********************************************************************/
86 /***** 16-bit accelerated drawing funcs *****/
87 /**********************************************************************/
89 IMPLEMENT_WRITE_RGBA_SPAN(16, unsigned short)
90 IMPLEMENT_WRITE_RGB_SPAN(16, unsigned short)
91 IMPLEMENT_WRITE_MONO_RGBA_SPAN(16, unsigned short)
92 IMPLEMENT_READ_RGBA_SPAN(16, unsigned short)
93 IMPLEMENT_WRITE_RGBA_PIXELS(16, unsigned short)
94 IMPLEMENT_WRITE_MONO_RGBA_PIXELS(16, unsigned short)
95 IMPLEMENT_READ_RGBA_PIXELS(16, unsigned short)
98 /**********************************************************************/
99 /***** 32-bit accelerated drawing funcs *****/
100 /**********************************************************************/
102 IMPLEMENT_WRITE_RGBA_SPAN(32, unsigned long)
103 IMPLEMENT_WRITE_RGB_SPAN(32, unsigned long)
104 IMPLEMENT_WRITE_MONO_RGBA_SPAN(32, unsigned long)
105 IMPLEMENT_READ_RGBA_SPAN(32, unsigned long)
106 IMPLEMENT_WRITE_RGBA_PIXELS(32, unsigned long)
107 IMPLEMENT_WRITE_MONO_RGBA_PIXELS(32, unsigned long)
108 IMPLEMENT_READ_RGBA_PIXELS(32, unsigned long)
111 /**********************************************************************/
112 /***** Miscellaneous device driver funcs *****/
113 /**********************************************************************/
115 static GLboolean
set_buffer(GLcontext
*ctx
, GLframebuffer
*buffer
, GLuint bit
)
117 AMesaContext context
= (AMesaContext
)(ctx
->DriverCtx
);
118 GLboolean ok
= GL_TRUE
;
120 if (bit
== FRONT_LEFT_BIT
)
121 context
->Buffer
->Active
= context
->Buffer
->Screen
;
123 else if (bit
== BACK_LEFT
)
125 if (context
->Buffer
->Background
)
126 context
->Buffer
->Active
= context
->Buffer
->Background
;
138 static void get_buffer_size(GLcontext
*ctx
, GLuint
*width
, GLuint
*height
)
140 AMesaContext context
= (AMesaContext
)(ctx
->DriverCtx
);
142 *width
= context
->Buffer
->Width
;
143 *height
= context
->Buffer
->Height
;
147 /**********************************************************************/
148 /**********************************************************************/
150 static void setup_dd_pointers(GLcontext
*ctx
)
152 AMesaContext context
= (AMesaContext
)(ctx
->DriverCtx
);
154 /* Initialize all the pointers in the driver struct. Do this whenever */
155 /* a new context is made current or we change buffers via set_buffer! */
157 ctx
->Driver
.UpdateState
= setup_dd_pointers
;
158 ctx
->Driver
.SetBuffer
= set_buffer
;
159 ctx
->Driver
.GetBufferSize
= get_buffer_size
;
161 ctx
->Driver
.Color
= set_color_generic
;
162 ctx
->Driver
.ClearColor
= clear_color_generic
;
163 ctx
->Driver
.Clear
= clear_generic
;
164 ctx
->Driver
.WriteRGBASpan
= write_rgba_span_generic
;
165 ctx
->Driver
.WriteRGBSpan
= write_rgb_span_generic
;
166 ctx
->Driver
.WriteMonoRGBASpan
= write_mono_rgba_span_generic
;
167 ctx
->Driver
.WriteRGBAPixels
= write_rgba_pixels_generic
;
168 ctx
->Driver
.WriteMonoRGBAPixels
= write_mono_rgba_pixels_generic
;
169 ctx
->Driver
.ReadRGBASpan
= read_rgba_span_generic
;
170 ctx
->Driver
.ReadRGBAPixels
= read_rgba_pixels_generic
;
172 if (context
->Buffer
->Active
!= screen
)
174 switch (context
->Visual
->Depth
)
177 ctx
->Driver
.WriteRGBASpan
= write_rgba_span_15
;
178 ctx
->Driver
.WriteRGBSpan
= write_rgb_span_15
;
179 ctx
->Driver
.WriteMonoRGBASpan
= write_mono_rgba_span_15
;
180 ctx
->Driver
.WriteRGBAPixels
= write_rgba_pixels_15
;
181 ctx
->Driver
.WriteMonoRGBAPixels
= write_mono_rgba_pixels_15
;
182 ctx
->Driver
.ReadRGBASpan
= read_rgba_span_15
;
183 ctx
->Driver
.ReadRGBAPixels
= read_rgba_pixels_15
;
187 ctx
->Driver
.WriteRGBASpan
= write_rgba_span_16
;
188 ctx
->Driver
.WriteRGBSpan
= write_rgb_span_16
;
189 ctx
->Driver
.WriteMonoRGBASpan
= write_mono_rgba_span_16
;
190 ctx
->Driver
.WriteRGBAPixels
= write_rgba_pixels_16
;
191 ctx
->Driver
.WriteMonoRGBAPixels
= write_mono_rgba_pixels_16
;
192 ctx
->Driver
.ReadRGBASpan
= read_rgba_span_16
;
193 ctx
->Driver
.ReadRGBAPixels
= read_rgba_pixels_16
;
197 ctx
->Driver
.WriteRGBASpan
= write_rgba_span_32
;
198 ctx
->Driver
.WriteRGBSpan
= write_rgb_span_32
;
199 ctx
->Driver
.WriteMonoRGBASpan
= write_mono_rgba_span_32
;
200 ctx
->Driver
.WriteRGBAPixels
= write_rgba_pixels_32
;
201 ctx
->Driver
.WriteMonoRGBAPixels
= write_mono_rgba_pixels_32
;
202 ctx
->Driver
.ReadRGBASpan
= read_rgba_span_32
;
203 ctx
->Driver
.ReadRGBAPixels
= read_rgba_pixels_32
;
210 /**********************************************************************/
211 /***** AMesa Public API Functions *****/
212 /**********************************************************************/
215 AMesaVisual
AMesaCreateVisual(GLboolean dbFlag
, GLint depth
,
216 GLint depthSize
, GLint stencilSize
, GLint accumSize
)
219 GLbyte redBits
, greenBits
, blueBits
;
221 visual
= (AMesaVisual
)calloc(1, sizeof(struct amesa_visual
));
250 visual
->DBFlag
= dbFlag
;
251 visual
->Depth
= depth
;
252 visual
->GLVisual
= _mesa_create_visual(GL_TRUE
, /* rgb mode */
253 dbFlag
, /* db_flag */
254 GL_FALSE
, /* stereo */
255 redBits
, greenBits
, blueBits
, 8,
257 depthSize
, /* depth bits */
258 stencilSize
,/* stencil bits */
259 accumSize
, /* accum bits */
260 accumSize
, /* accum bits */
261 accumSize
, /* accum bits */
262 accumSize
, /* accum bits */
264 if (!visual
->GLVisual
)
274 void AMesaDestroyVisual(AMesaVisual visual
)
276 _mesa_destroy_visual(visual
->GLVisual
);
281 AMesaBuffer
AMesaCreateBuffer(AMesaVisual visual
,
282 GLint width
, GLint height
)
286 buffer
= (AMesaBuffer
)calloc(1, sizeof(struct amesa_buffer
));
290 buffer
->Screen
= NULL
;
291 buffer
->Background
= NULL
;
292 buffer
->Active
= NULL
;
293 buffer
->Width
= width
;
294 buffer
->Height
= height
;
298 buffer
->Background
= create_bitmap_ex(visual
->Depth
, width
, height
);
299 if (!buffer
->Background
)
306 buffer
->GLBuffer
= _mesa_create_framebuffer(visual
->GLVisual
);
307 if (!buffer
->GLBuffer
)
309 if (buffer
->Background
) destroy_bitmap(buffer
->Background
);
318 void AMesaDestroyBuffer(AMesaBuffer buffer
)
320 if (buffer
->Screen
) destroy_bitmap(buffer
->Screen
);
321 if (buffer
->Background
) destroy_bitmap(buffer
->Background
);
322 _mesa_destroy_framebuffer(buffer
->GLBuffer
);
327 AMesaContext
AMesaCreateContext(AMesaVisual visual
,
330 AMesaContext context
;
331 GLboolean direct
= GL_FALSE
;
333 context
= (AMesaContext
)calloc(1, sizeof(struct amesa_context
));
337 context
->Visual
= visual
;
338 context
->Buffer
= NULL
;
339 context
->ClearColor
= 0;
340 context
->CurrentColor
= 0;
341 context
->GLContext
= _mesa_create_context(visual
->GLVisual
,
342 share
? share
->GLContext
: NULL
,
343 (void *) context
, GL_FALSE
);
344 if (!context
->GLContext
)
354 void AMesaDestroyContext(AMesaContext context
)
356 _mesa_destroy_context(context
->GLContext
);
361 GLboolean
AMesaMakeCurrent(AMesaContext context
, AMesaBuffer buffer
)
363 if (context
&& buffer
) {
364 set_color_depth(context
->Visual
->Depth
);
365 if (set_gfx_mode(GFX_AUTODETECT
, buffer
->Width
, buffer
->Height
, 0, 0) != 0)
368 context
->Buffer
= buffer
;
369 buffer
->Screen
= screen
;
370 buffer
->Active
= buffer
->Background
? buffer
->Background
: screen
;
372 setup_dd_pointers(context
->GLContext
);
373 _mesa_make_current(context
->GLContext
, buffer
->GLBuffer
);
374 _mesa_set_viewport(context
->GLContext
, 0, 0, buffer
->Width
, buffer
->Height
);
377 destroy_bitmap(context
->Buffer
->Screen
);
378 context
->Buffer
->Screen
= NULL
;
379 context
->Buffer
->Active
= NULL
;
380 context
->Buffer
= NULL
;
381 _mesa_make_current(NULL
, NULL
);
388 void AMesaSwapBuffers(AMesaBuffer buffer
)
390 if (buffer
->Background
) {
391 blit(buffer
->Background
, buffer
->Screen
,
393 buffer
->Width
, buffer
->Height
);