gllindrv.cpp revision 2e96343b87cf64e4be4d92b56ae6819f9d3b8c40
/** @file
*
* VBox OpenGL
*
* Simple buffered OpenGL functions
*
* Contributed by: Alexander Eichner
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#define GLX_GLXEXT_PROTOTYPES
#include "vboxgl.h"
#define LOG_GROUP LOG_GROUP_SHARED_OPENGL
#include <string.h>
#include <stdio.h>
/* X11 server connection for all OpenGL clients.
* Neccessary because Mesa and DRI cannot handle more than one
* connection per thread (only hardware acceleration, software rendering
* runs fine with more than one connection).
* Would crash in vboxglDisconnect if on every vboxglConnect
* a new Display is created */
}
/* from http://www.mesa3d.org/brianp/sig97/exten.htm */
{
/*
** Search for extName in the extensions string. Use of strstr()
** is not sufficient because extension names can be prefixes of
** other extension names. Could use strtok() but the constant
** string returned by glGetString can be in read-only memory.
*/
char *end;
int extNameLen;
while (p < end) {
int n = strcspn(p, " ");
return GL_TRUE;
}
p += (n + 1);
}
return GL_FALSE;
}
/**
* Global init of VBox OpenGL
*
* @returns VBox error code
*/
int vboxglGlobalInit()
{
Log(("vboxglGlobalInit\n"));
/*vboxInitOpenGLExtensions();*/
return VINF_SUCCESS;
}
/**
* Global deinit of VBox OpenGL
*
* @returns VBox error code
*/
int vboxglGlobalUnload()
{
Log(("vboxglGlobalUnload\n"));
if (glXDisplay)
return VINF_SUCCESS;
}
/**
* Enable OpenGL
*
* @returns VBox error code
* @param pClient Client context
*/
{
static int attribs[] = {
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
};
int screen_num;
unsigned long mask;
int returnedFBConfigs;
/* we have to set up a rendering context to be able to use glGetString
* a window is created but is not mapped to screen (so it's not visible')
* and a GLXContext is bound to it */
pClient->enable.fbConfig = pClient->glxChooseFBConfig(pClient->dpy, screen_num, attribs, &returnedFBConfigs);
pClient->enable.visinfo = pClient->glxGetVisualFromFBConfig(pClient->dpy, pClient->enable.fbConfig[0]);
/* Create Window */
attr.background_pixel = 0;
attr.border_pixel = 0;
attr.colormap = XCreateColormap(pClient->dpy, RootWindow(pClient->dpy, screen_num), pClient->enable.visinfo->visual, AllocNone);
pClient->enable.win = XCreateWindow(pClient->dpy, RootWindow(pClient->dpy, screen_num), 0, 0, 100, 100,
/* Create Context */
pClient->enable.ctx = pClient->glxCreateNewContext(pClient->dpy, pClient->enable.fbConfig[0], GLX_RGBA_TYPE, NULL, GL_TRUE);
return VINF_SUCCESS;
}
/**
* Disable OpenGL
*
* @returns VBox error code
* @param pClient Client context
*/
{
/* Free all data */
{
glFlush();
}
return VINF_SUCCESS;
}
/**
* Client connect init
*
* @returns VBox error code
* @param pClient Client context
*/
{
int rc = VERR_NOT_IMPLEMENTED;
Log(("vboxglConnect\n"));
if (!glXDisplay)
Log(("Server GLX 1.3 supported\n"));
(GLubyte *) "glXChooseFBConfig");
(GLubyte *) "glXGetVisualFromFBConfig");
(GLubyte *) "glXCreateNewContext");
Log(("GLX_SGIX_fbconfig extension supported\n"));
(GLubyte *) "glXChooseFBConfigSGIX");
(GLubyte *) "glXGetVisualFromFBConfigSGIX");
(GLubyte *) "glXCreateContextWithConfigSGIX");
} else {
Log(("Error no FBConfig supported\n"));
}
if (pClient->glxChooseFBConfig && pClient->glxGetVisualFromFBConfig && pClient->glxCreateNewContext)
rc = VINF_SUCCESS;
}
return rc;
}
/**
* Client disconnect cleanup
*
* @returns VBox error code
* @param pClient Client context
*/
{
Log(("vboxglDisconnect\n"));
#ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT
}
if (pClient->PixelFormatToFBConfigMapper) {
}
#endif
return VINF_SUCCESS;
}
/* Driver functions */
{
unsigned long mask;
int screen_num;
#ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT
/* window attributes */
attr.background_pixel = 0;
attr.border_pixel = 0;
attr.colormap = XCreateColormap(pClient->dpy, RootWindow(pClient->dpy, screen_num ), visinfo->visual, AllocNone);
}
pClient->glxContext = pClient->glxCreateNewContext(pClient->dpy, fbConfig, GLX_RGBA_TYPE, NULL, GL_TRUE);
glrc = 1;
#else
AssertFailed();
glrc = 0;
#endif
pClient->fHasLastError = true;
}
{
pClient->fHasLastError = true;
}
{
#ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT
if (!pClient->lastretval)
Log(("glXMakeCurrent failed\n"));
pClient->fHasLastError = true;
#else
AssertFailed();
#endif
}
{
glXCopyContext(pClient->dpy, VBOX_OGL_GUEST_TO_HOST_HDC(hglrc), VBOX_OGL_GUEST_TO_HOST_HDC(hglrc), mask);
pClient->fHasLastError = true;
}
{
/* clear current selection */
if (!pClient->lastretval)
Log(("glXMakeCurrent failed\n"));
pClient->fHasLastError = true;
}
{
unsigned long mask;
int screen_num;
OGL_PARAM(int, iLayerPlane);
#ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT
/* window attributes */
attr.background_pixel = 0;
attr.border_pixel = 0;
attr.colormap = XCreateColormap(pClient->dpy, RootWindow(pClient->dpy, screen_num ), visinfo->visual, AllocNone);
}
pClient->glxContext = pClient->glxCreateNewContext(pClient->dpy, fbConfig, GLX_RGBA_TYPE, NULL, GL_TRUE);
glrc = 1;
pClient->fHasLastError = true;
#else
AssertFailed();
#endif
}
{
pClient->fHasLastError = true;
}
{
OGL_PARAM(int, iLayerPlane);
pClient->fHasLastError = true;
}
{
pClient->fHasLastError = true;
}
{
int screen_num;
OGL_PARAM(int, iPixelFormat);
/* Get GLXFBConfig based on the given ID */
pClient->lastretval = true;
pClient->fHasLastError = true;
}
{
pClient->fHasLastError = true;
}
{
OGL_PARAM(int, iPixelFormat);
OGL_PARAM(int, iLayerPlane);
pClient->fHasLastError = true;
}
{
OGL_PARAM(int, iLayerPlane);
pClient->fHasLastError = true;
}
{
OGL_PARAM(int, iLayerPlane);
pClient->fHasLastError = true;
}
{
int screenNum, glxReturnValue;
OGL_PARAM(int, iPixelFormat);
if (!pClient->PixelFormatToFBConfigMapper) {
/* First get number of all visuals for the return value */
&pClient->numFBConfigs);
}
if (nBytes == sizeof(PIXELFORMATDESCRIPTOR)) {
/* Get GLXFBConfig which matches iPixelFormat */
Log(("Filling values into PIXELFORMATDESCRIPTOR\n"));
/* translate all values to theire corresponding Windows ones */
/* Set cColorBits */
/* Set dwFlags */
}
if (glxReturnValue)
}
/* Set iPixelType */
if (glxReturnValue & GLX_RGBA_BIT)
}
/* Set cDepthBits */
} else {
ppfd->cDepthBits = 0;
}
/* Set cStencilBits */
} else {
ppfd->cStencilBits = 0;
}
/** @todo Fill in the rest */
}
pClient->fHasLastError = true;
}
{
return pfnProc;
}