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.
32 GLvisual
*GLVisual
; /* inherit from GLvisual */
33 GLboolean DBFlag
; /* double buffered? */
34 GLuint Depth
; /* bits per pixel ( >= 15 ) */
40 GLframebuffer
*GLBuffer
; /* inherit from GLframebuffer */
50 GLcontext
*GLContext
; /* inherit from GLcontext */
58 static void setup_dd_pointers(GLcontext
*ctx
);
61 /**********************************************************************/
62 /***** drawing functions *****/
63 /**********************************************************************/
65 #define FLIP(context, y) (context->Buffer->Height - (y) - 1)
67 #include "allegro/generic.h"
68 #include "allegro/direct.h"
71 /**********************************************************************/
72 /***** 15-bit accelerated drawing funcs *****/
73 /**********************************************************************/
75 IMPLEMENT_WRITE_RGBA_SPAN(15, unsigned short)
76 IMPLEMENT_WRITE_RGB_SPAN(15, unsigned short)
77 IMPLEMENT_WRITE_MONO_RGBA_SPAN(15, unsigned short)
78 IMPLEMENT_READ_RGBA_SPAN(15, unsigned short)
79 IMPLEMENT_WRITE_RGBA_PIXELS(15, unsigned short)
80 IMPLEMENT_WRITE_MONO_RGBA_PIXELS(15, unsigned short)
81 IMPLEMENT_READ_RGBA_PIXELS(15, unsigned short)
84 /**********************************************************************/
85 /***** 16-bit accelerated drawing funcs *****/
86 /**********************************************************************/
88 IMPLEMENT_WRITE_RGBA_SPAN(16, unsigned short)
89 IMPLEMENT_WRITE_RGB_SPAN(16, unsigned short)
90 IMPLEMENT_WRITE_MONO_RGBA_SPAN(16, unsigned short)
91 IMPLEMENT_READ_RGBA_SPAN(16, unsigned short)
92 IMPLEMENT_WRITE_RGBA_PIXELS(16, unsigned short)
93 IMPLEMENT_WRITE_MONO_RGBA_PIXELS(16, unsigned short)
94 IMPLEMENT_READ_RGBA_PIXELS(16, unsigned short)
97 /**********************************************************************/
98 /***** 32-bit accelerated drawing funcs *****/
99 /**********************************************************************/
101 IMPLEMENT_WRITE_RGBA_SPAN(32, unsigned long)
102 IMPLEMENT_WRITE_RGB_SPAN(32, unsigned long)
103 IMPLEMENT_WRITE_MONO_RGBA_SPAN(32, unsigned long)
104 IMPLEMENT_READ_RGBA_SPAN(32, unsigned long)
105 IMPLEMENT_WRITE_RGBA_PIXELS(32, unsigned long)
106 IMPLEMENT_WRITE_MONO_RGBA_PIXELS(32, unsigned long)
107 IMPLEMENT_READ_RGBA_PIXELS(32, unsigned long)
110 /**********************************************************************/
111 /***** Miscellaneous device driver funcs *****/
112 /**********************************************************************/
114 static GLboolean
set_buffer(GLcontext
*ctx
, GLenum mode
)
116 AMesaContext context
= (AMesaContext
)(ctx
->DriverCtx
);
117 GLboolean ok
= GL_TRUE
;
119 if (mode
== GL_FRONT_LEFT
)
120 context
->Buffer
->Active
= context
->Buffer
->Screen
;
122 else if (mode
== GL_BACK_LEFT
)
124 if (context
->Buffer
->Background
)
125 context
->Buffer
->Active
= context
->Buffer
->Background
;
137 static void get_buffer_size(GLcontext
*ctx
, GLuint
*width
, GLuint
*height
)
139 AMesaContext context
= (AMesaContext
)(ctx
->DriverCtx
);
141 *width
= context
->Buffer
->Width
;
142 *height
= context
->Buffer
->Height
;
146 /**********************************************************************/
147 /**********************************************************************/
149 static void setup_dd_pointers(GLcontext
*ctx
)
151 AMesaContext context
= (AMesaContext
)(ctx
->DriverCtx
);
153 /* Initialize all the pointers in the driver struct. Do this whenever */
154 /* a new context is made current or we change buffers via set_buffer! */
156 ctx
->Driver
.UpdateState
= setup_dd_pointers
;
157 ctx
->Driver
.SetBuffer
= set_buffer
;
158 ctx
->Driver
.GetBufferSize
= get_buffer_size
;
160 ctx
->Driver
.Color
= set_color_generic
;
161 ctx
->Driver
.ClearColor
= clear_color_generic
;
162 ctx
->Driver
.Clear
= clear_generic
;
163 ctx
->Driver
.WriteRGBASpan
= write_rgba_span_generic
;
164 ctx
->Driver
.WriteRGBSpan
= write_rgb_span_generic
;
165 ctx
->Driver
.WriteMonoRGBASpan
= write_mono_rgba_span_generic
;
166 ctx
->Driver
.WriteRGBAPixels
= write_rgba_pixels_generic
;
167 ctx
->Driver
.WriteMonoRGBAPixels
= write_mono_rgba_pixels_generic
;
168 ctx
->Driver
.ReadRGBASpan
= read_rgba_span_generic
;
169 ctx
->Driver
.ReadRGBAPixels
= read_rgba_pixels_generic
;
171 if (context
->Buffer
->Active
!= screen
)
173 switch (context
->Visual
->Depth
)
176 ctx
->Driver
.WriteRGBASpan
= write_rgba_span_15
;
177 ctx
->Driver
.WriteRGBSpan
= write_rgb_span_15
;
178 ctx
->Driver
.WriteMonoRGBASpan
= write_mono_rgba_span_15
;
179 ctx
->Driver
.WriteRGBAPixels
= write_rgba_pixels_15
;
180 ctx
->Driver
.WriteMonoRGBAPixels
= write_mono_rgba_pixels_15
;
181 ctx
->Driver
.ReadRGBASpan
= read_rgba_span_15
;
182 ctx
->Driver
.ReadRGBAPixels
= read_rgba_pixels_15
;
186 ctx
->Driver
.WriteRGBASpan
= write_rgba_span_16
;
187 ctx
->Driver
.WriteRGBSpan
= write_rgb_span_16
;
188 ctx
->Driver
.WriteMonoRGBASpan
= write_mono_rgba_span_16
;
189 ctx
->Driver
.WriteRGBAPixels
= write_rgba_pixels_16
;
190 ctx
->Driver
.WriteMonoRGBAPixels
= write_mono_rgba_pixels_16
;
191 ctx
->Driver
.ReadRGBASpan
= read_rgba_span_16
;
192 ctx
->Driver
.ReadRGBAPixels
= read_rgba_pixels_16
;
196 ctx
->Driver
.WriteRGBASpan
= write_rgba_span_32
;
197 ctx
->Driver
.WriteRGBSpan
= write_rgb_span_32
;
198 ctx
->Driver
.WriteMonoRGBASpan
= write_mono_rgba_span_32
;
199 ctx
->Driver
.WriteRGBAPixels
= write_rgba_pixels_32
;
200 ctx
->Driver
.WriteMonoRGBAPixels
= write_mono_rgba_pixels_32
;
201 ctx
->Driver
.ReadRGBASpan
= read_rgba_span_32
;
202 ctx
->Driver
.ReadRGBAPixels
= read_rgba_pixels_32
;
209 /**********************************************************************/
210 /***** AMesa Public API Functions *****/
211 /**********************************************************************/
214 AMesaVisual
AMesaCreateVisual(GLboolean dbFlag
, GLint depth
,
215 GLint depthSize
, GLint stencilSize
, GLint accumSize
)
218 GLbyte redBits
, greenBits
, blueBits
;
220 visual
= (AMesaVisual
)calloc(1, sizeof(struct amesa_visual
));
249 visual
->DBFlag
= dbFlag
;
250 visual
->Depth
= depth
;
251 visual
->GLVisual
= gl_create_visual(GL_TRUE
, /* rgb mode */
252 GL_TRUE
, /* software alpha */
253 dbFlag
, /* db_flag */
254 GL_FALSE
, /* stereo */
255 depthSize
, /* depth bits */
256 stencilSize
,/* stencil bits */
257 accumSize
, /* accum bits */
259 redBits
, greenBits
, blueBits
, 0);
260 if (!visual
->GLVisual
)
270 void AMesaDestroyVisual(AMesaVisual visual
)
272 gl_destroy_visual(visual
->GLVisual
);
277 AMesaBuffer
AMesaCreateBuffer(AMesaVisual visual
,
278 GLint width
, GLint height
)
282 buffer
= (AMesaBuffer
)calloc(1, sizeof(struct amesa_buffer
));
286 buffer
->Screen
= NULL
;
287 buffer
->Background
= NULL
;
288 buffer
->Active
= NULL
;
289 buffer
->Width
= width
;
290 buffer
->Height
= height
;
294 buffer
->Background
= create_bitmap_ex(visual
->Depth
, width
, height
);
295 if (!buffer
->Background
)
302 buffer
->GLBuffer
= gl_create_framebuffer(visual
->GLVisual
);
303 if (!buffer
->GLBuffer
)
305 if (buffer
->Background
) destroy_bitmap(buffer
->Background
);
314 void AMesaDestroyBuffer(AMesaBuffer buffer
)
316 if (buffer
->Screen
) destroy_bitmap(buffer
->Screen
);
317 if (buffer
->Background
) destroy_bitmap(buffer
->Background
);
318 gl_destroy_framebuffer(buffer
->GLBuffer
);
323 AMesaContext
AMesaCreateContext(AMesaVisual visual
,
326 AMesaContext context
;
327 GLboolean direct
= GL_FALSE
;
329 context
= (AMesaContext
)calloc(1, sizeof(struct amesa_context
));
333 context
->Visual
= visual
;
334 context
->Buffer
= NULL
;
335 context
->ClearColor
= 0;
336 context
->CurrentColor
= 0;
337 context
->GLContext
= gl_create_context(visual
->GLVisual
,
338 share
? share
->GLContext
: NULL
,
341 if (!context
->GLContext
)
351 void AMesaDestroyContext(AMesaContext context
)
353 gl_destroy_context(context
->GLContext
);
358 GLboolean
AMesaMakeCurrent(AMesaContext context
, AMesaBuffer buffer
)
360 if (context
&& buffer
)
362 set_color_depth(context
->Visual
->Depth
);
363 if (set_gfx_mode(GFX_AUTODETECT
, buffer
->Width
, buffer
->Height
, 0, 0) != 0)
366 context
->Buffer
= buffer
;
367 buffer
->Screen
= screen
;
368 buffer
->Active
= buffer
->Background
? buffer
->Background
: screen
;
370 setup_dd_pointers(context
->GLContext
);
371 gl_make_current(context
->GLContext
, buffer
->GLBuffer
);
372 gl_Viewport(context
->GLContext
, 0, 0, buffer
->Width
, buffer
->Height
);
376 destroy_bitmap(context
->Buffer
->Screen
);
377 context
->Buffer
->Screen
= NULL
;
378 context
->Buffer
->Active
= NULL
;
379 context
->Buffer
= NULL
;
380 gl_make_current(NULL
, NULL
);
387 void AMesaSwapBuffers(AMesaBuffer buffer
)
389 if (buffer
->Background
)
391 blit(buffer
->Background
, buffer
->Screen
,
393 buffer
->Width
, buffer
->Height
);