VirtualBox

Ignore:
Timestamp:
Nov 9, 2014 8:48:01 PM (10 years ago)
Author:
vboxsync
Message:

DevVGA-SVGA3d-ogl.cpp: Corrected #elif RT_OS_DARWIN and #elif RT_OS_LINUX tests to use include defined(). Made several macros safer. Addressed a couple of darwin warnings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp

    r53206 r53275  
     1/* $Id$ */
    12/** @file
    23 * DevVMWare - VMWare SVGA device
     
    45
    56/*
    6  * Copyright (C) 2013 Oracle Corporation
     7 * Copyright (C) 2013-2014 Oracle Corporation
    78 *
    89 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    4445#include "vmsvga/svga3d_reg.h"
    4546#include "vmsvga/svga3d_shaderdefs.h"
     47
    4648#ifdef RT_OS_WINDOWS
    47 #include <GL/gl.h>
    48 #include "vmsvga_glext/wglext.h"
    49 #elif RT_OS_DARWIN
    50 #include <OpenGL/OpenGL.h>
    51 #include <OpenGL/gl3.h>
    52 #include <OpenGL/gl3ext.h>
    53 #define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED
    54 #include <OpenGL/gl.h>
    55 #include <OpenGL/glext.h>
    56 #include "DevVGA-SVGA3d-cocoa.h"
     49# include <GL/gl.h>
     50# include "vmsvga_glext/wglext.h"
     51
     52#elif defined(RT_OS_DARWIN)
     53# include <OpenGL/OpenGL.h>
     54# include <OpenGL/gl3.h>
     55# include <OpenGL/gl3ext.h>
     56# define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED
     57# include <OpenGL/gl.h>
     58# include <OpenGL/glext.h>
     59# include "DevVGA-SVGA3d-cocoa.h"
    5760/* work around conflicting definition of GLhandleARB in VMware's glext.h */
    5861//#define GL_ARB_shader_objects
     
    6164typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREPROC) (GLenum texture);
    6265typedef void (APIENTRYP PFNGLGETPROGRAMIVARBPROC) (GLenum target, GLenum pname, GLint *params);
    63 #define GL_RGBA_S3TC 0x83A2
    64 #define GL_ALPHA8_EXT 0x803c
    65 #define GL_LUMINANCE8_EXT 0x8040
    66 #define GL_LUMINANCE16_EXT 0x8042
    67 #define GL_LUMINANCE4_ALPHA4_EXT 0x8043
    68 #define GL_LUMINANCE8_ALPHA8_EXT 0x8045
    69 #define GL_INT_2_10_10_10_REV 0x8D9F
     66# define GL_RGBA_S3TC 0x83A2
     67# define GL_ALPHA8_EXT 0x803c
     68# define GL_LUMINANCE8_EXT 0x8040
     69# define GL_LUMINANCE16_EXT 0x8042
     70# define GL_LUMINANCE4_ALPHA4_EXT 0x8043
     71# define GL_LUMINANCE8_ALPHA8_EXT 0x8045
     72# define GL_INT_2_10_10_10_REV 0x8D9F
    7073#else
    71 #include <X11/Xlib.h>
    72 #include <X11/Xatom.h>
    73 #include <GL/gl.h>
    74 #include <GL/glx.h>
    75 #include <GL/glext.h>
     74# include <X11/Xlib.h>
     75# include <X11/Xatom.h>
     76# include <GL/gl.h>
     77# include <GL/glx.h>
     78# include <GL/glext.h>
    7679//HACK FOR NOW
    7780typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREPROC) (GLenum texture);
     
    8790#ifdef RT_OS_WINDOWS
    8891#define OGLGETPROCADDRESS       wglGetProcAddress
    89 #elif RT_OS_DARWIN
     92#elif defined(RT_OS_DARWIN)
    9093#include <dlfcn.h>
    9194void *MyNSGLGetProcAddress(const char *name)
    9295{
    93     static void *image = NULL;
    94     if (image == NULL)
    95         image = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY);
    96     return (image ? dlsym(image, name) : NULL);
     96    static void *s_image = NULL;
     97    if (s_image == NULL)
     98        s_image = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY);
     99    return (s_image ? dlsym(s_image, name) : NULL);
    97100}
    98101# define OGLGETPROCADDRESS       MyNSGLGetProcAddress
     
    115118*******************************************************************************/
    116119#define VMSVGA3D_CLEAR_CURRENT_CONTEXT(pState)                          \
    117     pState->idActiveContext = OPENGL_INVALID_ID;
     120    do { (pState)->idActiveContext = OPENGL_INVALID_ID; } while (0)
    118121
    119122#ifdef RT_OS_WINDOWS
    120123# define VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext)                   \
    121     if (pState->idActiveContext != pContext->id)                          \
     124    if ((pState)->idActiveContext != pContext->id)                        \
    122125    {                                                                     \
    123         BOOL makecurret = wglMakeCurrent(pContext->hdc, pContext->hglrc); \
     126        BOOL makecurret = wglMakeCurrent((pContext)->hdc, (pContext)->hglrc); \
    124127        Assert(makecurret == TRUE);                                       \
    125         pState->idActiveContext = pContext->id;                           \
    126     }
    127 
    128 #elif RT_OS_DARWIN
     128        pState->idActiveContext = (pContext)->id;                         \
     129    } else do { } while (0)
     130
     131#elif defined(RT_OS_DARWIN)
    129132# define VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext) \
    130     if (pState->idActiveContext != pContext->id)                        \
     133    if ((pState)->idActiveContext != (pContext)->id)                    \
    131134    {                                                                   \
    132         vmsvga3dCocoaViewMakeCurrentContext(pContext->cocoaView, pContext->cocoaContext); \
    133         pState->idActiveContext = pContext->id;                         \
    134     }
     135        vmsvga3dCocoaViewMakeCurrentContext((pContext)->cocoaView, (pContext)->cocoaContext); \
     136        (pState)->idActiveContext = (pContext)->id;                     \
     137    } else do { } while (0)
    135138#else
    136139# define VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext) \
    137     if (pState->idActiveContext != pContext->id)                        \
     140    if ((pState)->idActiveContext != (pContext)->id)                    \
    138141    {                                                                   \
    139         Bool makecurret = glXMakeCurrent(pState->display,              \
    140                                          pContext->window,              \
    141                                          pContext->glxContext);         \
     142        Bool makecurret = glXMakeCurrent((pState)->display,             \
     143                                         (pContext)->window,            \
     144                                         (pContext)->glxContext);       \
    142145        Assert(makecurret == True);                                     \
    143         pState->idActiveContext = pContext->id;                         \
    144     }
     146        (pState)->idActiveContext = (pContext)->id;                     \
     147    } else do { } while (0)
    145148#endif
    146149
    147 #ifdef DEBUG
    148 # define VMSVGA3D_CHECK_LAST_ERROR(pState, pContext)                        \
    149     Assert(pState->idActiveContext == pContext->id);                        \
    150     pContext->lastError = glGetError();                                     \
    151     AssertMsgReturn(pContext->lastError == GL_NO_ERROR, ("%s (%d): last error 0x%x\n", __FUNCTION__, __LINE__, pContext->lastError), VERR_INTERNAL_ERROR);
     150#ifdef VBOX_STRICT
     151# define VMSVGA3D_CHECK_LAST_ERROR(pState, pContext) do {                   \
     152    Assert((pState)->idActiveContext == (pContext)->id);                    \
     153    (pContext)->lastError = glGetError();                                   \
     154    AssertMsgReturn((pContext)->lastError == GL_NO_ERROR, ("%s (%d): last error 0x%x\n", __FUNCTION__, __LINE__, (pContext)->lastError), VERR_INTERNAL_ERROR); \
     155    } while (0)
    152156#else
    153 # define VMSVGA3D_CHECK_LAST_ERROR(pState, pContext)                   ;
     157# define VMSVGA3D_CHECK_LAST_ERROR(pState, pContext)                        do { } while (0)
    154158#endif
    155159
    156 #ifdef DEBUG
    157 # define VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext)                   \
    158     Assert(pState->idActiveContext == pContext->id);                        \
    159     pContext->lastError = glGetError();                                     \
    160     AssertMsg(pContext->lastError == GL_NO_ERROR, ("%s (%d): last error 0x%x\n", __FUNCTION__, __LINE__, pContext->lastError));
     160#ifdef VBOX_STRICT
     161# define VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext) do {              \
     162    Assert((pState)->idActiveContext == (pContext)->id);                    \
     163    (pContext)->lastError = glGetError();                                   \
     164    AssertMsg((pContext)->lastError == GL_NO_ERROR, ("%s (%d): last error 0x%x\n", __FUNCTION__, __LINE__, (pContext)->lastError)); \
     165    } while (0)
    161166#else
    162 # define VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext)                   ;
     167# define VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext)                   do { } while (0)
    163168#endif
    164169
     
    322327    /* Device context window handle. */
    323328    HWND                    hwnd;
    324 #elif RT_OS_DARWIN
     329#elif defined(RT_OS_DARWIN)
    325330    /* OpenGL rendering context */
    326331    NativeNSOpenGLContextRef cocoaContext;
     
    433438    /** Window request semaphore. */
    434439    RTSEMEVENT              WndRequestSem;
    435 #elif RT_OS_LINUX
     440#elif defined(RT_OS_LINUX)
    436441    /* The X display */
    437442    Display                 *display;
     
    752757    VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
    753758    glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &pState->caps.maxTextureBufferSize);
    754     VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
     759#ifdef DEBUG_bird
     760    if (pState->fGLVersion >= 3.1) /* darwin: Requires GL 3.1, so triggers on older mac os x versions. */
     761#endif
     762        VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
    755763    glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &pState->caps.maxTextures);
    756764    VMSVGA3D_CHECK_LAST_ERROR_WARN(pState, pContext);
     
    972980
    973981    RTSemEventDestroy(pState->WndRequestSem);
    974 #elif RT_OS_DARWIN
    975 
    976 #elif RT_OS_LINUX
     982#elif defined(RT_OS_DARWIN)
     983
     984#elif defined(RT_OS_LINUX)
    977985    /* signal to the thread that it is supposed to exit */
    978986    pState->bTerminate = true;
     
    28052813    BOOL ret = SwapBuffers(pContext->hdc);
    28062814    AssertMsg(ret, ("SwapBuffers failed with %d\n", GetLastError()));
    2807 #elif RT_OS_DARWIN
     2815#elif defined(RT_OS_DARWIN)
    28082816    vmsvga3dCocoaSwapBuffers(pContext->cocoaContext);
    28092817#else
     
    29912999    }
    29923000
    2993 #elif RT_OS_DARWIN
     3001#elif defined(RT_OS_DARWIN)
    29943002    /* Find the first active context to share the display list with (necessary for sharing e.g. textures between contexts). */
    29953003    NativeNSOpenGLContextRef shareContext = NULL;
     
    31883196        int rc = vmsvga3dSendThreadMessage(pState->pWindowThread, pState->WndRequestSem, WM_VMSVGA3D_DESTROYWINDOW, (WPARAM)pContext->hwnd, 0);
    31893197        AssertRC(rc);
    3190 #elif RT_OS_DARWIN
     3198#elif defined(RT_OS_DARWIN)
    31913199        vmsvga3dCocoaDestroyView(pContext->cocoaView);
    31923200        vmsvga3dCocoaDestroyContext(pContext->cocoaContext);
    3193 #elif RT_OS_LINUX
     3201#elif defined(RT_OS_LINUX)
    31943202        glXMakeCurrent(pState->display, None, NULL);
    31953203        glXDestroyContext(pState->display, pContext->glxContext);
     
    32323240            int rc = vmsvga3dSendThreadMessage(pState->pWindowThread, pState->WndRequestSem, WM_VMSVGA3D_RESIZEWINDOW, (WPARAM)pContext->hwnd, (LPARAM)&cs);
    32333241            AssertRC(rc);
    3234 #elif RT_OS_DARWIN
     3242#elif defined(RT_OS_DARWIN)
    32353243            vmsvga3dCocoaViewSetSize(pContext->cocoaView, pThis->svga.uWidth, pThis->svga.uHeight);
    3236 #elif RT_OS_LINUX
     3244#elif defined(RT_OS_LINUX)
    32373245            XWindowChanges wc;
    32383246            wc.width = pThis->svga.uWidth;
     
    55645572                AssertFailed();
    55655573                break;
     5574            case SVGA3D_DECLUSAGE_MAX: AssertFailed(); break; /* shut up gcc */
    55665575            }
    55675576        }
     
    56325641            case SVGA3D_DECLUSAGE_SAMPLE:
    56335642                break;
     5643            case SVGA3D_DECLUSAGE_MAX: AssertFailed(); break; /* shut up gcc */
    56345644            }
    56355645        }
     
    58415851                pTexture = &pState->paSurface[pContext->aSidActiveTexture[activeTextureUnit - GL_TEXTURE0]];
    58425852
    5843                 AssertMsg(pTexture->oglId.texture == activeTexture, ("%x vs %x unit %d - %d\n", pTexture->oglId.texture, activeTexture, i, activeTextureUnit - GL_TEXTURE0));
     5853                AssertMsg(pTexture->oglId.texture == (GLuint)activeTexture, ("%x vs %x unit %d - %d\n", pTexture->oglId.texture, activeTexture, i, activeTextureUnit - GL_TEXTURE0));
    58445854            }
    58455855        }
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette