2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 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 for Mesa
28 * Author: Daniel Borca
29 * Email : dborca@users.sourceforge.net
30 * Web : http://www.geocities.com/dborca
40 #include "GL/osmesa.h"
45 * This has nothing to do with Mesa Visual structure.
46 * We keep this one around for backwards compatibility,
47 * and to store video mode data for DMesaCreateContext.
50 GLenum format
; /* OSMesa framebuffer format */
57 * This has nothing to do with Mesa Buffer structure.
58 * We keep this one around for backwards compatibility,
59 * and to store various data.
62 int xpos
, ypos
; /* position */
63 int width
, height
; /* size in pixels */
65 void *the_window
; /* your window handle, etc */
69 * This has nothing to do with Mesa Context structure.
70 * We keep this one around for backwards compatibility,
71 * and to store real off-screen context.
73 struct dmesa_context
{
79 static DMesaContext ctx
;
82 /****************************************************************************
83 * DMesa Public API Functions
84 ***************************************************************************/
87 * The exact arguments to this function will depend on your window system
90 DMesaCreateVisual (GLint width
,
110 format
= OSMESA_COLOR_INDEX
;
112 } else if (alphaSize
) {
113 format
= OSMESA_BGRA
;
115 } else if (colDepth
== 15 || colDepth
== 16) {
116 format
= OSMESA_RGB_565
;
123 if ((visual
= (DMesaVisual
)CALLOC_STRUCT(dmesa_visual
)) == NULL
) {
127 if (vl_video_init(width
, height
, colDepth
, rgbFlag
, refresh
, fbbits
) <= 0) {
132 visual
->format
= format
;
133 visual
->depthBits
= depthSize
;
134 visual
->stencilBits
= stencilSize
;
135 visual
->accumBits
= accumSize
;
141 DMesaDestroyVisual (DMesaVisual visual
)
149 DMesaCreateBuffer (DMesaVisual visual
,
150 GLint xpos
, GLint ypos
,
151 GLint width
, GLint height
)
157 switch (visual
->format
) {
158 case OSMESA_COLOR_INDEX
:
164 type
= GL_UNSIGNED_SHORT_5_6_5
;
175 if ((buffer
= (DMesaBuffer
)CALLOC_STRUCT(dmesa_buffer
)) != NULL
) {
178 buffer
->width
= width
;
179 buffer
->height
= height
;
181 buffer
->the_window
= MALLOC(width
* height
* bytesPerPixel
+ 1);
182 if (buffer
->the_window
== NULL
) {
193 DMesaDestroyBuffer (DMesaBuffer buffer
)
195 FREE(buffer
->the_window
);
201 DMesaCreateContext (DMesaVisual visual
, DMesaContext share
)
204 if ((dmesa
= (DMesaContext
)CALLOC_STRUCT(dmesa_context
)) != NULL
) {
205 dmesa
->osmesa
= OSMesaCreateContextExt(
210 (share
!= NULL
) ? share
->osmesa
: NULL
);
211 if (dmesa
->osmesa
== NULL
) {
221 DMesaDestroyContext (DMesaContext dmesa
)
223 OSMesaDestroyContext(dmesa
->osmesa
);
229 DMesaMoveBuffer (GLint xpos
, GLint ypos
)
231 const DMesaContext dmesa
= DMesaGetCurrentContext();
232 DMesaBuffer b
= dmesa
->buffer
;
234 if (vl_sync_buffer(&b
->the_window
, xpos
, ypos
, b
->width
, b
->height
) == 0) {
245 DMesaResizeBuffer (GLint width
, GLint height
)
247 const DMesaContext dmesa
= DMesaGetCurrentContext();
248 DMesaBuffer b
= dmesa
->buffer
;
250 if (vl_sync_buffer(&b
->the_window
, b
->xpos
, b
->ypos
, width
, height
) == 0) {
261 DMesaMakeCurrent (DMesaContext dmesa
, DMesaBuffer buffer
)
263 if (dmesa
== NULL
|| buffer
== NULL
) {
267 if (OSMesaMakeCurrent(dmesa
->osmesa
, buffer
->the_window
,
269 buffer
->width
, buffer
->height
) &&
270 vl_sync_buffer(&buffer
->the_window
, buffer
->xpos
, buffer
->ypos
, buffer
->width
, buffer
->height
) == 0) {
271 OSMesaPixelStore(OSMESA_Y_UP
, GL_FALSE
);
272 dmesa
->buffer
= buffer
;
281 DMesaSwapBuffers (DMesaBuffer buffer
)
283 /* copy/swap back buffer to front if applicable */
284 GET_CURRENT_CONTEXT(ctx
);
285 _mesa_notifySwapBuffers(ctx
);
292 DMesaSetCI (int ndx
, GLfloat red
, GLfloat green
, GLfloat blue
)
294 vl_setCI(ndx
, red
, green
, blue
);
299 DMesaGetCurrentContext (void)
306 DMesaGetCurrentBuffer (void)
308 const DMesaContext dmesa
= DMesaGetCurrentContext();
311 return dmesa
->buffer
;
319 DMesaGetProcAddress (const char *name
)
321 DMesaProc p
= (DMesaProc
)_glapi_get_proc_address(name
);
323 /* TODO: handle DMesa* namespace
333 DMesaGetIntegerv (GLenum pname
, GLint
*params
)
336 case DMESA_GET_SCREEN_SIZE
:
337 vl_get(VL_GET_SCREEN_SIZE
, params
);
339 case DMESA_GET_DRIVER_CAPS
:
342 case DMESA_GET_VIDEO_MODES
:
343 return vl_get(VL_GET_VIDEO_MODES
, params
);
344 case DMESA_GET_BUFFER_ADDR
: {
345 const DMesaContext dmesa
= DMesaGetCurrentContext();
347 DMesaBuffer b
= dmesa
->buffer
;
349 params
[0] = (GLint
)b
->the_window
;