2012-07-26 20:47:31 +02:00
|
|
|
/*
|
|
|
|
* DIB driver OpenGL support
|
|
|
|
*
|
|
|
|
* Copyright 2012 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2020-11-05 10:41:12 +01:00
|
|
|
#if 0
|
|
|
|
#pragma makedep unix
|
|
|
|
#endif
|
|
|
|
|
2012-07-26 20:47:31 +02:00
|
|
|
#include "config.h"
|
2021-11-03 10:43:50 +01:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <dlfcn.h>
|
2012-07-26 20:47:31 +02:00
|
|
|
|
2020-11-05 10:41:12 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2021-07-09 15:28:26 +02:00
|
|
|
#include "ntgdi_private.h"
|
2012-07-26 20:47:31 +02:00
|
|
|
#include "dibdrv.h"
|
2020-11-05 10:41:12 +01:00
|
|
|
#include "wine/wgl.h"
|
|
|
|
#include "wine/wgl_driver.h"
|
|
|
|
|
|
|
|
#ifdef SONAME_LIBOSMESA
|
2012-07-26 20:47:31 +02:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dib);
|
|
|
|
|
2012-11-07 14:43:02 +01:00
|
|
|
#define OSMESA_COLOR_INDEX GL_COLOR_INDEX
|
|
|
|
#define OSMESA_RGBA GL_RGBA
|
|
|
|
#define OSMESA_BGRA 0x1
|
|
|
|
#define OSMESA_ARGB 0x2
|
|
|
|
#define OSMESA_RGB GL_RGB
|
|
|
|
#define OSMESA_BGR 0x4
|
|
|
|
#define OSMESA_RGB_565 0x5
|
|
|
|
#define OSMESA_ROW_LENGTH 0x10
|
|
|
|
#define OSMESA_Y_UP 0x11
|
|
|
|
|
|
|
|
typedef struct osmesa_context *OSMesaContext;
|
|
|
|
|
2012-07-26 20:47:31 +02:00
|
|
|
struct wgl_context
|
|
|
|
{
|
|
|
|
OSMesaContext context;
|
2020-11-05 10:41:12 +01:00
|
|
|
UINT format;
|
2012-07-26 20:47:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct opengl_funcs opengl_funcs;
|
|
|
|
|
|
|
|
#define USE_GL_FUNC(name) #name,
|
|
|
|
static const char *opengl_func_names[] = { ALL_WGL_FUNCS };
|
|
|
|
#undef USE_GL_FUNC
|
|
|
|
|
2012-11-07 14:43:02 +01:00
|
|
|
static OSMesaContext (*pOSMesaCreateContextExt)( GLenum format, GLint depthBits, GLint stencilBits,
|
|
|
|
GLint accumBits, OSMesaContext sharelist );
|
|
|
|
static void (*pOSMesaDestroyContext)( OSMesaContext ctx );
|
|
|
|
static void * (*pOSMesaGetProcAddress)( const char *funcName );
|
|
|
|
static GLboolean (*pOSMesaMakeCurrent)( OSMesaContext ctx, void *buffer, GLenum type,
|
|
|
|
GLsizei width, GLsizei height );
|
|
|
|
static void (*pOSMesaPixelStore)( GLint pname, GLint value );
|
2012-07-26 20:47:31 +02:00
|
|
|
|
|
|
|
static BOOL init_opengl(void)
|
|
|
|
{
|
2013-10-11 22:43:00 +02:00
|
|
|
static BOOL init_done = FALSE;
|
2012-07-26 20:47:31 +02:00
|
|
|
static void *osmesa_handle;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (init_done) return (osmesa_handle != NULL);
|
2013-10-11 22:43:00 +02:00
|
|
|
init_done = TRUE;
|
2012-07-26 20:47:31 +02:00
|
|
|
|
2020-04-06 11:46:10 +02:00
|
|
|
osmesa_handle = dlopen( SONAME_LIBOSMESA, RTLD_NOW );
|
2012-07-26 20:47:31 +02:00
|
|
|
if (osmesa_handle == NULL)
|
|
|
|
{
|
2020-04-06 11:46:10 +02:00
|
|
|
ERR( "Failed to load OSMesa: %s\n", dlerror() );
|
2012-07-26 20:47:31 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-04-06 11:46:10 +02:00
|
|
|
#define LOAD_FUNCPTR(f) do if (!(p##f = dlsym( osmesa_handle, #f ))) \
|
2012-07-26 20:47:31 +02:00
|
|
|
{ \
|
2020-04-06 11:46:10 +02:00
|
|
|
ERR( "%s not found in %s (%s), disabling.\n", #f, SONAME_LIBOSMESA, dlerror() ); \
|
2012-07-26 20:47:31 +02:00
|
|
|
goto failed; \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
LOAD_FUNCPTR(OSMesaCreateContextExt);
|
|
|
|
LOAD_FUNCPTR(OSMesaDestroyContext);
|
|
|
|
LOAD_FUNCPTR(OSMesaGetProcAddress);
|
|
|
|
LOAD_FUNCPTR(OSMesaMakeCurrent);
|
|
|
|
LOAD_FUNCPTR(OSMesaPixelStore);
|
|
|
|
#undef LOAD_FUNCPTR
|
|
|
|
|
2018-10-05 21:35:35 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE( opengl_func_names ); i++)
|
2017-04-24 01:20:15 +02:00
|
|
|
{
|
|
|
|
if (!(((void **)&opengl_funcs.gl)[i] = pOSMesaGetProcAddress( opengl_func_names[i] )))
|
|
|
|
{
|
|
|
|
ERR( "%s not found in %s, disabling.\n", opengl_func_names[i], SONAME_LIBOSMESA );
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-26 20:47:31 +02:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
failed:
|
2020-04-06 11:46:10 +02:00
|
|
|
dlclose( osmesa_handle );
|
2012-07-26 20:47:31 +02:00
|
|
|
osmesa_handle = NULL;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2020-11-05 10:41:12 +01:00
|
|
|
* osmesa_get_gl_funcs
|
2012-07-26 20:47:31 +02:00
|
|
|
*/
|
2021-10-15 16:53:50 +02:00
|
|
|
static void osmesa_get_gl_funcs( struct opengl_funcs *funcs )
|
2012-07-26 20:47:31 +02:00
|
|
|
{
|
2020-11-05 10:41:12 +01:00
|
|
|
funcs->gl = opengl_funcs.gl;
|
2012-07-26 20:47:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2020-11-05 10:41:12 +01:00
|
|
|
* osmesa_create_context
|
2012-07-26 20:47:31 +02:00
|
|
|
*/
|
2021-10-15 16:53:50 +02:00
|
|
|
static struct wgl_context * osmesa_create_context( HDC hdc, const PIXELFORMATDESCRIPTOR *descr )
|
2012-07-26 20:47:31 +02:00
|
|
|
{
|
|
|
|
struct wgl_context *context;
|
2020-11-05 10:41:12 +01:00
|
|
|
UINT gl_format;
|
2012-07-26 20:47:31 +02:00
|
|
|
|
2020-11-05 10:41:12 +01:00
|
|
|
switch (descr->cColorBits)
|
2012-07-26 20:47:31 +02:00
|
|
|
{
|
2020-11-05 10:41:12 +01:00
|
|
|
case 32:
|
|
|
|
if (descr->cRedShift == 8) gl_format = OSMESA_ARGB;
|
|
|
|
else if (descr->cRedShift == 16) gl_format = OSMESA_BGRA;
|
|
|
|
else gl_format = OSMESA_RGBA;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
gl_format = descr->cRedShift == 16 ? OSMESA_BGR : OSMESA_RGB;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
gl_format = OSMESA_RGB_565;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
2021-10-01 01:57:05 +02:00
|
|
|
if (!(context = malloc( sizeof( *context )))) return NULL;
|
2020-11-05 10:41:12 +01:00
|
|
|
context->format = gl_format;
|
|
|
|
if (!(context->context = pOSMesaCreateContextExt( gl_format, descr->cDepthBits, descr->cStencilBits,
|
|
|
|
descr->cAccumBits, 0 )))
|
|
|
|
{
|
2021-10-01 01:57:05 +02:00
|
|
|
free( context );
|
2012-07-26 20:47:31 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2020-11-05 10:41:12 +01:00
|
|
|
* osmesa_delete_context
|
2012-07-26 20:47:31 +02:00
|
|
|
*/
|
2021-10-15 16:53:50 +02:00
|
|
|
static BOOL osmesa_delete_context( struct wgl_context *context )
|
2012-07-26 20:47:31 +02:00
|
|
|
{
|
|
|
|
pOSMesaDestroyContext( context->context );
|
2021-10-01 01:57:05 +02:00
|
|
|
free( context );
|
2018-01-22 10:53:38 +01:00
|
|
|
return TRUE;
|
2012-07-26 20:47:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2020-11-05 10:41:12 +01:00
|
|
|
* osmesa_get_proc_address
|
2012-07-26 20:47:31 +02:00
|
|
|
*/
|
2021-10-15 16:53:50 +02:00
|
|
|
static PROC osmesa_get_proc_address( const char *proc )
|
2012-07-26 20:47:31 +02:00
|
|
|
{
|
|
|
|
return (PROC)pOSMesaGetProcAddress( proc );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2020-11-05 10:41:12 +01:00
|
|
|
* osmesa_make_current
|
2012-07-26 20:47:31 +02:00
|
|
|
*/
|
2021-10-15 16:53:50 +02:00
|
|
|
static BOOL osmesa_make_current( struct wgl_context *context, void *bits,
|
|
|
|
int width, int height, int bpp, int stride )
|
2012-07-26 20:47:31 +02:00
|
|
|
{
|
2020-11-05 10:41:12 +01:00
|
|
|
BOOL ret;
|
2015-02-03 11:07:38 +01:00
|
|
|
GLenum type;
|
2012-07-26 20:47:31 +02:00
|
|
|
|
|
|
|
if (!context)
|
|
|
|
{
|
|
|
|
pOSMesaMakeCurrent( NULL, NULL, GL_UNSIGNED_BYTE, 0, 0 );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-11-05 10:41:12 +01:00
|
|
|
type = context->format == OSMESA_RGB_565 ? GL_UNSIGNED_SHORT_5_6_5 : GL_UNSIGNED_BYTE;
|
|
|
|
ret = pOSMesaMakeCurrent( context->context, bits, type, width, height );
|
|
|
|
if (ret)
|
2012-07-26 20:47:31 +02:00
|
|
|
{
|
2020-11-05 10:41:12 +01:00
|
|
|
pOSMesaPixelStore( OSMESA_ROW_LENGTH, abs( stride ) * 8 / bpp );
|
|
|
|
pOSMesaPixelStore( OSMESA_Y_UP, 1 ); /* Windows seems to assume bottom-up */
|
2012-07-26 20:47:31 +02:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-11-05 10:41:12 +01:00
|
|
|
static const struct osmesa_funcs osmesa_funcs =
|
2012-07-30 21:53:37 +02:00
|
|
|
{
|
2020-11-05 10:41:12 +01:00
|
|
|
osmesa_get_gl_funcs,
|
|
|
|
osmesa_create_context,
|
|
|
|
osmesa_delete_context,
|
|
|
|
osmesa_get_proc_address,
|
|
|
|
osmesa_make_current
|
2012-07-26 20:47:31 +02:00
|
|
|
};
|
|
|
|
|
2021-09-29 14:09:21 +02:00
|
|
|
const struct osmesa_funcs *init_opengl_lib(void)
|
2012-07-26 20:47:31 +02:00
|
|
|
{
|
2021-09-29 14:09:21 +02:00
|
|
|
if (!init_opengl()) return NULL;
|
|
|
|
return &osmesa_funcs;
|
2012-07-26 20:47:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#else /* SONAME_LIBOSMESA */
|
|
|
|
|
2021-09-29 14:09:21 +02:00
|
|
|
const struct osmesa_funcs *init_opengl_lib(void)
|
2012-07-26 20:47:31 +02:00
|
|
|
{
|
2021-09-29 14:09:21 +02:00
|
|
|
return NULL;
|
2012-07-26 20:47:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* SONAME_LIBOSMESA */
|