2004-02-02 05:36:37 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
|
|
|
* FILE: lib/opengl32/wgl.c
|
2004-02-06 17:22:55 +00:00
|
|
|
* PURPOSE: OpenGL32 lib, rosglXXX functions
|
2004-02-02 05:36:37 +00:00
|
|
|
* PROGRAMMER: Anich Gregor (blight)
|
|
|
|
* UPDATE HISTORY:
|
|
|
|
* Feb 2, 2004: Created
|
|
|
|
*/
|
|
|
|
|
2004-07-16 16:16:16 +00:00
|
|
|
#define OPENGL32_GL_FUNC_PROTOTYPES
|
2004-02-02 05:36:37 +00:00
|
|
|
#include "opengl32.h"
|
|
|
|
|
2004-02-06 18:17:18 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
2004-07-16 16:16:16 +00:00
|
|
|
#endif /* __cplusplus */
|
2004-02-06 18:17:18 +00:00
|
|
|
|
2004-07-16 16:16:16 +00:00
|
|
|
#if !defined(UNIMPLEMENTED)
|
|
|
|
# define UNIMPLEMENTED DBGPRINT( "UNIMPLEMENTED" )
|
|
|
|
#endif
|
2004-02-02 05:36:37 +00:00
|
|
|
|
2004-03-01 19:36:21 +00:00
|
|
|
|
2005-11-03 00:15:39 +00:00
|
|
|
typedef struct _OPENGL_INFO
|
2004-03-01 19:36:21 +00:00
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
DWORD Version; /*!< Driver interface version */
|
|
|
|
DWORD DriverVersion; /*!< Driver version */
|
|
|
|
WCHAR DriverName[256]; /*!< Driver name */
|
2005-11-03 00:15:39 +00:00
|
|
|
} OPENGL_INFO, *POPENGL_INFO;
|
2004-03-01 19:36:21 +00:00
|
|
|
|
2004-07-16 16:16:16 +00:00
|
|
|
/*! \brief Append OpenGL Rendering Context (GLRC) to list
|
|
|
|
*
|
|
|
|
* \param glrc [IN] Pointer to GLRC to append to list
|
2004-02-03 14:23:42 +00:00
|
|
|
*/
|
2004-02-06 18:17:18 +00:00
|
|
|
static
|
|
|
|
void
|
2004-03-01 19:36:21 +00:00
|
|
|
ROSGL_AppendContext( GLRC *glrc )
|
2004-02-03 14:23:42 +00:00
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
/* synchronize */
|
|
|
|
if (WaitForSingleObject( OPENGL32_processdata.glrc_mutex, INFINITE ) ==
|
|
|
|
WAIT_FAILED)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: WaitForSingleObject() failed (%d)", GetLastError() );
|
|
|
|
return; /* FIXME: do we have to expect such an error and handle it? */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OPENGL32_processdata.glrc_list == NULL)
|
|
|
|
OPENGL32_processdata.glrc_list = glrc;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GLRC *p = OPENGL32_processdata.glrc_list;
|
|
|
|
while (p->next != NULL)
|
|
|
|
p = p->next;
|
|
|
|
p->next = glrc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* release mutex */
|
|
|
|
if (!ReleaseMutex( OPENGL32_processdata.glrc_mutex ))
|
|
|
|
DBGPRINT( "Error: ReleaseMutex() failed (%d)", GetLastError() );
|
2004-02-03 14:23:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-16 16:16:16 +00:00
|
|
|
/*! \brief Remove OpenGL Rendering Context (GLRC) from list
|
|
|
|
*
|
|
|
|
* \param glrc [IN] Pointer to GLRC to remove from list
|
2004-02-03 14:23:42 +00:00
|
|
|
*/
|
2004-02-06 18:17:18 +00:00
|
|
|
static
|
|
|
|
void
|
2004-03-01 19:36:21 +00:00
|
|
|
ROSGL_RemoveContext( GLRC *glrc )
|
2004-02-02 05:36:37 +00:00
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
/* synchronize */
|
|
|
|
if (WaitForSingleObject( OPENGL32_processdata.glrc_mutex, INFINITE ) ==
|
|
|
|
WAIT_FAILED)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: WaitForSingleObject() failed (%d)", GetLastError() );
|
|
|
|
return; /* FIXME: do we have to expect such an error and handle it? */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (glrc == OPENGL32_processdata.glrc_list)
|
|
|
|
OPENGL32_processdata.glrc_list = glrc->next;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GLRC *p = OPENGL32_processdata.glrc_list;
|
|
|
|
while (p != NULL)
|
|
|
|
{
|
|
|
|
if (p->next == glrc)
|
|
|
|
{
|
|
|
|
p->next = glrc->next;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
if (p == NULL)
|
|
|
|
DBGPRINT( "Error: GLRC 0x%08x not found in list!", glrc );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* release mutex */
|
|
|
|
if (!ReleaseMutex( OPENGL32_processdata.glrc_mutex ))
|
|
|
|
DBGPRINT( "Error: ReleaseMutex() failed (%d)", GetLastError() );
|
2004-02-03 14:23:42 +00:00
|
|
|
}
|
|
|
|
|
2004-03-01 19:36:21 +00:00
|
|
|
|
2004-07-16 16:16:16 +00:00
|
|
|
/*! \brief Create a new GL Context (GLRC) and append it to the list
|
|
|
|
*
|
|
|
|
* \return Pointer to new GLRC on success
|
|
|
|
* \retval NULL Returned on failure (i.e. Out of memory)
|
2004-03-01 19:36:21 +00:00
|
|
|
*/
|
|
|
|
static
|
|
|
|
GLRC *
|
2007-11-15 00:13:57 +00:00
|
|
|
ROSGL_NewContext(void)
|
2004-03-01 19:36:21 +00:00
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
GLRC *glrc;
|
2004-03-01 19:36:21 +00:00
|
|
|
|
2009-01-05 11:03:28 +00:00
|
|
|
/* allocate GLRC */
|
|
|
|
glrc = (GLRC*)HeapAlloc( GetProcessHeap(),
|
|
|
|
HEAP_ZERO_MEMORY | HEAP_GENERATE_EXCEPTIONS, sizeof (GLRC) );
|
2004-03-01 19:36:21 +00:00
|
|
|
|
2009-01-05 11:03:28 +00:00
|
|
|
/* append to list */
|
|
|
|
ROSGL_AppendContext( glrc );
|
2004-03-01 19:36:21 +00:00
|
|
|
|
2009-01-05 11:03:28 +00:00
|
|
|
return glrc;
|
2004-03-01 19:36:21 +00:00
|
|
|
}
|
|
|
|
|
2007-11-15 00:13:57 +00:00
|
|
|
/*! \brief Delete all GLDCDATA with this IDC
|
|
|
|
*
|
|
|
|
* \param icd [IN] Pointer to a ICD
|
|
|
|
*/
|
|
|
|
static
|
|
|
|
VOID
|
|
|
|
ROSGL_DeleteDCDataForICD( GLDRIVERDATA *icd )
|
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
GLDCDATA *p, **pptr;
|
2012-08-24 16:28:09 +00:00
|
|
|
|
|
|
|
return;
|
2009-01-05 11:03:28 +00:00
|
|
|
|
|
|
|
/* synchronize */
|
|
|
|
if (WaitForSingleObject( OPENGL32_processdata.dcdata_mutex, INFINITE ) ==
|
|
|
|
WAIT_FAILED)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: WaitForSingleObject() failed (%d)", GetLastError() );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = OPENGL32_processdata.dcdata_list;
|
|
|
|
pptr = &OPENGL32_processdata.dcdata_list;
|
|
|
|
while (p != NULL)
|
|
|
|
{
|
|
|
|
if (p->icd == icd)
|
|
|
|
{
|
|
|
|
*pptr = p->next;
|
|
|
|
OPENGL32_UnloadICD( p->icd );
|
|
|
|
|
|
|
|
if (!HeapFree( GetProcessHeap(), 0, p ))
|
|
|
|
DBGPRINT( "Warning: HeapFree() on GLDCDATA failed (%d)",
|
|
|
|
GetLastError() );
|
|
|
|
|
|
|
|
p = *pptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pptr = &p->next;
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* release mutex */
|
|
|
|
if (!ReleaseMutex( OPENGL32_processdata.dcdata_mutex ))
|
|
|
|
DBGPRINT( "Error: ReleaseMutex() failed (%d)", GetLastError() );
|
2007-11-15 00:13:57 +00:00
|
|
|
}
|
|
|
|
|
2004-03-01 19:36:21 +00:00
|
|
|
|
2004-07-16 16:16:16 +00:00
|
|
|
/*! \brief Delete a GL Context (GLRC) and remove it from the list
|
|
|
|
*
|
|
|
|
* \param glrc [IN] Pointer to GLRC to delete
|
|
|
|
*
|
|
|
|
* \retval TRUE Success
|
|
|
|
* \retval FALSE Failure
|
2004-03-01 19:36:21 +00:00
|
|
|
*/
|
|
|
|
static
|
|
|
|
BOOL
|
|
|
|
ROSGL_DeleteContext( GLRC *glrc )
|
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
/* unload icd */
|
2010-06-14 13:11:51 +00:00
|
|
|
if ((glrc->icd != NULL) && (!InterlockedDecrement((LONG*)&glrc->icd->refcount)))
|
|
|
|
{
|
|
|
|
/* This is the last context, remove the ICD*/
|
2009-01-05 11:03:28 +00:00
|
|
|
ROSGL_DeleteDCDataForICD( glrc->icd );
|
2010-06-14 13:11:51 +00:00
|
|
|
}
|
2004-03-01 19:36:21 +00:00
|
|
|
|
2009-01-05 11:03:28 +00:00
|
|
|
/* remove from list */
|
|
|
|
ROSGL_RemoveContext( glrc );
|
2004-03-01 19:36:21 +00:00
|
|
|
|
2009-01-05 11:03:28 +00:00
|
|
|
/* free memory */
|
|
|
|
HeapFree( GetProcessHeap(), 0, glrc );
|
2004-03-01 19:36:21 +00:00
|
|
|
|
2009-01-05 11:03:28 +00:00
|
|
|
return TRUE;
|
2004-03-01 19:36:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-16 16:16:16 +00:00
|
|
|
/*! \brief Check wether a GLRC is in the list
|
|
|
|
*
|
|
|
|
* \param glrc [IN] Pointer to GLRC to look for in the list
|
|
|
|
*
|
|
|
|
* \retval TRUE GLRC was found
|
|
|
|
* \retval FALSE GLRC was not found
|
2004-02-03 14:23:42 +00:00
|
|
|
*/
|
2004-02-06 18:17:18 +00:00
|
|
|
static
|
|
|
|
BOOL
|
2004-03-01 19:36:21 +00:00
|
|
|
ROSGL_ContainsContext( GLRC *glrc )
|
2004-02-03 14:23:42 +00:00
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
GLRC *p;
|
|
|
|
BOOL found = FALSE;
|
|
|
|
|
|
|
|
/* synchronize */
|
|
|
|
if (WaitForSingleObject( OPENGL32_processdata.glrc_mutex, INFINITE ) ==
|
|
|
|
WAIT_FAILED)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: WaitForSingleObject() failed (%d)", GetLastError() );
|
|
|
|
return FALSE; /* FIXME: do we have to expect such an error and handle it? */
|
|
|
|
}
|
|
|
|
|
|
|
|
p = OPENGL32_processdata.glrc_list;
|
|
|
|
while (p != NULL)
|
|
|
|
{
|
|
|
|
if (p == glrc)
|
|
|
|
{
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* release mutex */
|
|
|
|
if (!ReleaseMutex( OPENGL32_processdata.glrc_mutex ))
|
|
|
|
DBGPRINT( "Error: ReleaseMutex() failed (%d)", GetLastError() );
|
|
|
|
|
|
|
|
return found;
|
2004-02-02 05:36:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-16 16:16:16 +00:00
|
|
|
/*! \brief Get GL private DC data.
|
|
|
|
*
|
|
|
|
* This function adds an empty GLDCDATA to the list if there is no data for the
|
|
|
|
* given DC yet.
|
|
|
|
*
|
|
|
|
* \param hdc [IN] Handle to a Device Context for which to get the data
|
|
|
|
*
|
|
|
|
* \return Pointer to GLDCDATA on success
|
|
|
|
* \retval NULL on failure
|
2004-03-01 19:36:21 +00:00
|
|
|
*/
|
|
|
|
static
|
|
|
|
GLDCDATA *
|
|
|
|
ROSGL_GetPrivateDCData( HDC hdc )
|
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
GLDCDATA *data;
|
2012-07-12 14:06:34 +00:00
|
|
|
HANDLE handle;
|
2009-01-05 11:03:28 +00:00
|
|
|
|
|
|
|
/* check hdc */
|
|
|
|
if (GetObjectType( hdc ) != OBJ_DC && GetObjectType( hdc ) != OBJ_MEMDC)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: hdc is not a DC handle!" );
|
|
|
|
SetLastError( ERROR_INVALID_HANDLE );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* synchronize */
|
|
|
|
if (WaitForSingleObject( OPENGL32_processdata.dcdata_mutex, INFINITE ) ==
|
|
|
|
WAIT_FAILED)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: WaitForSingleObject() failed (%d)", GetLastError() );
|
|
|
|
return NULL; /* FIXME: do we have to expect such an error and handle it? */
|
|
|
|
}
|
|
|
|
|
2012-07-12 14:06:34 +00:00
|
|
|
/* We must use the window to identify our data, as pixel format is
|
|
|
|
* specific to a window for device context */
|
|
|
|
handle = WindowFromDC(hdc);
|
|
|
|
if(!handle)
|
|
|
|
handle = hdc;
|
|
|
|
|
2009-01-05 11:03:28 +00:00
|
|
|
/* look for data in list */
|
|
|
|
data = OPENGL32_processdata.dcdata_list;
|
|
|
|
while (data != NULL)
|
|
|
|
{
|
2012-07-12 14:06:34 +00:00
|
|
|
if (data->handle == handle) /* found */
|
2009-01-05 11:03:28 +00:00
|
|
|
break;
|
|
|
|
data = data->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate new data if not found in list */
|
|
|
|
if (data == NULL)
|
|
|
|
{
|
|
|
|
data = HeapAlloc( GetProcessHeap(),
|
|
|
|
HEAP_ZERO_MEMORY | HEAP_GENERATE_EXCEPTIONS,
|
|
|
|
sizeof (GLDCDATA) );
|
|
|
|
if (data == NULL)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: HeapAlloc() failed (%d)", GetLastError() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-12 14:06:34 +00:00
|
|
|
data->handle = handle;
|
2009-01-05 11:03:28 +00:00
|
|
|
|
|
|
|
/* append data to list */
|
|
|
|
if (OPENGL32_processdata.dcdata_list == NULL)
|
|
|
|
OPENGL32_processdata.dcdata_list = data;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GLDCDATA *p = OPENGL32_processdata.dcdata_list;
|
|
|
|
while (p->next != NULL)
|
|
|
|
p = p->next;
|
|
|
|
p->next = data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* release mutex */
|
|
|
|
if (!ReleaseMutex( OPENGL32_processdata.dcdata_mutex ))
|
|
|
|
DBGPRINT( "Error: ReleaseMutex() failed (%d)", GetLastError() );
|
|
|
|
|
|
|
|
return data;
|
2004-03-01 19:36:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-16 16:16:16 +00:00
|
|
|
/*! \brief Get ICD from HDC.
|
|
|
|
*
|
|
|
|
* This function asks the display driver which OpenGL ICD to load for the given
|
|
|
|
* HDC, loads it and returns a pointer to a GLDRIVERDATA struct on success.
|
|
|
|
*
|
|
|
|
* \param hdc [IN] Handle for DC for which to load/get the ICD
|
|
|
|
*
|
|
|
|
* \return Pointer to GLDRIVERDATA
|
|
|
|
* \retval NULL Failure.
|
2004-03-01 19:36:21 +00:00
|
|
|
*/
|
|
|
|
static
|
|
|
|
GLDRIVERDATA *
|
|
|
|
ROSGL_ICDForHDC( HDC hdc )
|
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
GLDCDATA *dcdata;
|
|
|
|
GLDRIVERDATA *drvdata;
|
|
|
|
|
|
|
|
dcdata = ROSGL_GetPrivateDCData( hdc );
|
|
|
|
if (dcdata == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (dcdata->icd == NULL)
|
|
|
|
{
|
|
|
|
LPCWSTR driverName;
|
|
|
|
OPENGL_INFO info;
|
|
|
|
|
|
|
|
/* NOTE: This might be done by multiple threads simultaneously, but only the fastest
|
|
|
|
actually gets to set the ICD! */
|
|
|
|
|
|
|
|
driverName = _wgetenv( L"OPENGL32_DRIVER" );
|
|
|
|
if (driverName == NULL)
|
|
|
|
{
|
|
|
|
DWORD dwInput;
|
|
|
|
LONG ret;
|
|
|
|
|
|
|
|
/* get driver name */
|
|
|
|
dwInput = OPENGL_GETINFO;
|
|
|
|
ret = ExtEscape( hdc, QUERYESCSUPPORT, sizeof (dwInput), (LPCSTR)&dwInput, 0, NULL );
|
|
|
|
if (ret > 0)
|
|
|
|
{
|
|
|
|
dwInput = 0;
|
|
|
|
ret = ExtEscape( hdc, OPENGL_GETINFO, sizeof (dwInput),
|
|
|
|
(LPCSTR)&dwInput, sizeof (OPENGL_INFO),
|
|
|
|
(LPSTR)&info );
|
|
|
|
}
|
|
|
|
if (ret <= 0)
|
|
|
|
{
|
|
|
|
HKEY hKey;
|
|
|
|
DWORD type, size;
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Warning: ExtEscape to get the drivername failed! (%d)", GetLastError() );
|
|
|
|
if (MessageBox( WindowFromDC( hdc ), L"Couldn't get installable client driver name!\nUsing default driver.",
|
|
|
|
L"OPENGL32.dll: Warning", MB_OKCANCEL | MB_ICONWARNING ) == IDCANCEL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* open registry key */
|
|
|
|
ret = RegOpenKeyExW( HKEY_LOCAL_MACHINE, OPENGL_DRIVERS_SUBKEY, 0, KEY_QUERY_VALUE, &hKey );
|
|
|
|
if (ret != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: Couldn't open registry key '%ws'", OPENGL_DRIVERS_SUBKEY );
|
|
|
|
SetLastError( ret );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* query value */
|
|
|
|
size = sizeof (info.DriverName);
|
|
|
|
ret = RegQueryValueExW( hKey, L"DefaultDriver", 0, &type, (LPBYTE)info.DriverName, &size );
|
|
|
|
RegCloseKey( hKey );
|
|
|
|
if (ret != ERROR_SUCCESS || type != REG_SZ)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: Couldn't query DefaultDriver value or not a string" );
|
|
|
|
SetLastError( ret );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wcsncpy( info.DriverName, driverName, sizeof (info.DriverName) / sizeof (info.DriverName[0]) );
|
|
|
|
}
|
|
|
|
/* load driver (or get a reference) */
|
|
|
|
drvdata = OPENGL32_LoadICD( info.DriverName );
|
|
|
|
if (drvdata == NULL)
|
|
|
|
{
|
|
|
|
WCHAR Buffer[256];
|
|
|
|
snwprintf(Buffer, sizeof(Buffer)/sizeof(WCHAR),
|
2009-05-31 21:54:34 +00:00
|
|
|
L"Couldn't load driver \"%s\".", info.DriverName);
|
2009-01-05 11:03:28 +00:00
|
|
|
MessageBox(WindowFromDC( hdc ), Buffer,
|
|
|
|
L"OPENGL32.dll: Warning",
|
|
|
|
MB_OK | MB_ICONWARNING);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Atomically set the ICD!!! */
|
|
|
|
if (InterlockedCompareExchangePointer((PVOID*)&dcdata->icd,
|
|
|
|
(PVOID)drvdata,
|
|
|
|
NULL) != NULL)
|
|
|
|
{
|
|
|
|
/* Too bad, somebody else was faster... */
|
2010-06-14 13:11:51 +00:00
|
|
|
DBGTRACE("ICD is already set!\n");
|
2009-01-05 11:03:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dcdata->icd;
|
2004-03-01 19:36:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-16 16:16:16 +00:00
|
|
|
/*! \brief SetContextCallBack passed to DrvSetContext.
|
|
|
|
*
|
|
|
|
* This function gets called by the OpenGL driver whenever the current GL
|
|
|
|
* context (dispatch table) is to be changed.
|
|
|
|
*
|
|
|
|
* \param table [IN] Function pointer table (first DWORD is number of functions)
|
|
|
|
*
|
|
|
|
* \return unkown (maybe void? ERROR_SUCCESS at the moment)
|
2004-02-05 04:28:11 +00:00
|
|
|
*/
|
2004-02-06 18:17:18 +00:00
|
|
|
DWORD
|
|
|
|
CALLBACK
|
2004-03-01 19:36:21 +00:00
|
|
|
ROSGL_SetContextCallBack( const ICDTable *table )
|
2004-02-05 04:28:11 +00:00
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
TEB *teb;
|
|
|
|
PROC *tebTable, *tebDispatchTable;
|
|
|
|
INT size;
|
|
|
|
|
|
|
|
teb = NtCurrentTeb();
|
|
|
|
tebTable = (PROC *)teb->glTable;
|
|
|
|
tebDispatchTable = (PROC *)teb->glDispatchTable;
|
|
|
|
|
|
|
|
DBGTRACE( "Called!" );
|
|
|
|
|
|
|
|
if (table != NULL)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Function count: %d\n", table->num_funcs );
|
|
|
|
|
|
|
|
/* save table */
|
|
|
|
size = sizeof (PROC) * table->num_funcs;
|
|
|
|
memcpy( tebTable, table->dispatch_table, size );
|
2011-03-11 18:17:34 +00:00
|
|
|
memset( tebTable + table->num_funcs, 0, DISPATCH_TABLE_SIZE - size );
|
2009-01-05 11:03:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBGPRINT( "Unsetting current context" );
|
2011-03-11 18:17:34 +00:00
|
|
|
memset( tebTable, 0, DISPATCH_TABLE_SIZE );
|
2009-01-05 11:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* put in empty functions as long as we dont have a fallback */
|
|
|
|
#define X(func, ret, typeargs, args, icdidx, tebidx, stack) \
|
|
|
|
if (tebTable[icdidx] == NULL) \
|
|
|
|
{ \
|
|
|
|
if (table != NULL) \
|
|
|
|
DBGPRINT( "Warning: GL proc '%s' is NULL", #func ); \
|
|
|
|
tebTable[icdidx] = (PROC)glEmptyFunc##stack; \
|
|
|
|
}
|
|
|
|
GLFUNCS_MACRO
|
|
|
|
#undef X
|
|
|
|
|
|
|
|
/* fill teb->glDispatchTable for fast calls */
|
|
|
|
#define X(func, ret, typeargs, args, icdidx, tebidx, stack) \
|
|
|
|
if (tebidx >= 0) \
|
|
|
|
tebDispatchTable[tebidx] = tebTable[icdidx];
|
|
|
|
GLFUNCS_MACRO
|
|
|
|
#undef X
|
|
|
|
|
|
|
|
DBGPRINT( "Done." );
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
2004-02-05 04:28:11 +00:00
|
|
|
}
|
2004-02-03 14:23:42 +00:00
|
|
|
|
|
|
|
|
2012-07-12 00:34:09 +00:00
|
|
|
/*! \brief Returns the current pixelformat.
|
|
|
|
*
|
|
|
|
* \param hdc [IN] Handle to DC to get the pixelformat from
|
|
|
|
*
|
|
|
|
* \return Pixelformat index
|
|
|
|
* \retval 0 Failure
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
WINAPI
|
|
|
|
rosglGetPixelFormat( HDC hdc )
|
|
|
|
{
|
|
|
|
GLDCDATA *dcdata;
|
|
|
|
|
|
|
|
DBGTRACE( "Called!" );
|
|
|
|
|
|
|
|
dcdata = ROSGL_GetPrivateDCData( hdc );
|
|
|
|
if (dcdata == NULL)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: ROSGL_GetPrivateDCData failed!" );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dcdata->pixel_format;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-16 16:16:16 +00:00
|
|
|
/*! \brief Attempts to find the best matching pixel format for HDC
|
|
|
|
*
|
|
|
|
* This function is comparing each available format with the preferred one
|
|
|
|
* and returns the one which is closest to it.
|
|
|
|
* If PFD_DOUBLEBUFFER, PFD_STEREO or one of PFD_DRAW_TO_WINDOW,
|
|
|
|
* PFD_DRAW_TO_BITMAP, PFD_SUPPORT_GDI and PDF_SUPPORT_OPENGL is given then
|
|
|
|
* only formats which also support those will be enumerated (unless
|
|
|
|
* PFD_DOUBLEBUFFER_DONTCARE or PFD_STEREO_DONTCARE is also set)
|
|
|
|
*
|
|
|
|
* \param hdc [IN] Handle to DC for which to get a pixel format index
|
|
|
|
* \param pfd [IN] PFD describing what kind of format you want
|
|
|
|
*
|
|
|
|
* \return Pixel format index
|
|
|
|
* \retval 0 Failed to find a suitable format
|
2004-02-06 20:31:15 +00:00
|
|
|
*/
|
|
|
|
#define BUFFERDEPTH_SCORE(want, have) \
|
2009-01-05 11:03:28 +00:00
|
|
|
((want == 0) ? (0) : ((want < have) ? (1) : ((want > have) ? (3) : (0))))
|
2009-05-25 10:50:03 +00:00
|
|
|
|
|
|
|
/* Score if we want and not have it */
|
|
|
|
#define FLAG_SCORE(want, have, flag) \
|
|
|
|
(((want & ~have) & flag) ? (1) : (0))
|
|
|
|
|
|
|
|
/* Score if what we want is different than what we have, except when
|
|
|
|
_DONTCARE was set */
|
|
|
|
#define FLAG_SCORE_DONTCARE(want, have, flag) \
|
|
|
|
((!(have & flag ## _DONTCARE)) && ((want & flag) != (have & flag)) ? (1) : (0))
|
|
|
|
|
2004-02-06 18:17:18 +00:00
|
|
|
int
|
|
|
|
APIENTRY
|
|
|
|
rosglChoosePixelFormat( HDC hdc, CONST PIXELFORMATDESCRIPTOR *pfd )
|
2004-02-06 13:59:13 +00:00
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
GLDRIVERDATA *icd;
|
|
|
|
PIXELFORMATDESCRIPTOR icdPfd;
|
|
|
|
int i;
|
|
|
|
int best = 0;
|
|
|
|
int score, bestScore = 0x7fff; /* used to choose a pfd if no exact match */
|
|
|
|
int icdNumFormats;
|
|
|
|
|
|
|
|
DBGTRACE( "Called!" );
|
|
|
|
|
|
|
|
/* load ICD */
|
|
|
|
icd = ROSGL_ICDForHDC( hdc );
|
|
|
|
if (icd == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* check input */
|
|
|
|
if (pfd->nSize != sizeof (PIXELFORMATDESCRIPTOR) || pfd->nVersion != 1)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get number of formats */
|
|
|
|
icdNumFormats = icd->DrvDescribePixelFormat( hdc, 1,
|
|
|
|
sizeof (PIXELFORMATDESCRIPTOR), &icdPfd );
|
|
|
|
if (icdNumFormats == 0)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: DrvDescribePixelFormat failed (%d)", GetLastError() );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DBGPRINT( "Info: Enumerating %d pixelformats", icdNumFormats );
|
|
|
|
|
|
|
|
/* try to find best format */
|
|
|
|
for (i = 0; i < icdNumFormats; i++)
|
|
|
|
{
|
|
|
|
if (icd->DrvDescribePixelFormat( hdc, i + 1,
|
|
|
|
sizeof (PIXELFORMATDESCRIPTOR), &icdPfd ) == 0)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Warning: DrvDescribePixelFormat failed (%d)",
|
|
|
|
GetLastError() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((pfd->dwFlags & PFD_GENERIC_ACCELERATED) != 0) /* we do not support such kind of drivers */
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-05-25 10:50:03 +00:00
|
|
|
score = 0; /* higher is worse */
|
|
|
|
|
2009-01-05 11:03:28 +00:00
|
|
|
/* compare flags */
|
2009-05-25 10:50:03 +00:00
|
|
|
score += FLAG_SCORE(pfd->dwFlags, icdPfd.dwFlags, PFD_DRAW_TO_WINDOW);
|
|
|
|
score += FLAG_SCORE(pfd->dwFlags, icdPfd.dwFlags, PFD_DRAW_TO_BITMAP);
|
|
|
|
score += FLAG_SCORE(pfd->dwFlags, icdPfd.dwFlags, PFD_SUPPORT_GDI);
|
|
|
|
score += FLAG_SCORE(pfd->dwFlags, icdPfd.dwFlags, PFD_SUPPORT_OPENGL);
|
|
|
|
score += FLAG_SCORE_DONTCARE(pfd->dwFlags, icdPfd.dwFlags, PFD_DOUBLEBUFFER);
|
|
|
|
score += FLAG_SCORE_DONTCARE(pfd->dwFlags, icdPfd.dwFlags, PFD_STEREO);
|
2009-01-05 11:03:28 +00:00
|
|
|
|
|
|
|
/* check other attribs */
|
|
|
|
if (pfd->iPixelType != icdPfd.iPixelType)
|
|
|
|
score += 5; /* this is really bad i think */
|
|
|
|
if (pfd->iLayerType != icdPfd.iLayerType)
|
|
|
|
score += 15; /* this is very very bad ;) */
|
|
|
|
|
|
|
|
score += BUFFERDEPTH_SCORE(pfd->cAlphaBits, icdPfd.cAlphaBits);
|
|
|
|
score += BUFFERDEPTH_SCORE(pfd->cAccumBits, icdPfd.cAccumBits);
|
|
|
|
score += BUFFERDEPTH_SCORE(pfd->cDepthBits, icdPfd.cDepthBits);
|
|
|
|
score += BUFFERDEPTH_SCORE(pfd->cStencilBits, icdPfd.cStencilBits);
|
|
|
|
score += BUFFERDEPTH_SCORE(pfd->cAuxBuffers, icdPfd.cAuxBuffers);
|
|
|
|
|
|
|
|
/* check score */
|
|
|
|
if (score < bestScore)
|
|
|
|
{
|
|
|
|
bestScore = score;
|
|
|
|
best = i + 1;
|
|
|
|
if (bestScore == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (best == 0)
|
|
|
|
SetLastError( 0 ); /* FIXME: set appropriate error */
|
|
|
|
|
|
|
|
DBGPRINT( "Info: Suggesting pixelformat %d", best );
|
|
|
|
return best;
|
2004-02-06 13:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-16 16:16:16 +00:00
|
|
|
/*! \brief Copy data specified by mask from one GLRC to another.
|
|
|
|
*
|
|
|
|
* \param src [IN] Source GLRC
|
|
|
|
* \param src [OUT] Destination GLRC
|
|
|
|
* \param mask [IN] Bitfield like given to glPushAttrib()
|
|
|
|
*
|
|
|
|
* \retval TRUE Success
|
|
|
|
* \retval FALSE Failure
|
2004-02-03 14:23:42 +00:00
|
|
|
*/
|
2004-02-06 18:17:18 +00:00
|
|
|
BOOL
|
|
|
|
APIENTRY
|
|
|
|
rosglCopyContext( HGLRC hsrc, HGLRC hdst, UINT mask )
|
2004-02-03 14:23:42 +00:00
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
GLRC *src = (GLRC *)hsrc;
|
|
|
|
GLRC *dst = (GLRC *)hdst;
|
|
|
|
|
|
|
|
/* check glrcs */
|
|
|
|
if (!ROSGL_ContainsContext( src ))
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: src GLRC not found!" );
|
|
|
|
SetLastError( ERROR_INVALID_HANDLE );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!ROSGL_ContainsContext( dst ))
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: dst GLRC not found!" );
|
|
|
|
SetLastError( ERROR_INVALID_HANDLE );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* I think this is only possible within one ICD */
|
|
|
|
if (src->icd != dst->icd)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: src and dst GLRC use different ICDs!" );
|
|
|
|
SetLastError( ERROR_INVALID_HANDLE );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy data (call ICD) */
|
|
|
|
return src->icd->DrvCopyContext( src->hglrc, dst->hglrc, mask );
|
2004-02-03 14:23:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-16 16:16:16 +00:00
|
|
|
/*! \brief Create a new GL Rendering Context.
|
|
|
|
*
|
|
|
|
* This function can create over- or underlay surfaces.
|
|
|
|
*
|
|
|
|
* \param hdc [IN] Handle for DC for which to create context
|
|
|
|
* \param layer [IN] Layer number to bind (draw?) to
|
|
|
|
*
|
|
|
|
* \return Handle for the created GLRC
|
|
|
|
* \retval NULL Failure
|
2004-02-03 14:23:42 +00:00
|
|
|
*/
|
2004-02-06 18:17:18 +00:00
|
|
|
HGLRC
|
|
|
|
APIENTRY
|
|
|
|
rosglCreateLayerContext( HDC hdc, int layer )
|
2004-02-02 05:36:37 +00:00
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
GLDRIVERDATA *icd = NULL;
|
|
|
|
GLRC *glrc;
|
|
|
|
HGLRC drvHglrc = NULL;
|
2004-02-02 05:36:37 +00:00
|
|
|
|
2009-01-05 11:03:28 +00:00
|
|
|
DBGTRACE( "Called!" );
|
2004-07-16 16:16:16 +00:00
|
|
|
|
2004-02-09 08:00:15 +00:00
|
|
|
/* if (GetObjectType( hdc ) != OBJ_DC)
|
2009-01-05 11:03:28 +00:00
|
|
|
{
|
|
|
|
DBGPRINT( "Error: hdc is not a DC handle!" );
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-02-09 08:00:15 +00:00
|
|
|
*/
|
2009-01-05 11:03:28 +00:00
|
|
|
|
|
|
|
/* load ICD */
|
|
|
|
icd = ROSGL_ICDForHDC( hdc );
|
|
|
|
if (icd == NULL)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Couldn't get ICD by HDC :-(" );
|
|
|
|
/* FIXME: fallback? */
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-07-12 00:34:09 +00:00
|
|
|
|
|
|
|
/* create new GLRC */
|
|
|
|
glrc = ROSGL_NewContext();
|
|
|
|
if (glrc == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2010-06-14 13:11:51 +00:00
|
|
|
/* Don't forget to refcount it, icd will be released when last context is deleted */
|
|
|
|
InterlockedIncrement((LONG*)&icd->refcount);
|
2012-07-12 00:34:09 +00:00
|
|
|
|
|
|
|
/* You can't create a context without first setting a valid pixel format */
|
|
|
|
if(rosglGetPixelFormat(hdc) == 0)
|
|
|
|
{
|
|
|
|
ROSGL_DeleteContext( glrc );
|
|
|
|
SetLastError(ERROR_INVALID_PIXEL_FORMAT);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-01-05 11:03:28 +00:00
|
|
|
|
|
|
|
/* create context */
|
|
|
|
if (icd->DrvCreateLayerContext != NULL)
|
|
|
|
drvHglrc = icd->DrvCreateLayerContext( hdc, layer );
|
|
|
|
if (drvHglrc == NULL)
|
|
|
|
{
|
|
|
|
if (layer == 0 && icd->DrvCreateContext != NULL)
|
|
|
|
drvHglrc = icd->DrvCreateContext( hdc );
|
|
|
|
else
|
|
|
|
DBGPRINT( "Warning: CreateLayerContext not supported by ICD!" );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drvHglrc == NULL)
|
|
|
|
{
|
|
|
|
/* FIXME: fallback to mesa? */
|
|
|
|
DBGPRINT( "Error: DrvCreate[Layer]Context failed! (%d)", GetLastError() );
|
|
|
|
ROSGL_DeleteContext( glrc );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we have our GLRC in glrc and the ICD's GLRC in drvHglrc */
|
|
|
|
glrc->hglrc = drvHglrc;
|
|
|
|
glrc->icd = icd;
|
|
|
|
|
|
|
|
return (HGLRC)glrc;
|
2004-02-02 05:36:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-16 16:16:16 +00:00
|
|
|
/*! \brief Create a new GL Rendering Context.
|
|
|
|
*
|
|
|
|
* \param hdc [IN] Handle for DC for which to create context
|
|
|
|
*
|
|
|
|
* \return Handle for the created GLRC
|
|
|
|
* \retval NULL Failure
|
2004-02-06 18:17:18 +00:00
|
|
|
*/
|
|
|
|
HGLRC
|
|
|
|
APIENTRY
|
|
|
|
rosglCreateContext( HDC hdc )
|
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
return rosglCreateLayerContext( hdc, 0 );
|
2004-02-06 18:17:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-16 16:16:16 +00:00
|
|
|
/*! \brief Delete an OpenGL context
|
|
|
|
*
|
2012-07-12 00:34:09 +00:00
|
|
|
* \param hglrc [IN] Handle to GLRC to delete;
|
2004-07-16 16:16:16 +00:00
|
|
|
*
|
|
|
|
* \retval TRUE Success
|
|
|
|
* \retval FALSE Failure (i.e. GLRC is current for a thread)
|
2004-02-03 14:23:42 +00:00
|
|
|
*/
|
2004-02-06 18:17:18 +00:00
|
|
|
BOOL
|
|
|
|
APIENTRY
|
|
|
|
rosglDeleteContext( HGLRC hglrc )
|
2004-02-02 05:36:37 +00:00
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
GLRC *glrc = (GLRC *)hglrc;
|
|
|
|
|
|
|
|
/* check if we know about this context */
|
|
|
|
if (!ROSGL_ContainsContext( glrc ))
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: hglrc not found!" );
|
|
|
|
SetLastError( ERROR_INVALID_HANDLE );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-07-12 00:34:09 +00:00
|
|
|
/* On windows, this is allowed to delete a context which is current */
|
2009-01-05 11:03:28 +00:00
|
|
|
if (glrc->is_current)
|
|
|
|
{
|
2012-07-12 00:34:09 +00:00
|
|
|
/* But only for its own thread */
|
|
|
|
if(glrc->thread_id != GetCurrentThreadId())
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: GLRC is current for DC 0x%08x", glrc->hdc );
|
|
|
|
SetLastError( ERROR_INVALID_FUNCTION );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/* Unset it before going further */
|
2012-07-19 21:55:56 +00:00
|
|
|
rosglMakeCurrent(NULL, NULL);
|
2009-01-05 11:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* release ICD's context */
|
|
|
|
if (glrc->hglrc != NULL)
|
|
|
|
{
|
|
|
|
if (!glrc->icd->DrvDeleteContext( glrc->hglrc ))
|
|
|
|
{
|
|
|
|
DBGPRINT( "Warning: DrvDeleteContext() failed (%d)", GetLastError() );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free resources */
|
|
|
|
return ROSGL_DeleteContext( glrc );
|
2004-02-02 05:36:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-06 18:17:18 +00:00
|
|
|
BOOL
|
|
|
|
APIENTRY
|
|
|
|
rosglDescribeLayerPlane( HDC hdc, int iPixelFormat, int iLayerPlane,
|
2004-03-01 19:36:21 +00:00
|
|
|
UINT nBytes, LPLAYERPLANEDESCRIPTOR plpd )
|
2004-02-02 05:36:37 +00:00
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
UNIMPLEMENTED;
|
|
|
|
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
|
|
|
|
return FALSE;
|
2004-02-06 13:59:13 +00:00
|
|
|
}
|
2004-02-03 14:23:42 +00:00
|
|
|
|
|
|
|
|
2004-07-16 16:16:16 +00:00
|
|
|
/*! \brief Gets information about a pixelformat.
|
|
|
|
*
|
|
|
|
* \param hdc [IN] Handle to DC
|
|
|
|
* \param iFormat [IN] Pixelformat index
|
|
|
|
* \param nBytes [IN] sizeof (pfd) - at most nBytes are copied into pfd
|
|
|
|
* \param pfd [OUT] Pointer to a PIXELFORMATDESCRIPTOR
|
|
|
|
*
|
|
|
|
* \return Maximum pixelformat index/number of formats
|
|
|
|
* \retval 0 Failure
|
2004-03-01 19:36:21 +00:00
|
|
|
*/
|
2004-02-06 18:17:18 +00:00
|
|
|
int
|
|
|
|
APIENTRY
|
|
|
|
rosglDescribePixelFormat( HDC hdc, int iFormat, UINT nBytes,
|
2004-03-01 19:36:21 +00:00
|
|
|
LPPIXELFORMATDESCRIPTOR pfd )
|
2004-02-06 13:59:13 +00:00
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
int ret = 0;
|
|
|
|
GLDRIVERDATA *icd = ROSGL_ICDForHDC( hdc );
|
|
|
|
|
|
|
|
if (icd != NULL)
|
|
|
|
{
|
|
|
|
ret = icd->DrvDescribePixelFormat( hdc, iFormat, nBytes, pfd );
|
|
|
|
if (ret == 0)
|
|
|
|
DBGPRINT( "Error: DrvDescribePixelFormat(format=%d) failed (%d)", iFormat, GetLastError() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_FUNCTION );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2004-02-02 05:36:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-16 16:16:16 +00:00
|
|
|
/*! \brief Return the thread's current GLRC
|
|
|
|
*
|
|
|
|
* \return Handle for thread's current GLRC
|
|
|
|
* \retval NULL No current GLRC set
|
2004-02-03 14:23:42 +00:00
|
|
|
*/
|
2004-02-06 18:17:18 +00:00
|
|
|
HGLRC
|
|
|
|
APIENTRY
|
|
|
|
rosglGetCurrentContext()
|
2004-02-02 05:36:37 +00:00
|
|
|
{
|
2012-07-12 11:39:23 +00:00
|
|
|
return NtCurrentTeb()->glCurrentRC;
|
2004-02-02 05:36:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-16 16:16:16 +00:00
|
|
|
/*! \brief Return the thread's current DC
|
|
|
|
*
|
|
|
|
* \return Handle for thread's current DC
|
|
|
|
* \retval NULL No current DC/GLRC set
|
2004-02-03 14:23:42 +00:00
|
|
|
*/
|
2004-02-06 18:17:18 +00:00
|
|
|
HDC
|
|
|
|
APIENTRY
|
|
|
|
rosglGetCurrentDC()
|
2004-02-02 05:36:37 +00:00
|
|
|
{
|
2012-07-12 11:39:23 +00:00
|
|
|
GLRC* glrc = (GLRC*)NtCurrentTeb()->glCurrentRC;
|
|
|
|
if(glrc) return glrc->hdc;
|
|
|
|
return NULL;
|
2004-02-02 05:36:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-06 18:17:18 +00:00
|
|
|
int
|
|
|
|
APIENTRY
|
|
|
|
rosglGetLayerPaletteEntries( HDC hdc, int iLayerPlane, int iStart,
|
2004-03-01 19:36:21 +00:00
|
|
|
int cEntries, COLORREF *pcr )
|
2004-02-02 05:36:37 +00:00
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
UNIMPLEMENTED;
|
|
|
|
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
|
|
|
|
return 0;
|
2004-02-06 13:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-16 16:16:16 +00:00
|
|
|
/*! \brief Get the address for an OpenGL extension function.
|
|
|
|
*
|
|
|
|
* The addresses this function returns are only valid within the same thread
|
|
|
|
* which it was called from.
|
|
|
|
*
|
|
|
|
* \param proc [IN] Name of the function to look for
|
|
|
|
*
|
|
|
|
* \return The address of the proc
|
|
|
|
* \retval NULL Failure
|
2004-02-03 14:23:42 +00:00
|
|
|
*/
|
2004-02-06 18:17:18 +00:00
|
|
|
PROC
|
|
|
|
APIENTRY
|
|
|
|
rosglGetProcAddress( LPCSTR proc )
|
2004-02-02 05:36:37 +00:00
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
PROC func;
|
2012-07-12 11:39:23 +00:00
|
|
|
GLRC* glrc = (GLRC*)NtCurrentTeb()->glCurrentRC;
|
2009-01-05 11:03:28 +00:00
|
|
|
|
|
|
|
/* FIXME we should Flush the gl here */
|
|
|
|
|
2012-07-12 11:39:23 +00:00
|
|
|
if (glrc == NULL)
|
2009-01-05 11:03:28 +00:00
|
|
|
{
|
|
|
|
DBGPRINT( "Error: No current GLRC!" );
|
|
|
|
SetLastError( ERROR_INVALID_FUNCTION );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-07-12 11:39:23 +00:00
|
|
|
func = glrc->icd->DrvGetProcAddress( proc );
|
2009-01-05 11:03:28 +00:00
|
|
|
if (func != NULL)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Info: Proc \"%s\" loaded from ICD.", proc );
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: Should we return wgl/gl 1.1 functions? */
|
|
|
|
SetLastError( ERROR_PROC_NOT_FOUND );
|
|
|
|
return NULL;
|
2007-11-15 12:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PROC
|
|
|
|
APIENTRY
|
|
|
|
rosglGetDefaultProcAddress( LPCSTR proc )
|
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
PROC func;
|
2012-07-12 11:39:23 +00:00
|
|
|
GLRC* glrc = (GLRC*)NtCurrentTeb()->glCurrentRC;
|
2009-01-05 11:03:28 +00:00
|
|
|
|
|
|
|
/* wglGetDefaultProcAddress does not flush the gl */
|
|
|
|
|
2012-07-12 11:39:23 +00:00
|
|
|
if (glrc == NULL)
|
2009-01-05 11:03:28 +00:00
|
|
|
{
|
|
|
|
DBGPRINT( "Error: No current GLRC!" );
|
|
|
|
SetLastError( ERROR_INVALID_FUNCTION );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-07-12 11:39:23 +00:00
|
|
|
func = glrc->icd->DrvGetProcAddress( proc );
|
2009-01-05 11:03:28 +00:00
|
|
|
if (func != NULL)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Info: Proc \"%s\" loaded from ICD.", proc );
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: Should we return wgl/gl 1.1 functions? */
|
|
|
|
SetLastError( ERROR_PROC_NOT_FOUND );
|
|
|
|
return NULL;
|
2004-02-02 05:36:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-16 16:16:16 +00:00
|
|
|
/*! \brief Make the given GLRC the threads current GLRC for hdc
|
|
|
|
*
|
|
|
|
* \param hdc [IN] Handle for a DC to be drawn on
|
|
|
|
* \param hglrc [IN] Handle for a GLRC to make current
|
|
|
|
*
|
|
|
|
* \retval TRUE Success
|
|
|
|
* \retval FALSE Failure
|
2004-02-03 14:23:42 +00:00
|
|
|
*/
|
2004-02-06 18:17:18 +00:00
|
|
|
BOOL
|
|
|
|
APIENTRY
|
|
|
|
rosglMakeCurrent( HDC hdc, HGLRC hglrc )
|
2004-02-02 05:36:37 +00:00
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
GLRC *glrc = (GLRC *)hglrc;
|
|
|
|
ICDTable *icdTable = NULL;
|
|
|
|
|
|
|
|
DBGTRACE( "Called!" );
|
|
|
|
|
2012-07-12 00:34:09 +00:00
|
|
|
/* Is t a new context ? */
|
|
|
|
if (glrc != NULL)
|
2009-01-05 11:03:28 +00:00
|
|
|
{
|
|
|
|
/* check hdc */
|
|
|
|
if (GetObjectType( hdc ) != OBJ_DC && GetObjectType( hdc ) != OBJ_MEMDC)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: hdc is not a DC handle!" );
|
|
|
|
SetLastError( ERROR_INVALID_HANDLE );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if we know about this glrc */
|
|
|
|
if (!ROSGL_ContainsContext( glrc ))
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: hglrc not found!" );
|
|
|
|
SetLastError( ERROR_INVALID_HANDLE );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if it is available */
|
|
|
|
if (glrc->is_current && glrc->thread_id != GetCurrentThreadId()) /* used by another thread */
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: hglrc is current for thread 0x%08x", glrc->thread_id );
|
|
|
|
SetLastError( ERROR_INVALID_HANDLE );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-07-12 00:34:09 +00:00
|
|
|
/* Unset previous one */
|
2012-07-12 11:39:23 +00:00
|
|
|
if (NtCurrentTeb()->glCurrentRC != NULL)
|
2012-07-12 00:34:09 +00:00
|
|
|
{
|
2012-07-12 11:39:23 +00:00
|
|
|
GLRC *oldglrc = (GLRC*)NtCurrentTeb()->glCurrentRC;
|
2012-07-12 00:34:09 +00:00
|
|
|
oldglrc->is_current = FALSE;
|
|
|
|
oldglrc->thread_id = 0;
|
|
|
|
oldglrc->hdc = NULL;
|
|
|
|
oldglrc->icd->DrvReleaseContext(oldglrc->hglrc);
|
|
|
|
}
|
|
|
|
|
2009-01-05 11:03:28 +00:00
|
|
|
/* call the ICD */
|
|
|
|
if (glrc->hglrc != NULL)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Info: Calling DrvSetContext!" );
|
|
|
|
SetLastError( ERROR_SUCCESS );
|
|
|
|
icdTable = glrc->icd->DrvSetContext( hdc, glrc->hglrc,
|
|
|
|
(void *)ROSGL_SetContextCallBack );
|
|
|
|
if (icdTable == NULL)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: DrvSetContext failed (%d)\n", GetLastError() );
|
2012-07-12 11:39:23 +00:00
|
|
|
NtCurrentTeb()->glCurrentRC = NULL;
|
2009-01-05 11:03:28 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
DBGPRINT( "Info: DrvSetContext succeeded!" );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make it current */
|
|
|
|
glrc->is_current = TRUE;
|
|
|
|
glrc->thread_id = GetCurrentThreadId();
|
|
|
|
glrc->hdc = hdc;
|
2012-07-12 11:39:23 +00:00
|
|
|
NtCurrentTeb()->glCurrentRC = (HGLRC)glrc;
|
2009-01-05 11:03:28 +00:00
|
|
|
}
|
2012-07-12 11:39:23 +00:00
|
|
|
else if(NtCurrentTeb()->glCurrentRC)
|
2012-07-12 00:34:09 +00:00
|
|
|
{
|
|
|
|
/* This is a call to unset the context */
|
2012-07-12 11:39:23 +00:00
|
|
|
GLRC *oldglrc = (GLRC*)NtCurrentTeb()->glCurrentRC;
|
2012-07-12 00:34:09 +00:00
|
|
|
oldglrc->is_current = FALSE;
|
|
|
|
oldglrc->thread_id = 0;
|
|
|
|
oldglrc->hdc = NULL;
|
|
|
|
oldglrc->icd->DrvReleaseContext(oldglrc->hglrc);
|
2012-07-12 11:39:23 +00:00
|
|
|
NtCurrentTeb()->glCurrentRC = NULL;
|
2012-07-12 00:34:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* To make wine tests happy.
|
|
|
|
* Now, who cares if MakeCurrentContext(NULL, NULL) fails when current context is already NULL
|
|
|
|
*/
|
|
|
|
if (GetObjectType( hdc ) != OBJ_DC && GetObjectType( hdc ) != OBJ_MEMDC)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: hdc is not a DC handle!" );
|
|
|
|
SetLastError( ERROR_INVALID_HANDLE );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2009-01-05 11:03:28 +00:00
|
|
|
|
|
|
|
if (ROSGL_SetContextCallBack( icdTable ) != ERROR_SUCCESS && icdTable == NULL)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Warning: ROSGL_SetContextCallBack failed!" );
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2004-02-02 05:36:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-06 18:17:18 +00:00
|
|
|
BOOL
|
|
|
|
APIENTRY
|
|
|
|
rosglRealizeLayerPalette( HDC hdc, int iLayerPlane, BOOL bRealize )
|
2004-02-02 05:36:37 +00:00
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
UNIMPLEMENTED;
|
|
|
|
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
|
|
|
|
return FALSE;
|
2004-02-02 05:36:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-06 18:17:18 +00:00
|
|
|
int
|
|
|
|
APIENTRY
|
|
|
|
rosglSetLayerPaletteEntries( HDC hdc, int iLayerPlane, int iStart,
|
2004-03-01 19:36:21 +00:00
|
|
|
int cEntries, CONST COLORREF *pcr )
|
2004-02-02 05:36:37 +00:00
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
UNIMPLEMENTED;
|
|
|
|
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
|
|
|
|
return 0;
|
2004-02-02 05:36:37 +00:00
|
|
|
}
|
|
|
|
|
2004-02-06 13:59:13 +00:00
|
|
|
|
2004-07-16 16:16:16 +00:00
|
|
|
/*! \brief Set a DCs pixelformat
|
|
|
|
*
|
|
|
|
* \param hdc [IN] Handle to DC for which to set the format
|
|
|
|
* \param iFormat [IN] Index of the pixelformat to set
|
|
|
|
* \param pfd [IN] Not sure what this is for
|
|
|
|
*
|
|
|
|
* \retval TRUE Success
|
|
|
|
* \retval FALSE Failure
|
2004-03-01 19:36:21 +00:00
|
|
|
*/
|
2004-02-06 18:17:18 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
rosglSetPixelFormat( HDC hdc, int iFormat, CONST PIXELFORMATDESCRIPTOR *pfd )
|
2004-02-06 13:59:13 +00:00
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
GLDCDATA *dcdata;
|
2012-07-12 14:06:34 +00:00
|
|
|
GLDRIVERDATA* icd;
|
2009-01-05 11:03:28 +00:00
|
|
|
|
|
|
|
DBGTRACE( "Called!" );
|
|
|
|
|
2012-07-12 14:06:34 +00:00
|
|
|
/* Get private DC data */
|
|
|
|
dcdata = ROSGL_GetPrivateDCData( hdc );
|
|
|
|
if (dcdata == NULL)
|
2009-01-05 11:03:28 +00:00
|
|
|
{
|
2012-07-12 14:06:34 +00:00
|
|
|
DBGPRINT( "Error: ROSGL_GetPrivateDCData() failed!" );
|
2009-01-05 11:03:28 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2012-07-12 14:06:34 +00:00
|
|
|
/* you can set the same pixel format twice, but you can't modify it */
|
|
|
|
if(dcdata->pixel_format) return dcdata->pixel_format == iFormat;
|
2009-01-05 11:03:28 +00:00
|
|
|
|
2012-07-12 14:06:34 +00:00
|
|
|
icd = ROSGL_ICDForHDC(hdc);
|
|
|
|
if(icd == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Call ICD function */
|
2009-01-05 11:03:28 +00:00
|
|
|
if (!icd->DrvSetPixelFormat( hdc, iFormat, pfd ))
|
|
|
|
{
|
|
|
|
DBGPRINT( "Warning: DrvSetPixelFormat(format=%d) failed (%d)",
|
|
|
|
iFormat, GetLastError() );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
dcdata->pixel_format = iFormat;
|
|
|
|
|
|
|
|
return TRUE;
|
2004-02-06 13:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-16 16:16:16 +00:00
|
|
|
/*! \brief Enable display-list sharing between multiple GLRCs
|
|
|
|
*
|
|
|
|
* This will only work if both GLRCs are from the same driver.
|
|
|
|
*
|
|
|
|
* \param hglrc1 [IN] GLRC number 1
|
|
|
|
* \param hglrc2 [IN] GLRC number 2
|
|
|
|
*
|
|
|
|
* \retval TRUE Success
|
|
|
|
* \retval FALSE Failure
|
2004-02-03 14:23:42 +00:00
|
|
|
*/
|
2004-02-06 18:17:18 +00:00
|
|
|
BOOL
|
|
|
|
APIENTRY
|
|
|
|
rosglShareLists( HGLRC hglrc1, HGLRC hglrc2 )
|
2004-02-02 05:36:37 +00:00
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
GLRC *glrc1 = (GLRC *)hglrc1;
|
|
|
|
GLRC *glrc2 = (GLRC *)hglrc2;
|
|
|
|
|
|
|
|
/* check glrcs */
|
|
|
|
if (!ROSGL_ContainsContext( glrc1 ))
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: hglrc1 not found!" );
|
|
|
|
SetLastError( ERROR_INVALID_HANDLE );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!ROSGL_ContainsContext( glrc2 ))
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: hglrc2 not found!" );
|
|
|
|
SetLastError( ERROR_INVALID_HANDLE );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* I think this is only possible within one ICD */
|
|
|
|
if (glrc1->icd != glrc2->icd)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: hglrc1 and hglrc2 use different ICDs!" );
|
|
|
|
SetLastError( ERROR_INVALID_HANDLE );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* share lists (call ICD) */
|
|
|
|
return glrc1->icd->DrvShareLists( glrc1->hglrc, glrc2->hglrc );
|
2004-02-03 14:23:42 +00:00
|
|
|
}
|
|
|
|
|
2004-02-06 13:59:13 +00:00
|
|
|
|
2004-07-16 16:16:16 +00:00
|
|
|
/*! \brief Flushes GL and swaps front/back buffer if appropriate
|
|
|
|
*
|
|
|
|
* \param hdc [IN] Handle to device context to swap buffers for
|
|
|
|
*
|
|
|
|
* \retval TRUE Success
|
|
|
|
* \retval FALSE Failure
|
2004-02-03 14:23:42 +00:00
|
|
|
*/
|
2004-02-06 18:17:18 +00:00
|
|
|
BOOL
|
|
|
|
APIENTRY
|
|
|
|
rosglSwapBuffers( HDC hdc )
|
2004-02-03 14:23:42 +00:00
|
|
|
{
|
2009-01-05 11:03:28 +00:00
|
|
|
GLDRIVERDATA *icd = ROSGL_ICDForHDC( hdc );
|
|
|
|
DBGTRACE( "Called!" );
|
|
|
|
if (icd != NULL)
|
|
|
|
{
|
|
|
|
DBGPRINT( "Swapping buffers!" );
|
|
|
|
if (!icd->DrvSwapBuffers( hdc ))
|
|
|
|
{
|
|
|
|
DBGPRINT( "Error: DrvSwapBuffers failed (%d)", GetLastError() );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: implement own functionality? */
|
|
|
|
SetLastError( ERROR_INVALID_FUNCTION );
|
|
|
|
return FALSE;
|
2004-02-02 05:36:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-06 18:17:18 +00:00
|
|
|
BOOL
|
|
|
|
APIENTRY
|
|
|
|
rosglSwapLayerBuffers( HDC hdc, UINT fuPlanes )
|
2004-02-02 05:36:37 +00:00
|
|
|
{
|
2009-09-24 16:35:20 +00:00
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
if(fuPlanes & WGL_SWAP_MAIN_PLANE)
|
|
|
|
ret = rosglSwapBuffers(hdc);
|
|
|
|
|
|
|
|
if(fuPlanes &~WGL_SWAP_MAIN_PLANE)
|
|
|
|
DBGTRACE("wglSwapLayerBuffers is not fully implemented\n");
|
|
|
|
|
|
|
|
return ret;
|
2004-02-02 05:36:37 +00:00
|
|
|
}
|
|
|
|
|
2004-02-06 18:17:18 +00:00
|
|
|
#ifdef __cplusplus
|
2004-07-16 16:16:16 +00:00
|
|
|
}; /* extern "C" */
|
|
|
|
#endif /* __cplusplus */
|
2004-02-06 18:17:18 +00:00
|
|
|
|
2004-02-03 14:23:42 +00:00
|
|
|
/* EOF */
|